Hi I use Provider (https://pub.dev/packages/provider) into my Flutter app. Now I want to manage the floating action button into a scaffold using a provider consumer, to be sure that the scaffold is not rebuilded when I need to hide the FAB button.
Now I've created a simple FABProvider
class FABProvider extends ChangeNotifier {
FABProvider(bool initialValue) {
this._visible = initialValue;
}
bool _visible;
bool get visible => _visible;
void hide() {
if (_visible) {
_visible = false;
notifyListeners();
}
}
void show() {
if (!_visible) {
_visible = true;
notifyListeners();
}
}
}
I wrap all Scaffold into a ChangeNotifierProvider:
return ChangeNotifierProvider<FABProvider>.value(
value: fabProvider,
child: Scaffold(
...
floatingActionButton: Consumer<FABProvider>(
child: createMyFAB(),
builder: (context, provider, child) {
if (provider.visible) {
return child;
} else {
return null; <-- Now I need to return null when the fab need to be hided otherwise the scaffold does not animate the FAB
}
},
),
...
)
...
I try also return an Offstage() or a Container(), but when return a Widget and not null the Scaffold does not animate the fab visibility.