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,57 +280,58 @@ 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
padding: EdgeInsets.all(!isDesktop ? 0 : 15), RoundedWhiteContainer(
child: Column( padding: EdgeInsets.all(!isDesktop ? 0 : 15),
children: [ child: Column(
..._cacheFav! children: [
.where((element) => element.addresses ...contacts
.where((e) => ref.watch( .where((element) => element.addresses
addressBookFilterProvider.select( .where((e) => ref.watch(addressBookFilterProvider
(value) => .select((value) => value.coins.contains(e.coin))))
value.coins.contains(e.coin)))) .isNotEmpty)
.isNotEmpty) .where((e) =>
.where((e) => e.isFavorite &&
e.isFavorite && ref
ref .read(addressBookServiceProvider)
.read(addressBookServiceProvider) .matches(_searchTerm, e))
.matches(_searchTerm, e)) .where((element) => element.isFavorite)
.where((element) => element.isFavorite) .map(
.map( (e) => AddressBookCard(
(e) => AddressBookCard( key: Key("favContactCard_${e.id}_key"),
key: Key("favContactCard_${e.id}_key"), contactId: e.id,
contactId: e.id,
),
),
],
),
);
} else {
return RoundedWhiteContainer(
child: Center(
child: Text(
"Your favorite contacts will appear here",
style: STextStyles.itemSubtitle(context),
), ),
), ),
); ],
} ),
} )
}, // ;
), // } else {
// return RoundedWhiteContainer(
// child: Center(
// child: Text(
// "Your favorite contacts will appear here",
// style: STextStyles.itemSubtitle(context),
// ),
// ),
// );
// }
// }
// },
// )
,
const SizedBox( const SizedBox(
height: 16, height: 16,
), ),
@ -340,63 +342,64 @@ 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: [
RoundedWhiteContainer(
padding: EdgeInsets.all(!isDesktop ? 0 : 15),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [ children: [
RoundedWhiteContainer( ...contacts
padding: EdgeInsets.all(!isDesktop ? 0 : 15), .where((element) => element.addresses
child: Padding( .where((e) => ref.watch(
padding: const EdgeInsets.all(8.0), addressBookFilterProvider.select((value) =>
child: Column( value.coins.contains(e.coin))))
children: [ .isNotEmpty)
..._cache! .where((e) => ref
.where((element) => element.addresses .read(addressBookServiceProvider)
.where((e) => ref.watch( .matches(_searchTerm, e))
addressBookFilterProvider.select( .where((element) => !element.isFavorite)
(value) => value.coins .map(
.contains(e.coin)))) (e) => AddressBookCard(
.isNotEmpty) key: Key("desktopContactCard_${e.id}_key"),
.where((e) => ref contactId: e.id,
.read(addressBookServiceProvider) ),
.matches(_searchTerm, e))
.where((element) => !element.isFavorite)
.map(
(e) => AddressBookCard(
key: Key(
"desktopContactCard_${e.id}_key"),
contactId: e.id,
),
),
],
), ),
),
),
], ],
); ),
} else { ),
return RoundedWhiteContainer( ),
child: Center( ],
child: Text( )
"Your contacts will appear here", // ;
style: STextStyles.itemSubtitle(context), // } else {
), // return RoundedWhiteContainer(
), // child: Center(
); // child: Text(
} // "Your contacts will appear here",
} // style: STextStyles.itemSubtitle(context),
}, // ),
), // ),
// );
// }
// }
// },
// )
,
], ],
), ),
), ),