Skip to content

Instantly share code, notes, and snippets.

@ScottS2017
Created November 27, 2018 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ScottS2017/3288c7e7e9a014430e56dd6be4c259ab to your computer and use it in GitHub Desktop.
Save ScottS2017/3288c7e7e9a014430e56dd6be4c259ab to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
/// Use these booleans to see how each approach works, use the one that fits your needs
/// *** For some strange reason HotReload is not responding to changes in these bools
/// but if you use HotRestart then it's fine.
///
/// Are you going to be using the setting button?
final bool useSettingButton = true;
/// Is the user already logged in?
final bool userIsLoggedIn = true;
@override
Widget build(BuildContext context) {
return MaterialApp(
home: useSettingButton == true ?
UsingSettingsButton(userIsLoggedIn: userIsLoggedIn) :
DoesNotUseSettingButton(loggedIn: userIsLoggedIn),
);
}
}
class DoesNotUseSettingButton extends StatelessWidget {
final bool loggedIn;
DoesNotUseSettingButton({
@required this.loggedIn,
});
@override
Widget build(BuildContext context) {
Widget result;
if (loggedIn == true) {
result = LoggedIn();
} else {
result = NotLoggedIn();
}
return result;
}
}
class UsingSettingsButton extends StatelessWidget {
const UsingSettingsButton({
Key key,
@required this.userIsLoggedIn,
}) : super(key: key);
final bool userIsLoggedIn;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Rera Farm'),
actions: <Widget>[
PopupMenuButton(
itemBuilder: (BuildContext context) {
return <PopupMenuEntry>[
PopupMenuItem(
child: ListTile(
title: Text('Settings'),
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) =>
userIsLoggedIn == true ?
LoggedIn() :
NotLoggedIn(),
),
);
},
),
),
];
},
)
],
),
body: Container(
height: double.infinity,
width: double.infinity,
color: Colors.blue,
),
);
}
}
class LoggedIn extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: double.infinity,
width: double.infinity,
color: Colors.green,
);
}
}
class NotLoggedIn extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: double.infinity,
width: double.infinity,
color: Colors.red,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment