Open name27 opened 1 year ago
import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:use_get_x_app/controller/app_setting_controller.dart'; import 'package:use_get_x_app/page/main_page.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { var controller = Get.put(AppSettingController( isSoundOn: true, isNotificationOn: false, appAuthor: 'Author', appName: 'App', appVersion: '0.1', appPackageName: 'App Package Name')); return GetMaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData.dark(), home: MainPage(), ); } }
import 'package:get/get.dart'; class AppSettingController extends GetxController { bool isSoundOn; bool isNotificationOn; String appVersion; String appName; String appAuthor; String appPackageName; DateTime? lastUpdated; AppSettingController( {required this.isSoundOn, required this.isNotificationOn, required this.appAuthor, required this.appName, required this.appVersion, required this.appPackageName, this.lastUpdated}); }
import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:use_get_x_app/controller/app_setting_controller.dart'; import 'package:use_get_x_app/page/sub_page.dart'; class MainPage extends StatelessWidget { const MainPage({super.key}); @override Widget build(BuildContext context) { var controller = Get.find<AppSettingController>(); return Scaffold( appBar: AppBar( centerTitle: true, title: Row( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [Text(controller.appName), Text(controller.appVersion)], ), actions: [ controller.isSoundOn ? IconButton(onPressed: () {}, icon: Icon(Icons.volume_up)) : IconButton(onPressed: () {}, icon: Icon(Icons.volume_off)), controller.isNotificationOn ? IconButton( onPressed: () {}, icon: Icon(Icons.notifications_active)) : IconButton( onPressed: () {}, icon: Icon(Icons.notifications_off)), ], ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [Text('App Author : ${controller.appAuthor}')], ), ), floatingActionButton: FloatingActionButton( onPressed: () { Get.to(SubPage()); }, child: Icon(Icons.navigate_next), ), ); } }
import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../controller/app_setting_controller.dart'; class SubPage extends StatelessWidget { const SubPage({super.key}); @override Widget build(BuildContext context) { var controller = Get.find<AppSettingController>(); return Scaffold( appBar: AppBar( centerTitle: true, title: Row( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [Text(controller.appName), Text(controller.appVersion)], ), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text('Sub Page'), ], )), floatingActionButton: FloatingActionButton( onPressed: () { Get.back(); }, child: Icon(Icons.navigate_before), ), ); } }
main.dart
app_setting_controller.dart
main_page.dart
sub_page.dart