remove loading future

This commit is contained in:
julian 2022-11-17 07:02:56 -06:00
parent 2936249bd6
commit fc9e4d35dd

View file

@ -18,7 +18,6 @@ import 'package:stackwallet/widgets/address_book_card.dart';
import 'package:stackwallet/widgets/conditional_parent.dart'; import 'package:stackwallet/widgets/conditional_parent.dart';
import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart';
import 'package:stackwallet/widgets/icon_widgets/x_icon.dart'; import 'package:stackwallet/widgets/icon_widgets/x_icon.dart';
import 'package:stackwallet/widgets/loading_indicator.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
import 'package:stackwallet/widgets/stack_text_field.dart'; import 'package:stackwallet/widgets/stack_text_field.dart';
import 'package:stackwallet/widgets/textfield_icon_button.dart'; import 'package:stackwallet/widgets/textfield_icon_button.dart';
@ -38,9 +37,9 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
late TextEditingController _searchController; late TextEditingController _searchController;
final _searchFocusNode = FocusNode(); final _searchFocusNode = FocusNode();
//
List<Contact>? _cache; // List<Contact>? _cache;
List<Contact>? _cacheFav; // List<Contact>? _cacheFav;
String _searchTerm = ""; String _searchTerm = "";
@ -100,8 +99,10 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
debugPrint("BUILD: $runtimeType"); debugPrint("BUILD: $runtimeType");
final addressBookEntriesFuture = ref.watch( // final addressBookEntriesFuture = ref.watch(
addressBookServiceProvider.select((value) => value.addressBookEntries)); // addressBookServiceProvider.select((value) => value.addressBookEntries));
final contacts =
ref.watch(addressBookServiceProvider.select((value) => value.contacts));
final isDesktop = Util.isDesktop; final isDesktop = Util.isDesktop;
return ConditionalParent( return ConditionalParent(
@ -279,28 +280,27 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
const SizedBox( const SizedBox(
height: 12, height: 12,
), ),
FutureBuilder( // FutureBuilder(
future: addressBookEntriesFuture, // future: addressBookEntriesFuture,
builder: (_, AsyncSnapshot<List<Contact>> snapshot) { // builder: (_, AsyncSnapshot<List<Contact>> snapshot) {
if (snapshot.connectionState == ConnectionState.done && // if (snapshot.connectionState == ConnectionState.done &&
snapshot.hasData) { // snapshot.hasData) {
_cacheFav = snapshot.data!; // _cacheFav = snapshot.data!;
} // }
if (_cacheFav == null) { // if (_cacheFav == null) {
// TODO proper loading animation // // TODO proper loading animation
return const LoadingIndicator(); // return const LoadingIndicator();
} else { // } else {
if (_cacheFav!.isNotEmpty) { // if (_cacheFav!.isNotEmpty) {
return RoundedWhiteContainer( // return
RoundedWhiteContainer(
padding: EdgeInsets.all(!isDesktop ? 0 : 15), padding: EdgeInsets.all(!isDesktop ? 0 : 15),
child: Column( child: Column(
children: [ children: [
..._cacheFav! ...contacts
.where((element) => element.addresses .where((element) => element.addresses
.where((e) => ref.watch( .where((e) => ref.watch(addressBookFilterProvider
addressBookFilterProvider.select( .select((value) => value.coins.contains(e.coin))))
(value) =>
value.coins.contains(e.coin))))
.isNotEmpty) .isNotEmpty)
.where((e) => .where((e) =>
e.isFavorite && e.isFavorite &&
@ -316,20 +316,22 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
), ),
], ],
), ),
); )
} else { // ;
return RoundedWhiteContainer( // } else {
child: Center( // return RoundedWhiteContainer(
child: Text( // child: Center(
"Your favorite contacts will appear here", // child: Text(
style: STextStyles.itemSubtitle(context), // "Your favorite contacts will appear here",
), // style: STextStyles.itemSubtitle(context),
), // ),
); // ),
} // );
} // }
}, // }
), // },
// )
,
const SizedBox( const SizedBox(
height: 16, height: 16,
), ),
@ -340,19 +342,20 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
const SizedBox( const SizedBox(
height: 12, height: 12,
), ),
FutureBuilder( // FutureBuilder(
future: addressBookEntriesFuture, // future: addressBookEntriesFuture,
builder: (_, AsyncSnapshot<List<Contact>> snapshot) { // builder: (_, AsyncSnapshot<List<Contact>> snapshot) {
if (snapshot.connectionState == ConnectionState.done && // if (snapshot.connectionState == ConnectionState.done &&
snapshot.hasData) { // snapshot.hasData) {
_cache = snapshot.data!; // _cache = snapshot.data!;
} // }
if (_cache == null) { // if (_cache == null) {
// TODO proper loading animation // // TODO proper loading animation
return const LoadingIndicator(); // return const LoadingIndicator();
} else { // } else {
if (_cache!.isNotEmpty) { // if (_cache!.isNotEmpty) {
return Column( // return
Column(
children: [ children: [
RoundedWhiteContainer( RoundedWhiteContainer(
padding: EdgeInsets.all(!isDesktop ? 0 : 15), padding: EdgeInsets.all(!isDesktop ? 0 : 15),
@ -360,12 +363,11 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Column( child: Column(
children: [ children: [
..._cache! ...contacts
.where((element) => element.addresses .where((element) => element.addresses
.where((e) => ref.watch( .where((e) => ref.watch(
addressBookFilterProvider.select( addressBookFilterProvider.select((value) =>
(value) => value.coins value.coins.contains(e.coin))))
.contains(e.coin))))
.isNotEmpty) .isNotEmpty)
.where((e) => ref .where((e) => ref
.read(addressBookServiceProvider) .read(addressBookServiceProvider)
@ -373,8 +375,7 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
.where((element) => !element.isFavorite) .where((element) => !element.isFavorite)
.map( .map(
(e) => AddressBookCard( (e) => AddressBookCard(
key: Key( key: Key("desktopContactCard_${e.id}_key"),
"desktopContactCard_${e.id}_key"),
contactId: e.id, contactId: e.id,
), ),
), ),
@ -383,20 +384,22 @@ class _AddressBookViewState extends ConsumerState<AddressBookView> {
), ),
), ),
], ],
); )
} else { // ;
return RoundedWhiteContainer( // } else {
child: Center( // return RoundedWhiteContainer(
child: Text( // child: Center(
"Your contacts will appear here", // child: Text(
style: STextStyles.itemSubtitle(context), // "Your contacts will appear here",
), // style: STextStyles.itemSubtitle(context),
), // ),
); // ),
} // );
} // }
}, // }
), // },
// )
,
], ],
), ),
), ),