Source : link getX
import 'package:flutter/material.dart';
import 'package:get/get.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GetMaterialApp(
home: MainPage(),
initialBinding: MainBinding(),
getPages: [
GetPage(
name: '/',
page: () => MainPage(),
binding: MainBinding(),
),
GetPage(
name: '/second',
page: () => SecondPage(),
binding: SecondBinding(),
),
],
);
}
}
class MainBinding extends Bindings {
@override
void dependencies() {
// Tambahkan dependencies yang diperlukan untuk halaman Main di sini
Get.put(MainController());
}
}
class SecondBinding extends Bindings {
@override
void dependencies() {
// Tambahkan dependencies yang diperlukan untuk halaman Second di sini
Get.put(SecondController());
}
}
class MainController extends GetxController {
// Logika dan state untuk halaman Main di sini
}
class SecondController extends GetxController {
// Logika dan state untuk halaman Second di sini
}
class MainPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final MainController mainController = Get.find<MainController>();
return Scaffold(
appBar: AppBar(
title: Text('Main Page'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
Get.toNamed('/second');
},
child: Text('Go to Second Page'),
),
),
);
}
}
class SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final SecondController secondController = Get.find<SecondController>();
return Scaffold(
appBar: AppBar(
title: Text('Second Page'),
),
body: Center(
child: ElevatedButton(
onPressed: () {
Get.back();
},
child: Text('Go Back'),
),
),
);
}
}