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/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:stackwallet/providers/db/main_db_provider.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/themes/stack_colors.dart';
|
||||||
import 'package:stackwallet/utilities/constants.dart';
|
import 'package:stackwallet/utilities/constants.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.dart';
|
import 'package:stackwallet/utilities/text_styles.dart';
|
||||||
|
@ -63,17 +62,8 @@ class ManageFavoritesView extends StatelessWidget {
|
||||||
body: isDesktop
|
body: isDesktop
|
||||||
? Consumer(
|
? Consumer(
|
||||||
builder: (_, ref, __) {
|
builder: (_, ref, __) {
|
||||||
final favorites = ref.watch(pFavouriteWalletInfos);
|
final favorites = ref.watch(pFavouriteWalletInfos(true));
|
||||||
print(
|
final nonFavorites = ref.watch(pFavouriteWalletInfos(false));
|
||||||
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
|
|
||||||
|
|
||||||
// todo [prio=??] do this differently
|
|
||||||
final nonFavorites = ref
|
|
||||||
.watch(pWallets)
|
|
||||||
.wallets
|
|
||||||
.map((e) => e.info)
|
|
||||||
.where((e) => !e.isFavourite)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
|
@ -158,7 +148,7 @@ class ManageFavoritesView extends StatelessWidget {
|
||||||
actualIndex - (oldIndex - newIndex),
|
actualIndex - (oldIndex - newIndex),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
for (int i = oldIndex + 1; i <= newIndex; i++) {
|
for (int i = oldIndex + 1; i < newIndex; i++) {
|
||||||
final next = favorites[i];
|
final next = favorites[i];
|
||||||
next.updateIsFavourite(
|
next.updateIsFavourite(
|
||||||
true,
|
true,
|
||||||
|
@ -274,7 +264,8 @@ class ManageFavoritesView extends StatelessWidget {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Consumer(
|
child: Consumer(
|
||||||
builder: (_, ref, __) {
|
builder: (_, ref, __) {
|
||||||
final favorites = ref.watch(pFavouriteWalletInfos);
|
final favorites =
|
||||||
|
ref.watch(pFavouriteWalletInfos(true));
|
||||||
return ReorderableListView.builder(
|
return ReorderableListView.builder(
|
||||||
key: key,
|
key: key,
|
||||||
itemCount: favorites.length,
|
itemCount: favorites.length,
|
||||||
|
@ -312,7 +303,7 @@ class ManageFavoritesView extends StatelessWidget {
|
||||||
actualIndex - (oldIndex - newIndex),
|
actualIndex - (oldIndex - newIndex),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
for (int i = oldIndex + 1; i <= newIndex; i++) {
|
for (int i = oldIndex + 1; i < newIndex; i++) {
|
||||||
final next = favorites[i];
|
final next = favorites[i];
|
||||||
next.updateIsFavourite(
|
next.updateIsFavourite(
|
||||||
true,
|
true,
|
||||||
|
@ -367,13 +358,8 @@ class ManageFavoritesView extends StatelessWidget {
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Consumer(
|
child: Consumer(
|
||||||
builder: (_, ref, __) {
|
builder: (_, ref, __) {
|
||||||
// todo [prio=??] do this differently
|
final nonFavorites =
|
||||||
final nonFavorites = ref
|
ref.watch(pFavouriteWalletInfos(false));
|
||||||
.watch(pWallets)
|
|
||||||
.wallets
|
|
||||||
.map((e) => e.info)
|
|
||||||
.where((e) => !e.isFavourite)
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
return ListView.builder(
|
return ListView.builder(
|
||||||
itemCount: nonFavorites.length,
|
itemCount: nonFavorites.length,
|
||||||
|
|
|
@ -73,7 +73,7 @@ class _FavoriteWalletsState extends ConsumerState<FavoriteWallets> {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
debugPrint("BUILD: $runtimeType");
|
debugPrint("BUILD: $runtimeType");
|
||||||
|
|
||||||
final favorites = ref.watch(pFavouriteWalletInfos);
|
final favorites = ref.watch(pFavouriteWalletInfos(true));
|
||||||
_favLength = favorites.length;
|
_favLength = favorites.length;
|
||||||
|
|
||||||
bool hasFavorites = favorites.isNotEmpty;
|
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/assets.dart';
|
||||||
import 'package:stackwallet/utilities/constants.dart';
|
import 'package:stackwallet/utilities/constants.dart';
|
||||||
import 'package:stackwallet/utilities/text_styles.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/custom_buttons/blue_text_button.dart';
|
||||||
import 'package:stackwallet/widgets/db_watchers/favourite_wallets_watcher.dart';
|
|
||||||
|
|
||||||
class DesktopFavoriteWallets extends ConsumerWidget {
|
class DesktopFavoriteWallets extends ConsumerWidget {
|
||||||
const DesktopFavoriteWallets({Key? key}) : super(key: key);
|
const DesktopFavoriteWallets({Key? key}) : super(key: key);
|
||||||
|
@ -30,117 +30,112 @@ class DesktopFavoriteWallets extends ConsumerWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
debugPrint("BUILD: $runtimeType");
|
debugPrint("BUILD: $runtimeType");
|
||||||
|
final favourites = ref.watch(pFavouriteWalletInfos(true));
|
||||||
|
|
||||||
return FavouriteWalletsWatcher(
|
final bool hasFavorites = favourites.isNotEmpty;
|
||||||
builder: (context, favourites) {
|
return Column(
|
||||||
bool hasFavorites = favourites.isNotEmpty;
|
mainAxisSize: MainAxisSize.min,
|
||||||
return Column(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisSize: MainAxisSize.min,
|
children: [
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Text(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
"Favorite wallets",
|
||||||
children: [
|
style: STextStyles.desktopTextExtraSmall(context).copyWith(
|
||||||
Text(
|
color: Theme.of(context)
|
||||||
"Favorite wallets",
|
.extension<StackColors>()!
|
||||||
style: STextStyles.desktopTextExtraSmall(context).copyWith(
|
.textFieldActiveSearchIconRight,
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.textFieldActiveSearchIconRight,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
CustomTextButton(
|
|
||||||
text: "Edit",
|
|
||||||
onTap: () {
|
|
||||||
Navigator.of(context)
|
|
||||||
.pushNamed(ManageFavoritesView.routeName);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 20,
|
|
||||||
),
|
|
||||||
ConstrainedBox(
|
|
||||||
constraints: const BoxConstraints(
|
|
||||||
maxHeight: (cardHeight * 2) + standardPadding,
|
|
||||||
minHeight: cardHeight,
|
|
||||||
),
|
),
|
||||||
child: hasFavorites
|
|
||||||
? SingleChildScrollView(
|
|
||||||
primary: false,
|
|
||||||
child: Wrap(
|
|
||||||
spacing: 16,
|
|
||||||
runSpacing: 16,
|
|
||||||
children: [
|
|
||||||
...favourites.map((e) {
|
|
||||||
return FavoriteCard(
|
|
||||||
walletId: e.walletId,
|
|
||||||
key: Key(e.name),
|
|
||||||
width: cardWidth,
|
|
||||||
height: cardHeight,
|
|
||||||
);
|
|
||||||
})
|
|
||||||
],
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: Container(
|
|
||||||
height: cardHeight,
|
|
||||||
width: cardWidth,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.textFieldDefaultBG,
|
|
||||||
borderRadius: BorderRadius.circular(
|
|
||||||
Constants.size.circularBorderRadius,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: MaterialButton(
|
|
||||||
splashColor: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.highlight,
|
|
||||||
key: const Key("favoriteWalletsAddFavoriteButtonKey"),
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(
|
|
||||||
Constants.size.circularBorderRadius),
|
|
||||||
),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context)
|
|
||||||
.pushNamed(ManageFavoritesView.routeName);
|
|
||||||
},
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
SvgPicture.asset(
|
|
||||||
Assets.svg.plus,
|
|
||||||
width: 14,
|
|
||||||
height: 14,
|
|
||||||
color: Theme.of(context)
|
|
||||||
.extension<StackColors>()!
|
|
||||||
.textSubtitle1,
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
width: 4,
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
"Add a favorite",
|
|
||||||
style: STextStyles.itemSubtitle(context).copyWith(
|
|
||||||
fontSize: 18,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
const SizedBox(
|
CustomTextButton(
|
||||||
height: 40,
|
text: "Edit",
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pushNamed(ManageFavoritesView.routeName);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
),
|
||||||
},
|
const SizedBox(
|
||||||
|
height: 20,
|
||||||
|
),
|
||||||
|
ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(
|
||||||
|
maxHeight: (cardHeight * 2) + standardPadding,
|
||||||
|
minHeight: cardHeight,
|
||||||
|
),
|
||||||
|
child: hasFavorites
|
||||||
|
? SingleChildScrollView(
|
||||||
|
primary: false,
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 16,
|
||||||
|
runSpacing: 16,
|
||||||
|
children: [
|
||||||
|
...favourites.map((e) {
|
||||||
|
return FavoriteCard(
|
||||||
|
walletId: e.walletId,
|
||||||
|
key: Key(e.name),
|
||||||
|
width: cardWidth,
|
||||||
|
height: cardHeight,
|
||||||
|
);
|
||||||
|
})
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Container(
|
||||||
|
height: cardHeight,
|
||||||
|
width: cardWidth,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.textFieldDefaultBG,
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
Constants.size.circularBorderRadius,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: MaterialButton(
|
||||||
|
splashColor:
|
||||||
|
Theme.of(context).extension<StackColors>()!.highlight,
|
||||||
|
key: const Key("favoriteWalletsAddFavoriteButtonKey"),
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(
|
||||||
|
Constants.size.circularBorderRadius),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context)
|
||||||
|
.pushNamed(ManageFavoritesView.routeName);
|
||||||
|
},
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
SvgPicture.asset(
|
||||||
|
Assets.svg.plus,
|
||||||
|
width: 14,
|
||||||
|
height: 14,
|
||||||
|
color: Theme.of(context)
|
||||||
|
.extension<StackColors>()!
|
||||||
|
.textSubtitle1,
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
width: 4,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
"Add a favorite",
|
||||||
|
style: STextStyles.itemSubtitle(context).copyWith(
|
||||||
|
fontSize: 18,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 40,
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,11 +162,10 @@ class WalletInfo implements IsarId {
|
||||||
} else if (flag) {
|
} else if (flag) {
|
||||||
final highest = await isar.walletInfo
|
final highest = await isar.walletInfo
|
||||||
.where()
|
.where()
|
||||||
.walletIdEqualTo(walletId)
|
|
||||||
.sortByFavouriteOrderIndexDesc()
|
.sortByFavouriteOrderIndexDesc()
|
||||||
.favouriteOrderIndexProperty()
|
.favouriteOrderIndexProperty()
|
||||||
.findFirst();
|
.findFirst();
|
||||||
index = highest ?? 0;
|
index = (highest ?? 0) + 1;
|
||||||
} else {
|
} else {
|
||||||
index = -1;
|
index = -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,19 @@ import 'package:stackwallet/providers/db/main_db_provider.dart';
|
||||||
import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
|
import 'package:stackwallet/wallets/isar/models/wallet_info.dart';
|
||||||
|
|
||||||
class _Watcher extends ChangeNotifier {
|
class _Watcher extends ChangeNotifier {
|
||||||
|
final bool isFavourite;
|
||||||
late final StreamSubscription<List<WalletInfo>> _streamSubscription;
|
late final StreamSubscription<List<WalletInfo>> _streamSubscription;
|
||||||
|
|
||||||
List<WalletInfo> _value;
|
List<WalletInfo> _value;
|
||||||
|
|
||||||
List<WalletInfo> get value => _value;
|
List<WalletInfo> get value => _value;
|
||||||
|
|
||||||
_Watcher(this._value, Isar isar) {
|
_Watcher(this._value, this.isFavourite, Isar isar) {
|
||||||
_streamSubscription = isar.walletInfo
|
_streamSubscription = isar.walletInfo
|
||||||
.filter()
|
.filter()
|
||||||
.isFavouriteEqualTo(true)
|
.isFavouriteEqualTo(isFavourite)
|
||||||
.watch()
|
.sortByFavouriteOrderIndex()
|
||||||
|
.watch(fireImmediately: true)
|
||||||
.listen((event) {
|
.listen((event) {
|
||||||
_value = event;
|
_value = event;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
@ -31,16 +33,17 @@ class _Watcher extends ChangeNotifier {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final _wiProvider = ChangeNotifierProvider.autoDispose(
|
final _wiProvider = ChangeNotifierProvider.family<_Watcher, bool>(
|
||||||
(ref) {
|
(ref, isFavourite) {
|
||||||
final isar = ref.watch(mainDBProvider).isar;
|
final isar = ref.watch(mainDBProvider).isar;
|
||||||
|
|
||||||
final watcher = _Watcher(
|
final watcher = _Watcher(
|
||||||
isar.walletInfo
|
isar.walletInfo
|
||||||
.filter()
|
.filter()
|
||||||
.isFavouriteEqualTo(true)
|
.isFavouriteEqualTo(isFavourite)
|
||||||
.sortByFavouriteOrderIndex()
|
.sortByFavouriteOrderIndex()
|
||||||
.findAllSync(),
|
.findAllSync(),
|
||||||
|
isFavourite,
|
||||||
isar,
|
isar,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -50,8 +53,8 @@ final _wiProvider = ChangeNotifierProvider.autoDispose(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
final pFavouriteWalletInfos = Provider.autoDispose(
|
final pFavouriteWalletInfos = Provider.family<List<WalletInfo>, bool>(
|
||||||
(ref) {
|
(ref, isFavourite) {
|
||||||
return ref.watch(_wiProvider).value;
|
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