mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-22 10:34:32 +00:00
favourites ui fixes and provider tweaks
This commit is contained in:
parent
a9bdf08186
commit
d93136e285
6 changed files with 123 additions and 180 deletions
|
@ -11,7 +11,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:stackwallet/providers/db/main_db_provider.dart';
|
||||
import 'package:stackwallet/providers/providers.dart';
|
||||
import 'package:stackwallet/themes/stack_colors.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
|
@ -63,17 +62,8 @@ class ManageFavoritesView extends StatelessWidget {
|
|||
body: isDesktop
|
||||
? Consumer(
|
||||
builder: (_, ref, __) {
|
||||
final favorites = ref.watch(pFavouriteWalletInfos);
|
||||
print(
|
||||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
|
||||
|
||||
// todo [prio=??] do this differently
|
||||
final nonFavorites = ref
|
||||
.watch(pWallets)
|
||||
.wallets
|
||||
.map((e) => e.info)
|
||||
.where((e) => !e.isFavourite)
|
||||
.toList();
|
||||
final favorites = ref.watch(pFavouriteWalletInfos(true));
|
||||
final nonFavorites = ref.watch(pFavouriteWalletInfos(false));
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
|
@ -158,7 +148,7 @@ class ManageFavoritesView extends StatelessWidget {
|
|||
actualIndex - (oldIndex - newIndex),
|
||||
);
|
||||
} else {
|
||||
for (int i = oldIndex + 1; i <= newIndex; i++) {
|
||||
for (int i = oldIndex + 1; i < newIndex; i++) {
|
||||
final next = favorites[i];
|
||||
next.updateIsFavourite(
|
||||
true,
|
||||
|
@ -274,7 +264,8 @@ class ManageFavoritesView extends StatelessWidget {
|
|||
Expanded(
|
||||
child: Consumer(
|
||||
builder: (_, ref, __) {
|
||||
final favorites = ref.watch(pFavouriteWalletInfos);
|
||||
final favorites =
|
||||
ref.watch(pFavouriteWalletInfos(true));
|
||||
return ReorderableListView.builder(
|
||||
key: key,
|
||||
itemCount: favorites.length,
|
||||
|
@ -312,7 +303,7 @@ class ManageFavoritesView extends StatelessWidget {
|
|||
actualIndex - (oldIndex - newIndex),
|
||||
);
|
||||
} else {
|
||||
for (int i = oldIndex + 1; i <= newIndex; i++) {
|
||||
for (int i = oldIndex + 1; i < newIndex; i++) {
|
||||
final next = favorites[i];
|
||||
next.updateIsFavourite(
|
||||
true,
|
||||
|
@ -367,13 +358,8 @@ class ManageFavoritesView extends StatelessWidget {
|
|||
Expanded(
|
||||
child: Consumer(
|
||||
builder: (_, ref, __) {
|
||||
// todo [prio=??] do this differently
|
||||
final nonFavorites = ref
|
||||
.watch(pWallets)
|
||||
.wallets
|
||||
.map((e) => e.info)
|
||||
.where((e) => !e.isFavourite)
|
||||
.toList();
|
||||
final nonFavorites =
|
||||
ref.watch(pFavouriteWalletInfos(false));
|
||||
|
||||
return ListView.builder(
|
||||
itemCount: nonFavorites.length,
|
||||
|
|
|
@ -73,7 +73,7 @@ class _FavoriteWalletsState extends ConsumerState<FavoriteWallets> {
|
|||
Widget build(BuildContext context) {
|
||||
debugPrint("BUILD: $runtimeType");
|
||||
|
||||
final favorites = ref.watch(pFavouriteWalletInfos);
|
||||
final favorites = ref.watch(pFavouriteWalletInfos(true));
|
||||
_favLength = favorites.length;
|
||||
|
||||
bool hasFavorites = favorites.isNotEmpty;
|
||||
|
|
|
@ -17,8 +17,8 @@ import 'package:stackwallet/themes/stack_colors.dart';
|
|||
import 'package:stackwallet/utilities/assets.dart';
|
||||
import 'package:stackwallet/utilities/constants.dart';
|
||||
import 'package:stackwallet/utilities/text_styles.dart';
|
||||
import 'package:stackwallet/wallets/isar/providers/favourite_wallets_provider.dart';
|
||||
import 'package:stackwallet/widgets/custom_buttons/blue_text_button.dart';
|
||||
import 'package:stackwallet/widgets/db_watchers/favourite_wallets_watcher.dart';
|
||||
|
||||
class DesktopFavoriteWallets extends ConsumerWidget {
|
||||
const DesktopFavoriteWallets({Key? key}) : super(key: key);
|
||||
|
@ -30,10 +30,9 @@ class DesktopFavoriteWallets extends ConsumerWidget {
|
|||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
debugPrint("BUILD: $runtimeType");
|
||||
final favourites = ref.watch(pFavouriteWalletInfos(true));
|
||||
|
||||
return FavouriteWalletsWatcher(
|
||||
builder: (context, favourites) {
|
||||
bool hasFavorites = favourites.isNotEmpty;
|
||||
final bool hasFavorites = favourites.isNotEmpty;
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
@ -52,8 +51,7 @@ class DesktopFavoriteWallets extends ConsumerWidget {
|
|||
CustomTextButton(
|
||||
text: "Edit",
|
||||
onTap: () {
|
||||
Navigator.of(context)
|
||||
.pushNamed(ManageFavoritesView.routeName);
|
||||
Navigator.of(context).pushNamed(ManageFavoritesView.routeName);
|
||||
},
|
||||
),
|
||||
],
|
||||
|
@ -96,9 +94,8 @@ class DesktopFavoriteWallets extends ConsumerWidget {
|
|||
),
|
||||
),
|
||||
child: MaterialButton(
|
||||
splashColor: Theme.of(context)
|
||||
.extension<StackColors>()!
|
||||
.highlight,
|
||||
splashColor:
|
||||
Theme.of(context).extension<StackColors>()!.highlight,
|
||||
key: const Key("favoriteWalletsAddFavoriteButtonKey"),
|
||||
padding: const EdgeInsets.all(12),
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
|
@ -140,7 +137,5 @@ class DesktopFavoriteWallets extends ConsumerWidget {
|
|||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,11 +162,10 @@ class WalletInfo implements IsarId {
|
|||
} else if (flag) {
|
||||
final highest = await isar.walletInfo
|
||||
.where()
|
||||
.walletIdEqualTo(walletId)
|
||||
.sortByFavouriteOrderIndexDesc()
|
||||
.favouriteOrderIndexProperty()
|
||||
.findFirst();
|
||||
index = highest ?? 0;
|
||||
index = (highest ?? 0) + 1;
|
||||
} else {
|
||||
index = -1;
|
||||
}
|
||||
|
|
|
@ -7,17 +7,19 @@ import 'package:stackwallet/providers/db/main_db_provider.dart';
|
|||
import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
|
||||
|
||||
class _Watcher extends ChangeNotifier {
|
||||
final bool isFavourite;
|
||||
late final StreamSubscription<List<WalletInfo>> _streamSubscription;
|
||||
|
||||
List<WalletInfo> _value;
|
||||
|
||||
List<WalletInfo> get value => _value;
|
||||
|
||||
_Watcher(this._value, Isar isar) {
|
||||
_Watcher(this._value, this.isFavourite, Isar isar) {
|
||||
_streamSubscription = isar.walletInfo
|
||||
.filter()
|
||||
.isFavouriteEqualTo(true)
|
||||
.watch()
|
||||
.isFavouriteEqualTo(isFavourite)
|
||||
.sortByFavouriteOrderIndex()
|
||||
.watch(fireImmediately: true)
|
||||
.listen((event) {
|
||||
_value = event;
|
||||
notifyListeners();
|
||||
|
@ -31,16 +33,17 @@ class _Watcher extends ChangeNotifier {
|
|||
}
|
||||
}
|
||||
|
||||
final _wiProvider = ChangeNotifierProvider.autoDispose(
|
||||
(ref) {
|
||||
final _wiProvider = ChangeNotifierProvider.family<_Watcher, bool>(
|
||||
(ref, isFavourite) {
|
||||
final isar = ref.watch(mainDBProvider).isar;
|
||||
|
||||
final watcher = _Watcher(
|
||||
isar.walletInfo
|
||||
.filter()
|
||||
.isFavouriteEqualTo(true)
|
||||
.isFavouriteEqualTo(isFavourite)
|
||||
.sortByFavouriteOrderIndex()
|
||||
.findAllSync(),
|
||||
isFavourite,
|
||||
isar,
|
||||
);
|
||||
|
||||
|
@ -50,8 +53,8 @@ final _wiProvider = ChangeNotifierProvider.autoDispose(
|
|||
},
|
||||
);
|
||||
|
||||
final pFavouriteWalletInfos = Provider.autoDispose(
|
||||
(ref) {
|
||||
return ref.watch(_wiProvider).value;
|
||||
final pFavouriteWalletInfos = Provider.family<List<WalletInfo>, bool>(
|
||||
(ref, isFavourite) {
|
||||
return ref.watch(_wiProvider(isFavourite)).value;
|
||||
},
|
||||
);
|
||||
|
|
|
@ -1,40 +0,0 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/providers/db/main_db_provider.dart';
|
||||
import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
|
||||
|
||||
class FavouriteWalletsWatcher extends ConsumerWidget {
|
||||
const FavouriteWalletsWatcher({
|
||||
super.key,
|
||||
required this.builder,
|
||||
});
|
||||
|
||||
final Widget Function(BuildContext, List<WalletInfo>) builder;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final initialInfo = ref
|
||||
.watch(mainDBProvider)
|
||||
.isar
|
||||
.walletInfo
|
||||
.where()
|
||||
.filter()
|
||||
.isFavouriteEqualTo(true)
|
||||
.findAllSync();
|
||||
|
||||
return StreamBuilder(
|
||||
stream: ref
|
||||
.watch(mainDBProvider)
|
||||
.isar
|
||||
.walletInfo
|
||||
.where()
|
||||
.filter()
|
||||
.isFavouriteEqualTo(true)
|
||||
.watch(),
|
||||
builder: (context, snapshot) {
|
||||
return builder(context, snapshot.data ?? initialInfo);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue