Konten [Tampil]
Berikut ini codenya :
App bindings
import 'package:bebas/splash_controller.dart';import 'package:get/get.dart';import 'home_controller.dart';class AppBindings implements Bindings {@overridevoid dependencies() {Get.lazyPut<SplashController>(() => SplashController());Get.lazyPut<HomeController>(() => HomeController());}}
App Routes :
import 'package:bebas/splash_screen.dart';import 'package:get/get.dart';import 'app_bindings.dart';import 'home_page.dart';class AppRoutes {static const String splash = '/';static const String home = '/home';static final List<GetPage> routes = [GetPage(name: splash,page: () => SplashScreen(),binding: AppBindings(),),GetPage(name: home,page: () => HomePage(),binding: AppBindings(),),];}
home controller
import 'package:get/get.dart';class HomeController extends GetxController {// Logic atau method yang diperlukan untuk HomePage}
home page
import 'package:flutter/material.dart';import 'package:get/get_state_manager/src/simple/get_view.dart';import 'home_controller.dart';class HomePage extends GetWidget<HomeController> {@overrideWidget build(BuildContext context) {return Scaffold(body: Center(child: Text('Home Page'),),);}}
main :
import 'package:flutter/material.dart';import 'package:get/get.dart';import 'app_routes.dart';void main() {runApp(MyApp());}class MyApp extends StatelessWidget {@overrideWidget build(BuildContext context) {return GetMaterialApp(title: 'Your App',initialRoute: AppRoutes.splash,getPages: AppRoutes.routes,);}}
Splashcreen controller :
import 'package:get/get.dart';import 'package:get/get_state_manager/src/simple/get_controllers.dart';class SplashController extends GetxController {@overridevoid onReady() {super.onReady();// Delay 2 detik sebelum pindah ke halaman utamaFuture.delayed(Duration(seconds: 2), () {Get.offNamed('/home');});}}
splash screen :
import 'package:bebas/splash_controller.dart';import 'package:flutter/material.dart';import 'package:get/get.dart';class SplashScreen extends GetWidget<SplashController> {@overrideWidget build(BuildContext context) {return Scaffold(body: Center(child: Text('Splash Screen'),),);}}