Skip to content

Commit

Permalink
Merge pull request #3179 from jonataslaw/redirect-fix
Browse files Browse the repository at this point in the history
Fix redirect in redirectDelegate and fix Get.until
  • Loading branch information
jonataslaw committed Aug 16, 2024
2 parents 5da0cb6 + fe7e812 commit afdc567
Show file tree
Hide file tree
Showing 16 changed files with 492 additions and 653 deletions.
2 changes: 1 addition & 1 deletion example/.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ migration:
- platform: root
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
- platform: web
- platform: android
create_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819
base_revision: 80c2e84975bbd28ecf5f8d4bd4ca5a2490bfc819

Expand Down
313 changes: 160 additions & 153 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import 'lang/translation_service.dart';
import 'routes/app_pages.dart';
import 'shared/logger/logger_utils.dart';
// import 'lang/translation_service.dart';
// import 'routes/app_pages.dart';
// import 'shared/logger/logger_utils.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(const MyApp());
// }
Expand All @@ -39,141 +15,172 @@ class MyApp extends StatelessWidget {
// @override
// Widget build(BuildContext context) {
// return GetMaterialApp(
// getPages: [
// GetPage(
// participatesInRootNavigator: true,
// name: '/first',
// page: () => const First()),
// GetPage(
// name: '/second',
// page: () => const Second(),
// transition: Transition.downToUp,
// ),
// GetPage(
// name: '/third',
// page: () => const Third(),
// ),
// ],
// 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(),
// );
// }
// }

// class FirstController extends GetxController {
// @override
// void onClose() {
// print('on close first');
// super.onClose();
// }
// }
/// Nav 2 snippet
void main() {
runApp(const MyApp());
}

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

// @override
// Widget build(BuildContext context) {
// print('First rebuild');
// Get.put(FirstController());
// return Scaffold(
// appBar: AppBar(
// title: const Text('page one'),
// leading: IconButton(
// icon: const Icon(Icons.more),
// onPressed: () {
// 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: SizedBox(
// height: 300,
// width: 300,
// child: ElevatedButton(
// onPressed: () {
// Get.toNamed('/second?id=123');
// },
// child: const Text('next screen'),
// ),
// ),
// ),
// );
// }
// }
@override
Widget build(BuildContext context) {
return GetMaterialApp(
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 SecondController extends GetxController {
// final textEdit = TextEditingController();
// @override
// void onClose() {
// print('on close second');
// textEdit.dispose();
// super.onClose();
// }
// }
class FirstController extends GetxController {
@override
void onClose() {
print('on close first');
super.onClose();
}
}

// class Second extends StatelessWidget {
// const Second({Key? key}) : super(key: key);
class First extends StatelessWidget {
const First({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'),
// ),
// ),
// ],
// ),
// ),
// );
// }
// }
@override
Widget build(BuildContext context) {
print('First rebuild');
Get.put(FirstController());
return Scaffold(
appBar: AppBar(
title: const Text('page one'),
leading: IconButton(
icon: const Icon(Icons.more),
onPressed: () {
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: 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 Third extends StatelessWidget {
// const Third({Key? key}) : super(key: key);
class Second extends StatelessWidget {
const Second({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'),
// ),
// ),
// ),
// );
// }
// }
@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: () {
Get.toNamed('/third');
},
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: () {
Get.until((route) {
print(Get.currentRoute);
return Get.currentRoute == '/first';
});
},
child: const Text('go to first screen'),
),
),
),
);
}
}
29 changes: 0 additions & 29 deletions example/test/widget_test.dart

This file was deleted.

Loading

0 comments on commit afdc567

Please sign in to comment.