Skip to content

Instantly share code, notes, and snippets.

@Grohden
Created May 23, 2020 03:07
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 Grohden/d1530f626b39230e6378b75afcdc5ac0 to your computer and use it in GitHub Desktop.
Save Grohden/d1530f626b39230e6378b75afcdc5ac0 to your computer and use it in GitHub Desktop.
Prototype for home screen decentralisation of routes 'upper' widgets
class _HomeItem {
_HomeItem({
@required this.appbar,
@required this.body
});
final PreferredSizeWidget appbar;
final Widget body;
}
class HomeController extends RxController {
static HomeController get to => Get.find();
final currentRoute = 0.obs;
}
class HomeScreen extends StatelessWidget {
final _homeItems = [
_HomeItem(
appbar: AgendaScreen.appbar(),
body: AgendaScreen(),
),
_HomeItem(
appbar: OrderListScreen.appbar(),
body: OrderListScreen(),
),
_HomeItem(
appbar: RequestListScreen.appbar(),
body: RequestListScreen(),
),
_HomeItem(
appbar: ProfileScreen.appbar(),
body: ProfileScreen(),
),
];
Widget _buildScaffold(BuildContext context, HomeController _) {
final theme = Theme.of(context);
final selected = theme.accentColor;
final unselected = theme.iconTheme.color.withOpacity(0.7);
final index = _.currentRoute.value;
final route = _homeItems[index];
return Scaffold(
appBar: route.appbar,
body: route.body,
bottomNavigationBar: BottomNavigationBar(
currentIndex: index,
selectedItemColor: selected,
unselectedItemColor: unselected,
onTap: (index) {
_.currentRoute.value = index;
},
items: const <BottomNavigationBarItem>[
BottomNavigationBarItem(
icon: Icon(Icons.calendar_today),
title: Text('Agenda'),
),
BottomNavigationBarItem(
icon: Icon(Icons.business),
title: Text('Ordens'),
),
BottomNavigationBarItem(
icon: Icon(Icons.school),
title: Text('Solicitações'),
),
BottomNavigationBarItem(
icon: Icon(Icons.account_circle),
title: Text('Perfil'),
),
],
),
);
}
@override
Widget build(BuildContext context) {
return GetX<HomeController>(
init: HomeController(),
builder: (_) => _buildScaffold(context, _),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment