Skip to content

Commit

Permalink
put example back
Browse files Browse the repository at this point in the history
  • Loading branch information
jonataslaw committed Mar 8, 2024
1 parent 3a4dced commit 5155b2f
Showing 1 changed file with 146 additions and 32 deletions.
178 changes: 146 additions & 32 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,59 +1,173 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

// void main() {
// runApp(const MyApp());
// }

// class MyApp extends StatelessWidget {
// const MyApp({Key? key}) : super(key: key);

// @override
// Widget build(BuildContext context) {
// return GetMaterialApp(
// theme: ThemeData(useMaterial3: true),
// debugShowCheckedModeBanner: false,
// enableLog: true,
// logWriterCallback: Logger.write,
// initialRoute: AppPages.INITIAL,
// getPages: AppPages.routes,
// locale: TranslationService.locale,
// fallbackLocale: TranslationService.fallbackLocale,
// translations: TranslationService(),
// );
// }
// }

/// Nav 2 snippet
void main() {
runApp(MyApp());
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
// This widget is the root of your application.
const MyApp({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Scaffold demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
getPages: [
GetPage(
participatesInRootNavigator: true,
name: '/first',
page: () => const First()),
GetPage(
name: '/second',
page: () => const Second(),
transition: Transition.downToUp,
),
GetPage(
name: '/third',
page: () => const Third(),
),
],
debugShowCheckedModeBanner: false,
);
}
}

class MyHomePage extends StatelessWidget {
class FirstController extends GetxController {
@override
void onClose() {
print('on close first');
super.onClose();
}
}

class First extends StatelessWidget {
const First({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
print('First rebuild');
Get.put(FirstController());
return Scaffold(
appBar: AppBar(
title: Text('Test'),
centerTitle: true,
backgroundColor: Colors.green,
),
bottomNavigationBar: SizedBox(
width: double.infinity,
child: ElevatedButton(
child: Text('Tap me when Snackbar appears'),
title: const Text('page one'),
leading: IconButton(
icon: const Icon(Icons.more),
onPressed: () {
print('This should clicked');
Get.snackbar(
'title',
"message",
mainButton:
TextButton(onPressed: () {}, child: const Text('button')),
isDismissible: true,
duration: Duration(seconds: 5),
snackbarStatus: (status) => print(status),
);
// print('THEME CHANGED');
// Get.changeTheme(
// Get.isDarkMode ? ThemeData.light() : ThemeData.dark());
},
),
),
body: Center(
child: ElevatedButton(
child: Text('Open Snackbar'),
onPressed: () {
Get.snackbar(
"Snackbar Showed",
"Please click the button on BottomNavigationBar",
icon: Icon(Icons.check, color: Colors.green),
backgroundColor: Colors.white,
snackStyle: SnackStyle.floating,
borderRadius: 20,
isDismissible: false,
snackPosition: SnackPosition.bottom,
margin: EdgeInsets.fromLTRB(50, 15, 50, 15),
);
},
child: SizedBox(
height: 300,
width: 300,
child: ElevatedButton(
onPressed: () {
Get.toNamed('/second?id=123');
},
child: const Text('next screen'),
),
),
),
);
}
}

class SecondController extends GetxController {
final textEdit = TextEditingController();
@override
void onClose() {
print('on close second');
textEdit.dispose();
super.onClose();
}
}

class Second extends StatelessWidget {
const Second({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
final controller = Get.put(SecondController());
print('second rebuild');
return Scaffold(
appBar: AppBar(
title: Text('page two ${Get.parameters["id"]}'),
),
body: Center(
child: Column(
children: [
Expanded(
child: TextField(
controller: controller.textEdit,
)),
SizedBox(
height: 300,
width: 300,
child: ElevatedButton(
onPressed: () {},
child: const Text('next screen'),
),
),
],
),
),
);
}
}

class Third extends StatelessWidget {
const Third({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.red,
appBar: AppBar(
title: const Text('page three'),
),
body: Center(
child: SizedBox(
height: 300,
width: 300,
child: ElevatedButton(
onPressed: () {},
child: const Text('go to first screen'),
),
),
),
);
Expand Down

0 comments on commit 5155b2f

Please sign in to comment.