Removed helpers lib and updated to flutter 3.22
This commit is contained in:
+14
-22
@@ -1,8 +1,8 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:colorful_print/colorful_print.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:helpers/helpers/print.dart';
|
||||
import 'package:rluv/global/api.dart';
|
||||
import 'package:rluv/models/budget.dart';
|
||||
import 'package:rluv/models/budget_category_model.dart';
|
||||
@@ -13,8 +13,7 @@ import '../models/shared_note.dart';
|
||||
import '../models/transaction_model.dart';
|
||||
import '../models/user.dart';
|
||||
|
||||
StateProvider<SharedPreferences?> prefsProvider =
|
||||
StateProvider<SharedPreferences?>((ref) => null);
|
||||
StateProvider<SharedPreferences?> prefsProvider = StateProvider<SharedPreferences?>((ref) => null);
|
||||
|
||||
// final StateProvider<Token?> tokenProvider = StateProvider<Token?>((ref) {
|
||||
// // final tokenStr = prefs.getString('jwt');
|
||||
@@ -42,8 +41,7 @@ final Provider<FamilyModel?> familyProvider = Provider<FamilyModel?>(
|
||||
},
|
||||
);
|
||||
|
||||
final Provider<List<BudgetCategory>> budgetCategoriesProvider =
|
||||
Provider<List<BudgetCategory>>((ref) {
|
||||
final Provider<List<BudgetCategory>> budgetCategoriesProvider = Provider<List<BudgetCategory>>((ref) {
|
||||
final dash = ref.watch(dashboardProvider);
|
||||
if (dash == null) return [];
|
||||
final categoriesData = dash['budget_categories'] as List<dynamic>;
|
||||
@@ -55,7 +53,7 @@ final Provider<List<BudgetCategory>> budgetCategoriesProvider =
|
||||
|
||||
final prefs = ref.read(prefsProvider);
|
||||
final budgetJson = jsonEncode({'budget_categories': categoriesData});
|
||||
printBlue('updated prefs stored categories');
|
||||
printColor('updated prefs stored categories', textColor: TextColor.blue);
|
||||
prefs?.setString('budget_categories', budgetJson);
|
||||
|
||||
return categories;
|
||||
@@ -71,8 +69,7 @@ final Provider<Budget?> budgetProvider = Provider<Budget?>(
|
||||
},
|
||||
);
|
||||
|
||||
final Provider<List<Transaction>> transactionsProvider =
|
||||
Provider<List<Transaction>>((ref) {
|
||||
final Provider<List<Transaction>> transactionsProvider = Provider<List<Transaction>>((ref) {
|
||||
final dash = ref.watch(dashboardProvider);
|
||||
if (dash == null) return [];
|
||||
final transactions = dash['transactions'] as List<dynamic>;
|
||||
@@ -83,8 +80,7 @@ final Provider<List<Transaction>> transactionsProvider =
|
||||
.toList();
|
||||
});
|
||||
|
||||
final Provider<List<SharedNote>> sharedNotesProvider =
|
||||
Provider<List<SharedNote>>(
|
||||
final Provider<List<SharedNote>> sharedNotesProvider = Provider<List<SharedNote>>(
|
||||
(ref) {
|
||||
final dash = ref.watch(dashboardProvider);
|
||||
if (dash == null) return [];
|
||||
@@ -97,8 +93,7 @@ final Provider<List<SharedNote>> sharedNotesProvider =
|
||||
},
|
||||
);
|
||||
|
||||
final dashboardProvider =
|
||||
StateNotifierProvider<DashBoardStateNotifier, Map<String, dynamic>?>(
|
||||
final dashboardProvider = StateNotifierProvider<DashBoardStateNotifier, Map<String, dynamic>?>(
|
||||
(ref) {
|
||||
return DashBoardStateNotifier(ref);
|
||||
},
|
||||
@@ -119,10 +114,10 @@ class DashBoardStateNotifier extends StateNotifier<Map<String, dynamic>?> {
|
||||
);
|
||||
final token = ref.read(tokenProvider);
|
||||
if (token?.familyId == null) {
|
||||
printPink('No token, cannot fetch dashboard');
|
||||
printColor('No token, cannot fetch dashboard', textColor: TextColor.red);
|
||||
return;
|
||||
}
|
||||
printAmber('Fetching dashboard');
|
||||
printColor('Fetching dashboard', textColor: TextColor.yellow);
|
||||
state = await ref.read(apiProvider.notifier).get("dashboard");
|
||||
WidgetsBinding.instance.addPostFrameCallback(
|
||||
(_) => ref.read(loadingStateProvider.notifier).state = false,
|
||||
@@ -131,7 +126,7 @@ class DashBoardStateNotifier extends StateNotifier<Map<String, dynamic>?> {
|
||||
|
||||
void update(Map<String, dynamic> data) {
|
||||
if (state == null) {
|
||||
printPink('Cant update data, state is null');
|
||||
printColor('Cant update data, state is null', textColor: TextColor.red);
|
||||
return;
|
||||
}
|
||||
if (data.keys.length != 1 || data.values.length != 1) {
|
||||
@@ -149,9 +144,7 @@ class DashBoardStateNotifier extends StateNotifier<Map<String, dynamic>?> {
|
||||
)
|
||||
.toList();
|
||||
subStateListObj.removeWhere(
|
||||
(element) =>
|
||||
element['id'] ==
|
||||
(data.values.first as Map<String, dynamic>)['id'],
|
||||
(element) => element['id'] == (data.values.first as Map<String, dynamic>)['id'],
|
||||
);
|
||||
subStateListObj.add(data.values.first);
|
||||
|
||||
@@ -167,7 +160,7 @@ class DashBoardStateNotifier extends StateNotifier<Map<String, dynamic>?> {
|
||||
|
||||
void add(Map<String, dynamic> data) {
|
||||
if (state == null) {
|
||||
printPink('Cant add data, state is null');
|
||||
printColor('Cant add data, state is null', textColor: TextColor.red);
|
||||
return;
|
||||
}
|
||||
if (data.keys.length != 1 || data.values.length != 1) {
|
||||
@@ -192,7 +185,7 @@ class DashBoardStateNotifier extends StateNotifier<Map<String, dynamic>?> {
|
||||
|
||||
void removeWithId(String stateKey, int id) {
|
||||
if (state == null) {
|
||||
printPink('Cant remove data, state is null');
|
||||
printColor('Cant remove data, state is null', textColor: TextColor.red);
|
||||
return;
|
||||
}
|
||||
switch (stateKey) {
|
||||
@@ -201,8 +194,7 @@ class DashBoardStateNotifier extends StateNotifier<Map<String, dynamic>?> {
|
||||
case 'shared_noted':
|
||||
final subStateList = state![stateKey] as List<dynamic>;
|
||||
final newState = state;
|
||||
subStateList
|
||||
.removeWhere((e) => (e as Map<String, dynamic>)['id'] == id);
|
||||
subStateList.removeWhere((e) => (e as Map<String, dynamic>)['id'] == id);
|
||||
newState![stateKey] = subStateList;
|
||||
state = {...newState};
|
||||
// printBlue(state);
|
||||
|
||||
Reference in New Issue
Block a user