Putting the finishing touches on my first Flutter mobile app. Another important ToDo: My Floating Action Button appears in the Top App Bar for every page, but i would like its status to change (enabled / disabled) depending on the current page. Is this possible? if so, any tutorials, resources, reference material and / or code examples fit for a novice, would be much appreciated. Thanks!
Asked
Active
Viewed 898 times
1 Answers
2
Cool, you can use Visibility:
floatingActionButton: Visibility(
child: FloatingActionButton(...),
visible: false, // set it to false
)
Alternatively, you could use NotificationListener (more elegante but sophisticated).
Please check this example from another publication
Edit: maybe controlling it directly in onPressed. According to official docs:
"If the onPressed callback is null, then the button will be disabled and by default will resemble a flat button in the disabledColor."
FloatingActionButton(
onPressed: shouldButtonBeDisabled() ? null : () => whatToDoOnPressed,
child: Text('blablabla')
);

vinipx
- 425
- 2
- 5
-
thank you for the suggestion! ..I will definitely use this one day. But not for this project, i don't think; as i want the button to remain visible, just not active. although your suggestion reminds me that visual cues are important to UI; if my button remains visible AND looks the same, it might be misconstrued as 'broken' on the disabled page. so i think a color and/or opacity change is something my solution needs as well, since it will remain visible. thanks – codeName Jun 24 '20 at 21:25
-
[EDIT] added one new suggestion. Check it out if it makes sense. – vinipx Jun 24 '20 at 21:32
-
That might work. I mean, for an experienced programmer, probably definitely. Can I pull it off?.. that's another question entirely lol. But it seems simple enough, and only 3 lines.. that's a plus; i will give this a try asap.. stay tuned. Thanks! – codeName Jun 24 '20 at 21:42