Showing
1 changed file
with
146 additions
and
32 deletions
| 1 | import 'package:flutter/material.dart'; | 1 | import 'package:flutter/material.dart'; |
| 2 | import 'package:get/get.dart'; | 2 | import 'package:get/get.dart'; |
| 3 | 3 | ||
| 4 | +// void main() { | ||
| 5 | +// runApp(const MyApp()); | ||
| 6 | +// } | ||
| 7 | + | ||
| 8 | +// class MyApp extends StatelessWidget { | ||
| 9 | +// const MyApp({Key? key}) : super(key: key); | ||
| 10 | + | ||
| 11 | +// @override | ||
| 12 | +// Widget build(BuildContext context) { | ||
| 13 | +// return GetMaterialApp( | ||
| 14 | +// theme: ThemeData(useMaterial3: true), | ||
| 15 | +// debugShowCheckedModeBanner: false, | ||
| 16 | +// enableLog: true, | ||
| 17 | +// logWriterCallback: Logger.write, | ||
| 18 | +// initialRoute: AppPages.INITIAL, | ||
| 19 | +// getPages: AppPages.routes, | ||
| 20 | +// locale: TranslationService.locale, | ||
| 21 | +// fallbackLocale: TranslationService.fallbackLocale, | ||
| 22 | +// translations: TranslationService(), | ||
| 23 | +// ); | ||
| 24 | +// } | ||
| 25 | +// } | ||
| 26 | + | ||
| 27 | +/// Nav 2 snippet | ||
| 4 | void main() { | 28 | void main() { |
| 5 | - runApp(MyApp()); | 29 | + runApp(const MyApp()); |
| 6 | } | 30 | } |
| 7 | 31 | ||
| 8 | class MyApp extends StatelessWidget { | 32 | class MyApp extends StatelessWidget { |
| 9 | -// This widget is the root of your application. | 33 | + const MyApp({Key? key}) : super(key: key); |
| 34 | + | ||
| 10 | @override | 35 | @override |
| 11 | Widget build(BuildContext context) { | 36 | Widget build(BuildContext context) { |
| 12 | return GetMaterialApp( | 37 | return GetMaterialApp( |
| 13 | - title: 'Scaffold demo', | ||
| 14 | - theme: ThemeData( | ||
| 15 | - primarySwatch: Colors.blue, | ||
| 16 | - ), | ||
| 17 | - home: MyHomePage(), | 38 | + getPages: [ |
| 39 | + GetPage( | ||
| 40 | + participatesInRootNavigator: true, | ||
| 41 | + name: '/first', | ||
| 42 | + page: () => const First()), | ||
| 43 | + GetPage( | ||
| 44 | + name: '/second', | ||
| 45 | + page: () => const Second(), | ||
| 46 | + transition: Transition.downToUp, | ||
| 47 | + ), | ||
| 48 | + GetPage( | ||
| 49 | + name: '/third', | ||
| 50 | + page: () => const Third(), | ||
| 51 | + ), | ||
| 52 | + ], | ||
| 18 | debugShowCheckedModeBanner: false, | 53 | debugShowCheckedModeBanner: false, |
| 19 | ); | 54 | ); |
| 20 | } | 55 | } |
| 21 | } | 56 | } |
| 22 | 57 | ||
| 23 | -class MyHomePage extends StatelessWidget { | 58 | +class FirstController extends GetxController { |
| 59 | + @override | ||
| 60 | + void onClose() { | ||
| 61 | + print('on close first'); | ||
| 62 | + super.onClose(); | ||
| 63 | + } | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +class First extends StatelessWidget { | ||
| 67 | + const First({Key? key}) : super(key: key); | ||
| 68 | + | ||
| 24 | @override | 69 | @override |
| 25 | Widget build(BuildContext context) { | 70 | Widget build(BuildContext context) { |
| 71 | + print('First rebuild'); | ||
| 72 | + Get.put(FirstController()); | ||
| 26 | return Scaffold( | 73 | return Scaffold( |
| 27 | appBar: AppBar( | 74 | appBar: AppBar( |
| 28 | - title: Text('Test'), | ||
| 29 | - centerTitle: true, | ||
| 30 | - backgroundColor: Colors.green, | ||
| 31 | - ), | ||
| 32 | - bottomNavigationBar: SizedBox( | ||
| 33 | - width: double.infinity, | ||
| 34 | - child: ElevatedButton( | ||
| 35 | - child: Text('Tap me when Snackbar appears'), | 75 | + title: const Text('page one'), |
| 76 | + leading: IconButton( | ||
| 77 | + icon: const Icon(Icons.more), | ||
| 36 | onPressed: () { | 78 | onPressed: () { |
| 37 | - print('This should clicked'); | 79 | + Get.snackbar( |
| 80 | + 'title', | ||
| 81 | + "message", | ||
| 82 | + mainButton: | ||
| 83 | + TextButton(onPressed: () {}, child: const Text('button')), | ||
| 84 | + isDismissible: true, | ||
| 85 | + duration: Duration(seconds: 5), | ||
| 86 | + snackbarStatus: (status) => print(status), | ||
| 87 | + ); | ||
| 88 | + // print('THEME CHANGED'); | ||
| 89 | + // Get.changeTheme( | ||
| 90 | + // Get.isDarkMode ? ThemeData.light() : ThemeData.dark()); | ||
| 38 | }, | 91 | }, |
| 39 | ), | 92 | ), |
| 40 | ), | 93 | ), |
| 41 | body: Center( | 94 | body: Center( |
| 42 | - child: ElevatedButton( | ||
| 43 | - child: Text('Open Snackbar'), | ||
| 44 | - onPressed: () { | ||
| 45 | - Get.snackbar( | ||
| 46 | - "Snackbar Showed", | ||
| 47 | - "Please click the button on BottomNavigationBar", | ||
| 48 | - icon: Icon(Icons.check, color: Colors.green), | ||
| 49 | - backgroundColor: Colors.white, | ||
| 50 | - snackStyle: SnackStyle.floating, | ||
| 51 | - borderRadius: 20, | ||
| 52 | - isDismissible: false, | ||
| 53 | - snackPosition: SnackPosition.bottom, | ||
| 54 | - margin: EdgeInsets.fromLTRB(50, 15, 50, 15), | ||
| 55 | - ); | ||
| 56 | - }, | 95 | + child: SizedBox( |
| 96 | + height: 300, | ||
| 97 | + width: 300, | ||
| 98 | + child: ElevatedButton( | ||
| 99 | + onPressed: () { | ||
| 100 | + Get.toNamed('/second?id=123'); | ||
| 101 | + }, | ||
| 102 | + child: const Text('next screen'), | ||
| 103 | + ), | ||
| 104 | + ), | ||
| 105 | + ), | ||
| 106 | + ); | ||
| 107 | + } | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +class SecondController extends GetxController { | ||
| 111 | + final textEdit = TextEditingController(); | ||
| 112 | + @override | ||
| 113 | + void onClose() { | ||
| 114 | + print('on close second'); | ||
| 115 | + textEdit.dispose(); | ||
| 116 | + super.onClose(); | ||
| 117 | + } | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +class Second extends StatelessWidget { | ||
| 121 | + const Second({Key? key}) : super(key: key); | ||
| 122 | + | ||
| 123 | + @override | ||
| 124 | + Widget build(BuildContext context) { | ||
| 125 | + final controller = Get.put(SecondController()); | ||
| 126 | + print('second rebuild'); | ||
| 127 | + return Scaffold( | ||
| 128 | + appBar: AppBar( | ||
| 129 | + title: Text('page two ${Get.parameters["id"]}'), | ||
| 130 | + ), | ||
| 131 | + body: Center( | ||
| 132 | + child: Column( | ||
| 133 | + children: [ | ||
| 134 | + Expanded( | ||
| 135 | + child: TextField( | ||
| 136 | + controller: controller.textEdit, | ||
| 137 | + )), | ||
| 138 | + SizedBox( | ||
| 139 | + height: 300, | ||
| 140 | + width: 300, | ||
| 141 | + child: ElevatedButton( | ||
| 142 | + onPressed: () {}, | ||
| 143 | + child: const Text('next screen'), | ||
| 144 | + ), | ||
| 145 | + ), | ||
| 146 | + ], | ||
| 147 | + ), | ||
| 148 | + ), | ||
| 149 | + ); | ||
| 150 | + } | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +class Third extends StatelessWidget { | ||
| 154 | + const Third({Key? key}) : super(key: key); | ||
| 155 | + | ||
| 156 | + @override | ||
| 157 | + Widget build(BuildContext context) { | ||
| 158 | + return Scaffold( | ||
| 159 | + backgroundColor: Colors.red, | ||
| 160 | + appBar: AppBar( | ||
| 161 | + title: const Text('page three'), | ||
| 162 | + ), | ||
| 163 | + body: Center( | ||
| 164 | + child: SizedBox( | ||
| 165 | + height: 300, | ||
| 166 | + width: 300, | ||
| 167 | + child: ElevatedButton( | ||
| 168 | + onPressed: () {}, | ||
| 169 | + child: const Text('go to first screen'), | ||
| 170 | + ), | ||
| 57 | ), | 171 | ), |
| 58 | ), | 172 | ), |
| 59 | ); | 173 | ); |
-
Please register or login to post a comment