Skip to content

Instantly share code, notes, and snippets.

@IsmailAlamKhan
Created March 8, 2021 13:19
Show Gist options
  • Save IsmailAlamKhan/aeb20b07a3a6daa7688585e1e52e224c to your computer and use it in GitHub Desktop.
Save IsmailAlamKhan/aeb20b07a3a6daa7688585e1e52e224c to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
runApp(
GetMaterialApp(
debugShowCheckedModeBanner: false,
initialRoute: '/',
themeMode: ThemeMode.system,
darkTheme: ThemeData.dark(),
theme: ThemeData.dark(),
defaultTransition: Transition.fade,
initialBinding: BindingsBuilder.put(() => HomeController()),
home: Home(),
),
);
}
class HomeController extends GetxController {
final index = 0.obs;
int get currentIndex => index.value;
@override
void onInit() {
ever(index, (int val) {
Get.toNamed('${val + 1}', id: 1);
});
super.onInit();
}
}
class Home extends GetWidget<HomeController> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Navigator(
initialRoute: '1',
key: Get.nestedKey(1),
onGenerateRoute: (settings) {
switch (settings.name) {
case '1':
return GetPageRoute(
page: () => Center(child: Text('1')),
);
break;
case '2':
return GetPageRoute(
page: () => Center(child: Text('2')),
);
break;
default:
return GetPageRoute(
page: () => Center(child: Text('Error')),
);
}
},
),
),
bottomNavigationBar: Obx(
() => BottomNavigationBar(
currentIndex: controller.currentIndex,
onTap: controller.index,
selectedItemColor: Colors.amber,
items: [
BottomNavigationBarItem(
icon: Icon(Icons.access_alarm),
label: 'Hello',
),
BottomNavigationBarItem(
icon: Icon(Icons.access_alarm),
label: 'Hello',
),
BottomNavigationBarItem(
icon: Icon(Icons.access_alarm),
label: 'Hello',
),
BottomNavigationBarItem(
icon: Icon(Icons.access_alarm),
label: 'Hello',
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment