From f323df9f0f1450c6dd607944e9cfeaf74c8d420d Mon Sep 17 00:00:00 2001 From: sindhu Date: Fri, 12 Jan 2024 14:52:17 +0700 Subject: [PATCH] step 4 : home screen --- app_petty_cash/lib/app/route.dart | 36 ++++- app_petty_cash/lib/main.dart | 134 +++--------------- .../lib/screen/home/home_screen.dart | 66 +++++++++ .../lib/screen/login/block_bodyv2.dart | 41 +++--- .../screen/transaksi/transaksi_screen.dart | 10 ++ 5 files changed, 154 insertions(+), 133 deletions(-) create mode 100644 app_petty_cash/lib/screen/home/home_screen.dart create mode 100644 app_petty_cash/lib/screen/transaksi/transaksi_screen.dart diff --git a/app_petty_cash/lib/app/route.dart b/app_petty_cash/lib/app/route.dart index 56a2d9a..40cbf2f 100644 --- a/app_petty_cash/lib/app/route.dart +++ b/app_petty_cash/lib/app/route.dart @@ -1,17 +1,49 @@ +import 'package:app_petty_cash/screen/home/home_screen.dart'; import 'package:flutter/material.dart'; import '../screen/login/login_screen.dart'; +import '../screen/splash/splash_screen.dart'; const loginRoute = "/loginRoute"; const menuRoute = "/menuRoute"; +const splashScreen = "/splashScreen"; +const homeRoute = "/homeRoute"; class AppRoute { static Route generateRoute(RouteSettings settings) { + // splash screen + if (settings.name == splashScreen) { + return MaterialPageRoute(builder: (context) { + return MediaQuery( + data: MediaQuery.of(context).copyWith( + textScaleFactor: 1.0, + padding: EdgeInsets.all(0), + ), + child: SplashScreen(), + ); + }); + } + + // home screen + if (settings.name == homeRoute) { + return MaterialPageRoute(builder: (context) { + return MediaQuery( + data: MediaQuery.of(context).copyWith( + textScaleFactor: 1.0, + padding: EdgeInsets.all(0), + ), + child: HomeScreen(), + ); + }); + } + // default return MaterialPageRoute(builder: (context) { return MediaQuery( - data: MediaQuery.of(context) - .copyWith(textScaleFactor: 1.0, padding: const EdgeInsets.all(0)), + data: MediaQuery.of(context).copyWith( + textScaleFactor: 1.0, + padding: const EdgeInsets.all(0), + ), child: const LoginScreen(), ); }); diff --git a/app_petty_cash/lib/main.dart b/app_petty_cash/lib/main.dart index dda5554..6413458 100644 --- a/app_petty_cash/lib/main.dart +++ b/app_petty_cash/lib/main.dart @@ -1,125 +1,35 @@ import 'package:flutter/material.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'app/route.dart'; -void main() { - runApp(const MyApp()); +void main() async { + WidgetsFlutterBinding.ensureInitialized(); + runApp(const ProviderScope(child: MyApp())); } class MyApp extends StatelessWidget { - const MyApp({super.key}); + const MyApp({Key? key}) : super(key: key); - // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( - title: 'Flutter Demo', + title: 'App Petty Cash', theme: ThemeData( - // This is the theme of your application. - // - // TRY THIS: Try running your application with "flutter run". You'll see - // the application has a blue toolbar. Then, without quitting the app, - // try changing the seedColor in the colorScheme below to Colors.green - // and then invoke "hot reload" (save your changes or press the "hot - // reload" button in a Flutter-supported IDE, or press "r" if you used - // the command line to start the app). - // - // Notice that the counter didn't reset back to zero; the application - // state is not lost during the reload. To reset the state, use hot - // restart instead. - // - // This works for code too, not just values: Most code changes can be - // tested with just a hot reload. - colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), - useMaterial3: true, + primarySwatch: Colors.red, ), - home: const MyHomePage(title: 'Flutter Demo Home Page'), + scrollBehavior: MaterialScrollBehavior().copyWith( + dragDevices: { + PointerDeviceKind.mouse, + PointerDeviceKind.touch, + PointerDeviceKind.stylus, + PointerDeviceKind.unknown, + }, + ), + debugShowCheckedModeBanner: false, + // initialRoute: loginRoute, + initialRoute: splashScreen, + onGenerateRoute: AppRoute.generateRoute, ); } -} - -class MyHomePage extends StatefulWidget { - const MyHomePage({super.key, required this.title}); - - // This widget is the home page of your application. It is stateful, meaning - // that it has a State object (defined below) that contains fields that affect - // how it looks. - - // This class is the configuration for the state. It holds the values (in this - // case the title) provided by the parent (in this case the App widget) and - // used by the build method of the State. Fields in a Widget subclass are - // always marked "final". - - final String title; - - @override - State createState() => _MyHomePageState(); -} - -class _MyHomePageState extends State { - int _counter = 0; - - void _incrementCounter() { - setState(() { - // This call to setState tells the Flutter framework that something has - // changed in this State, which causes it to rerun the build method below - // so that the display can reflect the updated values. If we changed - // _counter without calling setState(), then the build method would not be - // called again, and so nothing would appear to happen. - _counter++; - }); - } - - @override - Widget build(BuildContext context) { - // This method is rerun every time setState is called, for instance as done - // by the _incrementCounter method above. - // - // The Flutter framework has been optimized to make rerunning build methods - // fast, so that you can just rebuild anything that needs updating rather - // than having to individually change instances of widgets. - return Scaffold( - appBar: AppBar( - // TRY THIS: Try changing the color here to a specific color (to - // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar - // change color while the other colors stay the same. - backgroundColor: Theme.of(context).colorScheme.inversePrimary, - // Here we take the value from the MyHomePage object that was created by - // the App.build method, and use it to set our appbar title. - title: Text(widget.title), - ), - body: Center( - // Center is a layout widget. It takes a single child and positions it - // in the middle of the parent. - child: Column( - // Column is also a layout widget. It takes a list of children and - // arranges them vertically. By default, it sizes itself to fit its - // children horizontally, and tries to be as tall as its parent. - // - // Column has various properties to control how it sizes itself and - // how it positions its children. Here we use mainAxisAlignment to - // center the children vertically; the main axis here is the vertical - // axis because Columns are vertical (the cross axis would be - // horizontal). - // - // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint" - // action in the IDE, or press "p" in the console), to see the - // wireframe for each widget. - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headlineMedium, - ), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. - ); - } -} +} \ No newline at end of file diff --git a/app_petty_cash/lib/screen/home/home_screen.dart b/app_petty_cash/lib/screen/home/home_screen.dart new file mode 100644 index 0000000..3dedaff --- /dev/null +++ b/app_petty_cash/lib/screen/home/home_screen.dart @@ -0,0 +1,66 @@ +import 'package:app_petty_cash/app/route.dart'; +import 'package:flutter/material.dart'; + +class HomeScreen extends StatelessWidget { + const HomeScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text('Home Screen'), + ), + drawer: Drawer( + child: ListView( + padding: EdgeInsets.zero, + children: [ + DrawerHeader( + decoration: BoxDecoration( + color: Colors.blue, + ), + child: Text( + 'Drawer Header', + style: TextStyle( + color: Colors.white, + fontSize: 24, + ), + ), + ), + ListTile( + title: Text('Home'), + onTap: () { + // Handle navigation to Home screen + Navigator.pop(context); + Navigator.pushNamed(context, homeRoute); + }, + ), + ListTile( + title: Text('Transaksi'), + onTap: () { + // Handle navigation to Transaksi screen + Navigator.pop(context); + }, + ), + ListTile( + title: Text('User'), + onTap: () { + // Handle navigation to User screen + Navigator.pop(context); + }, + ), + ListTile( + title: Text('Logout'), + onTap: () { + // Handle logout logic + Navigator.pop(context); + }, + ), + ], + ), + ), + body: Center( + child: Text('Home Screen Content'), + ), + ); + } +} diff --git a/app_petty_cash/lib/screen/login/block_bodyv2.dart b/app_petty_cash/lib/screen/login/block_bodyv2.dart index 42b75c3..6c35c48 100644 --- a/app_petty_cash/lib/screen/login/block_bodyv2.dart +++ b/app_petty_cash/lib/screen/login/block_bodyv2.dart @@ -311,25 +311,28 @@ class BlockBodyV2 extends HookConsumerWidget { width: Constant.getActualXPhone(context: context, x: 320), height: Constant.getActualYPhone(context: context, y: 50), child: ElevatedButton( - onPressed: (isSuccess.value == true) - ? () {} - : () { - if (ctrlUsername.text.isEmpty || - ctrlDokterId.text.isEmpty || - ctrlPassword.text.isEmpty) { - isLoading.value = true; - errorMessage.value = 'Inputan harus diisi'; - Timer(const Duration(seconds: 3), () { - isLoading.value = false; - errorMessage.value = ""; - }); - } else { - ref.read(loginProvider.notifier).login( - username: ctrlUsername.text, - dokterId: ctrlDokterId.text, - password: ctrlPassword.text); - } - }, + onPressed: () { + Navigator.of(context).pushNamed(homeRoute); + }, + // onPressed: (isSuccess.value == true) + // ? () {} + // : () { + // if (ctrlUsername.text.isEmpty || + // ctrlDokterId.text.isEmpty || + // ctrlPassword.text.isEmpty) { + // isLoading.value = true; + // errorMessage.value = 'Inputan harus diisi'; + // Timer(const Duration(seconds: 3), () { + // isLoading.value = false; + // errorMessage.value = ""; + // }); + // } else { + // ref.read(loginProvider.notifier).login( + // username: ctrlUsername.text, + // dokterId: ctrlDokterId.text, + // password: ctrlPassword.text); + // } + // }, style: ButtonStyle( backgroundColor: MaterialStateColor.resolveWith((st) => (isSuccess.value == true) diff --git a/app_petty_cash/lib/screen/transaksi/transaksi_screen.dart b/app_petty_cash/lib/screen/transaksi/transaksi_screen.dart new file mode 100644 index 0000000..05eb5d5 --- /dev/null +++ b/app_petty_cash/lib/screen/transaksi/transaksi_screen.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; + +class TransaksiScreen extends StatelessWidget { + const TransaksiScreen({super.key}); + + @override + Widget build(BuildContext context) { + return const Placeholder(); + } +} \ No newline at end of file