From b65cb1590c882f66d2351383aceefb6dccda164d Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 3 Jun 2020 21:26:15 +0300 Subject: [PATCH] Fix pull to refresh --- lib/ui/client/view/client_view.dart | 64 ++++++++++++++------------- lib/ui/expense/view/expense_view.dart | 38 ++++++++-------- lib/ui/vendor/view/vendor_view.dart | 28 ++++++------ lib/utils/completers.dart | 3 +- 4 files changed, 70 insertions(+), 63 deletions(-) diff --git a/lib/ui/client/view/client_view.dart b/lib/ui/client/view/client_view.dart index 668e30871..8a34c3f12 100644 --- a/lib/ui/client/view/client_view.dart +++ b/lib/ui/client/view/client_view.dart @@ -69,40 +69,42 @@ class _ClientViewState extends State ), ], ), - body: Column( - children: [ - Expanded( - child: TabBarView( - controller: _controller, - children: [ - RefreshIndicator( - onRefresh: () => viewModel.onRefreshed(context), - child: ClientOverview( - viewModel: viewModel, - isFilter: widget.isFilter, + body: Builder(builder: (context) { + return Column( + children: [ + Expanded( + child: TabBarView( + controller: _controller, + children: [ + RefreshIndicator( + onRefresh: () => viewModel.onRefreshed(context), + child: ClientOverview( + viewModel: viewModel, + isFilter: widget.isFilter, + ), ), - ), - RefreshIndicator( - onRefresh: () => viewModel.onRefreshed(context), - child: ClientViewDetails(client: viewModel.client), - ), - RefreshIndicator( - onRefresh: () => viewModel.onRefreshed(context), - child: ClientViewActivity( - viewModel: viewModel, - key: ValueKey(viewModel.client.id), + RefreshIndicator( + onRefresh: () => viewModel.onRefreshed(context), + child: ClientViewDetails(client: viewModel.client), ), - ), - ], + RefreshIndicator( + onRefresh: () => viewModel.onRefreshed(context), + child: ClientViewActivity( + viewModel: viewModel, + key: ValueKey(viewModel.client.id), + ), + ), + ], + ), ), - ), - BottomButtons( - entity: client, - action1: EntityAction.settings, - action2: EntityAction.newInvoice, - ), - ], - ), + BottomButtons( + entity: client, + action1: EntityAction.settings, + action2: EntityAction.newInvoice, + ), + ], + ); + }), floatingActionButton: FloatingActionButton( heroTag: 'client_view_fab', backgroundColor: Theme.of(context).primaryColorDark, diff --git a/lib/ui/expense/view/expense_view.dart b/lib/ui/expense/view/expense_view.dart index 30e0d4a6f..40164754b 100644 --- a/lib/ui/expense/view/expense_view.dart +++ b/lib/ui/expense/view/expense_view.dart @@ -68,24 +68,26 @@ class _ExpenseViewState extends State ), ], ), - body: TabBarView( - controller: _controller, - children: [ - RefreshIndicator( - onRefresh: () => viewModel.onRefreshed(context), - child: ExpenseOverview(viewModel: viewModel), - ), - RefreshIndicator( - onRefresh: () => viewModel.onRefreshed(context), - child: ExpenseViewDetails(expense: viewModel.expense), - ), - RefreshIndicator( - onRefresh: () => viewModel.onRefreshed(context), - child: ExpenseViewDocuments( - viewModel: viewModel, expense: viewModel.expense), - ), - ], - ), + body: Builder(builder: (context) { + return TabBarView( + controller: _controller, + children: [ + RefreshIndicator( + onRefresh: () => viewModel.onRefreshed(context), + child: ExpenseOverview(viewModel: viewModel), + ), + RefreshIndicator( + onRefresh: () => viewModel.onRefreshed(context), + child: ExpenseViewDetails(expense: viewModel.expense), + ), + RefreshIndicator( + onRefresh: () => viewModel.onRefreshed(context), + child: ExpenseViewDocuments( + viewModel: viewModel, expense: viewModel.expense), + ), + ], + ); + }), floatingActionButton: company.isEnterprisePlan ? Builder(builder: (BuildContext context) { return FloatingActionButton( diff --git a/lib/ui/vendor/view/vendor_view.dart b/lib/ui/vendor/view/vendor_view.dart index 92e75e19b..8a6294ada 100644 --- a/lib/ui/vendor/view/vendor_view.dart +++ b/lib/ui/vendor/view/vendor_view.dart @@ -56,19 +56,21 @@ class _VendorViewState extends State ), ], ), - body: TabBarView( - controller: _controller, - children: [ - RefreshIndicator( - onRefresh: () => viewModel.onRefreshed(context), - child: VendorOverview(viewModel: viewModel), - ), - RefreshIndicator( - onRefresh: () => viewModel.onRefreshed(context), - child: VendorViewDetails(vendor: viewModel.vendor), - ), - ], - ), + body: Builder(builder: (context) { + return TabBarView( + controller: _controller, + children: [ + RefreshIndicator( + onRefresh: () => viewModel.onRefreshed(context), + child: VendorOverview(viewModel: viewModel), + ), + RefreshIndicator( + onRefresh: () => viewModel.onRefreshed(context), + child: VendorViewDetails(vendor: viewModel.vendor), + ), + ], + ); + }), floatingActionButton: FloatingActionButton( heroTag: 'vendor_view_fab', backgroundColor: Theme.of(context).primaryColorDark, diff --git a/lib/utils/completers.dart b/lib/utils/completers.dart index 04af06f80..f11510e76 100644 --- a/lib/utils/completers.dart +++ b/lib/utils/completers.dart @@ -29,12 +29,13 @@ Completer refreshCompleter(BuildContext context) { Completer snackBarCompleter(BuildContext context, String message, {bool shouldPop = false}) { final Completer completer = Completer(); + final scaffold = Scaffold.of(context); completer.future.then((_) { if (shouldPop) { Navigator.of(context).pop(); } - Scaffold.of(context).showSnackBar(SnackBar( + scaffold.showSnackBar(SnackBar( content: SnackBarRow( message: message, )));