Explorar el Código

[new]增加首页

zk hace 1 año
padre
commit
de2621e673

+ 4 - 1
assets/color/color.xml

@@ -1,4 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-
+    <color name="transparent">#00FFFFFF</color>
+    <color name="colorPrimary">#6177F2</color>
+    <color name="bgColorPrimary">#FFFFFFFF</color>
+    <color name="common_txt_color">#25262A</color>
 </resources>

BIN
assets/images/main_tab_file_selected.webp


BIN
assets/images/main_tab_file_un_select.webp


BIN
assets/images/main_tab_home_selected.webp


BIN
assets/images/main_tab_home_un_select.webp


BIN
assets/images/main_tab_secretary.png


+ 2 - 0
lib/main.dart

@@ -1,6 +1,7 @@
 import 'package:electronic_assistant/resource/string_source.dart';
 import 'package:electronic_assistant/router/app_pages.dart';
 import 'package:flutter/material.dart';
+import 'package:get/get.dart';
 import 'package:get/get_navigation/src/root/get_material_app.dart';
 
 void main() {
@@ -17,6 +18,7 @@ class MyApp extends StatelessWidget {
       title: 'Flutter Demo',
       getPages: AppPage.pages,
       initialRoute: RoutePath.splash,
+      initialBinding: AppBinding(),
       theme: ThemeData(
         colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
         useMaterial3: true,

+ 48 - 0
lib/module/main/controller.dart

@@ -0,0 +1,48 @@
+import 'dart:ui';
+
+import 'package:electronic_assistant/base/base_controller.dart';
+import 'package:electronic_assistant/resource/assets.gen.dart';
+import 'package:electronic_assistant/resource/colors.gen.dart';
+import 'package:electronic_assistant/utils/expand.dart';
+import 'package:flutter/cupertino.dart';
+import 'package:get/get.dart';
+
+class MainController extends BaseController {
+  final List<TabBean> tabBeans = [
+    TabBean(
+        'main_tab_home'.tr,
+        Assets.images.mainTabHomeUnSelect.path,
+        Assets.images.mainTabHomeSelected.path,
+        "#969696".toColor(),
+        ColorName.commonTxtColor),
+    TabBean(
+        'main_tab_file'.tr,
+        Assets.images.mainTabFileUnSelect.path,
+        Assets.images.mainTabFileSelected.path,
+        "#969696".toColor(),
+        ColorName.commonTxtColor),
+  ];
+
+  final _currentIndex = 0.obs;
+
+  int get currentIndex => _currentIndex.value;
+
+  void changeIndex(int index) {
+    _currentIndex.value = index;
+  }
+
+  void updateIndex(int index) {
+    _currentIndex.value = index;
+  }
+}
+
+class TabBean {
+  final String title;
+  final String normalIcon;
+  final String selectedIcon;
+  final Color txtNormalColor;
+  final Color txtSelectedColor;
+
+  TabBean(this.title, this.normalIcon, this.selectedIcon, this.txtNormalColor,
+      this.txtSelectedColor);
+}

+ 95 - 3
lib/module/main/view.dart

@@ -1,12 +1,104 @@
 import 'package:electronic_assistant/base/base_page.dart';
+import 'package:electronic_assistant/module/main/controller.dart';
 import 'package:flutter/material.dart';
+import 'package:get/get.dart';
 
-class MainTabPage extends BasePage {
+class MainTabPage extends BasePage<MainController> {
   const MainTabPage({super.key});
 
   @override
   Widget? buildBody(BuildContext context) {
-    // TODO: implement buildBody
-    throw UnimplementedError();
+    return Scaffold(
+      body: const Center(
+        child: Text('MainTabPage'),
+      ),
+      bottomNavigationBar: BottomAppBar(
+        color: Colors.white,
+        height: 68,
+        shape: const CircularNotchedRectangle(),
+        child: Obx(() {
+          return Row(
+            mainAxisAlignment: MainAxisAlignment.spaceAround,
+            children: <Widget>[
+              SizedBox(child: bottomAppBarItem(0)),
+              const SizedBox(),
+              SizedBox(child: bottomAppBarItem(1)),
+            ],
+          );
+        }),
+      ),
+      drawer: Drawer(
+        child: Center(
+          child: Column(
+            mainAxisAlignment: MainAxisAlignment.center,
+            children: <Widget>[
+              const Text('This is the Drawer'),
+              ElevatedButton(
+                onPressed: () {},
+                child: const Text('Close Drawer'),
+              ),
+            ],
+          ),
+        ),
+      ),
+    );
   }
+
+  Widget bottomAppBarItem(int index) {
+    //设置默认未选中的状态
+    TextStyle style;
+    TabBean tabBean = controller.tabBeans[index];
+    String imagePath;
+    if (controller.currentIndex == index) {
+      //选中的话
+      style = TextStyle(fontSize: 10, color: tabBean.txtSelectedColor);
+      imagePath = tabBean.selectedIcon;
+    } else {
+      style = TextStyle(fontSize: 10, color: tabBean.txtNormalColor);
+      imagePath = tabBean.normalIcon;
+    }
+    //构造返回的Widget
+    Widget item = GestureDetector(
+      behavior: HitTestBehavior.opaque,
+      child: Center(
+        child: Column(
+          mainAxisSize: MainAxisSize.min,
+          children: <Widget>[
+            Image.asset(imagePath, width: 24, height: 24),
+            Text(
+              tabBean.title,
+              style: style,
+            )
+          ],
+        ),
+      ),
+      onTap: () {
+        if (controller.currentIndex != index) {
+          controller.updateIndex(index);
+        }
+      },
+    );
+    return item;
+  }
+
+// List<BottomNavigationBarItem> get _buildBottomBarItem {
+//   return [
+//     BottomNavigationBarItem(
+//       icon: Assets.images.mainTabHomeUnSelect.image(width: 24, height: 24),
+//       activeIcon:
+//           Assets.images.mainTabHomeSelected.image(width: 24, height: 24),
+//       label: 'main_tab_home'.tr,
+//     ),
+//     const BottomNavigationBarItem(
+//       icon: SizedBox(width: 24, height: 24),
+//       label: '',
+//     ),
+//     BottomNavigationBarItem(
+//       icon: Assets.images.mainTabFileUnSelect.image(width: 24, height: 24),
+//       activeIcon:
+//           Assets.images.mainTabFileSelected.image(width: 24, height: 24),
+//       label: 'main_tab_file'.tr,
+//     ),
+//   ];
+// }
 }

+ 0 - 10
lib/module/splash/binding.dart

@@ -1,10 +0,0 @@
-import 'package:get/get.dart';
-
-import 'controller.dart';
-
-class SplashBinding extends Bindings {
-  @override
-  void dependencies() {
-    Get.lazyPut(() => SplashController());
-  }
-}

+ 0 - 3
lib/module/splash/controller.dart

@@ -1,3 +0,0 @@
-import 'package:electronic_assistant/base/base_controller.dart';
-
-class SplashController extends BaseController {}

+ 15 - 3
lib/module/splash/view.dart

@@ -1,13 +1,25 @@
+import 'dart:async';
+
 import 'package:electronic_assistant/base/base_page.dart';
 import 'package:flutter/material.dart';
+import 'package:get/get.dart';
 
-import 'controller.dart';
+import '../../router/app_pages.dart';
 
-class SplashPage extends BasePage<SplashController> {
+class SplashPage extends BasePage {
   const SplashPage({super.key});
 
+  final splashDelayedTime = 2;
+
   @override
   Widget? buildBody(BuildContext context) {
-    return null;
+    Timer(Duration(seconds: splashDelayedTime), () {
+      Get.toNamed(RoutePath.mainTab);
+    });
+    return GestureDetector(
+        child: Text('启屏页'),
+        onTap: () {
+          Get.toNamed(RoutePath.mainTab);
+        });
   }
 }

+ 3 - 1
lib/resource/string_source.dart

@@ -5,6 +5,8 @@ class StringResource extends Translations {
   Map<String, Map<String, String>> get keys => {
         'zh_CN': {
           'app_name': '电子秘书',
-        },
+          'main_tab_home': '首页',
+          'main_tab_file': '文件',
+        }
       };
 }

+ 12 - 0
lib/router/app_pages.dart

@@ -1,3 +1,4 @@
+import 'package:electronic_assistant/module/main/controller.dart';
 import 'package:get/get.dart';
 
 import '../module/files/view.dart';
@@ -21,6 +22,17 @@ abstract class RoutePath {
   static const files = '/files';
 }
 
+class AppBinding extends Bindings {
+  @override
+  void dependencies() {
+    lazyPut(() => MainController());
+  }
+
+  void lazyPut<S>(InstanceBuilderCallback<S> builder) {
+    Get.lazyPut(builder, fenix: true);
+  }
+}
+
 final generalPages = [
   GetPage(name: RoutePath.splash, page: () => const SplashPage()),
   GetPage(name: RoutePath.login, page: () => const LoginPage()),

+ 8 - 0
lib/utils/expand.dart

@@ -0,0 +1,8 @@
+import 'dart:ui';
+
+extension HexColor on String {
+  Color toColor() {
+    final hexCode = replaceAll('#', '');
+    return Color(int.parse('FF$hexCode', radix: 16));
+  }
+}