Skip to content

Instantly share code, notes, and snippets.

@ulusoyca
Last active January 23, 2023 18:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ulusoyca/4ef6d9a46db1eeac091aab4596281cde to your computer and use it in GitHub Desktop.
Save ulusoyca/4ef6d9a46db1eeac091aab4596281cde to your computer and use it in GitHub Desktop.
LogoutFab02
class LogoutFab extends StatelessWidget {
final VoidCallback onLogout;
final Color color;
const LogoutFab({Key key, @required this.onLogout, this.color}) : super(key: key);
@override
Widget build(BuildContext context) {
final authViewModel = context.watch<AuthViewModel>();
return authViewModel.logingOut ? _inProgressFab() : _extendedFab(authViewModel);
}
FloatingActionButton _inProgressFab() {
return FloatingActionButton(
onPressed: null,
child: CircularProgressIndicator(backgroundColor: Colors.white),
foregroundColor: color == null ? Colors.white : color.onTextColor(),
backgroundColor: color,
);
}
FloatingActionButton _extendedFab(AuthViewModel authViewModel) {
return FloatingActionButton.extended(
icon: Icon(Icons.exit_to_app),
onPressed: () async {
await authViewModel.onLogoutTap();
onLogout();
},
foregroundColor: color == null ? Colors.white : color.onTextColor(),
backgroundColor: color,
label: Padding(
padding: const EdgeInsets.all(16.0),
child: Text('Logout'),
),
);
}
}
@eximius313
Copy link

According to this video creating own FloatingActionButton and FloatingActionButton Widgets is preferrable over helper methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment