ソースを参照

[new]增加资源管理

zk 1 年間 前
コミット
548afa7078

+ 4 - 0
assets/color/color.xml

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+
+</resources>

+ 48 - 0
assets/color/common_color.xml

@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <!-- 白色 -->
+    <color name="white">#FFFFFFFF</color>
+    <color name="white95">#F2FFFFFF</color>
+    <color name="white90">#E6FFFFFF</color>
+    <color name="white87">#DEFFFFFF</color>
+    <color name="white85">#D9FFFFFF</color>
+    <color name="white80">#CCFFFFFF</color>
+    <color name="white75">#BFFFFFFF</color>
+    <color name="white70">#B3FFFFFF</color>
+    <color name="white65">#A6FFFFFF</color>
+    <color name="white60">#99FFFFFF</color>
+    <color name="white55">#8CFFFFFF</color>
+    <color name="white50">#80FFFFFF</color>
+    <color name="white45">#73FFFFFF</color>
+    <color name="white40">#66FFFFFF</color>
+    <color name="white35">#59FFFFFF</color>
+    <color name="white30">#4DFFFFFF</color>
+    <color name="white25">#40FFFFFF</color>
+    <color name="white20">#33FFFFFF</color>
+    <color name="white15">#26FFFFFF</color>
+    <color name="white10">#1AFFFFFF</color>
+    <color name="white5">#0DFFFFFF</color>
+
+    <!-- 黑色 -->
+    <color name="black">#FF000000</color>
+    <color name="black95">#F2000000</color>
+    <color name="black90">#E6000000</color>
+    <color name="black85">#D9000000</color>
+    <color name="black80">#CC000000</color>
+    <color name="black75">#B000000F</color>
+    <color name="black70">#B3000000</color>
+    <color name="black65">#A6000000</color>
+    <color name="black60">#99000000</color>
+    <color name="black55">#8C000000</color>
+    <color name="black50">#80000000</color>
+    <color name="black45">#73000000</color>
+    <color name="black40">#66000000</color>
+    <color name="black35">#59000000</color>
+    <color name="black30">#4D000000</color>
+    <color name="black25">#40000000</color>
+    <color name="black20">#33000000</color>
+    <color name="black15">#26000000</color>
+    <color name="black10">#1A000000</color>
+    <color name="black5">#0D000000</color>
+
+</resources>

+ 3 - 0
lib/base/base_controller.dart

@@ -0,0 +1,3 @@
+import 'package:get/get.dart';
+
+class BaseController extends GetxController {}

+ 20 - 0
lib/base/base_page.dart

@@ -0,0 +1,20 @@
+import 'package:flutter/material.dart';
+import 'package:get/get.dart';
+
+abstract class BasePage<T extends GetxController> extends GetView<T> {
+  const BasePage({super.key});
+
+  @override
+  Widget build(BuildContext context) {
+    return Container(
+      color: backgroundColor(),
+      child: buildBody(context),
+    );
+  }
+
+  Widget? buildBody(BuildContext context);
+
+  Color backgroundColor() {
+    return const Color(0xFF1A1A1A);
+  }
+}

+ 13 - 120
lib/main.dart

@@ -1,23 +1,11 @@
-import 'package:electronic_assistant/data/api/atmob_api.dart';
-import 'package:electronic_assistant/data/api/request/verification_code_request.dart';
-import 'package:electronic_assistant/utils/app_info_util.dart';
+import 'package:electronic_assistant/router/app_pages.dart';
+import 'package:electronic_assistant/router/route_path.dart';
+import 'package:electronic_assistant/resource/string_source.dart';
 import 'package:flutter/material.dart';
+import 'package:get/get_navigation/src/root/get_material_app.dart';
 
-Future<void> main() async {
-  WidgetsFlutterBinding.ensureInitialized();
-
-  await appInfoUtil.init();
-
+void main() {
   runApp(const MyApp());
-
-  debugPrint("getVerificationCode start");
-  atmobApi
-      .getVerificationCode(VerificationCodeRequest("17674103210"))
-      .then((void value) {
-    debugPrint("getVerificationCode success");
-  }).catchError((Object error) {
-    debugPrint("getVerificationCode error: $error");
-  });
 }
 
 class MyApp extends StatelessWidget {
@@ -26,116 +14,21 @@ class MyApp extends StatelessWidget {
   // This widget is the root of your application.
   @override
   Widget build(BuildContext context) {
-    return MaterialApp(
+    return GetMaterialApp(
       title: 'Flutter Demo',
+      getPages: AppPage.pages,
       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 purple 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,
       ),
-      home: const MyHomePage(title: 'Flutter Demo Home Page'),
+      initialRoute: RoutePath.splash,
+      translations: StringResource(),
+      // 你的翻译
+      locale: const Locale('zh', 'CN'),
+      // 将会按照此处指定的语言翻译
+      fallbackLocale: const Locale('zh', 'CN'), // 添加一个回调语言选项,以备上面指定的语言翻译不存在
     );
   }
 }
 
-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<MyHomePage> createState() => _MyHomePageState();
-}
-
-class _MyHomePageState extends State<MyHomePage> {
-  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: <Widget>[
-            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.
-    );
-  }
-}

+ 12 - 0
lib/module/login/view.dart

@@ -0,0 +1,12 @@
+import 'package:electronic_assistant/base/base_page.dart';
+import 'package:flutter/material.dart';
+
+class LoginPage extends BasePage {
+  const LoginPage({super.key});
+
+  @override
+  Widget? buildBody(BuildContext context) {
+    // TODO: implement buildBody
+    throw UnimplementedError();
+  }
+}

+ 12 - 0
lib/module/main/view.dart

@@ -0,0 +1,12 @@
+import 'package:electronic_assistant/base/base_page.dart';
+import 'package:flutter/material.dart';
+
+class MainTabPage extends BasePage {
+  const MainTabPage({super.key});
+
+  @override
+  Widget? buildBody(BuildContext context) {
+    // TODO: implement buildBody
+    throw UnimplementedError();
+  }
+}

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

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

+ 13 - 0
lib/module/splash/view.dart

@@ -0,0 +1,13 @@
+import 'package:electronic_assistant/base/base_page.dart';
+import 'package:flutter/material.dart';
+
+import 'controller.dart';
+
+class SplashPage extends BasePage<SplashController> {
+  const SplashPage({super.key});
+
+  @override
+  Widget? buildBody(BuildContext context) {
+    return null;
+  }
+}

+ 12 - 0
lib/resource/assets.gen.dart

@@ -0,0 +1,12 @@
+/// GENERATED CODE - DO NOT MODIFY BY HAND
+/// *****************************************************
+///  FlutterGen
+/// *****************************************************
+
+// coverage:ignore-file
+// ignore_for_file: type=lint
+// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use
+
+class Assets {
+  Assets._();
+}

+ 138 - 0
lib/resource/colors.gen.dart

@@ -0,0 +1,138 @@
+/// GENERATED CODE - DO NOT MODIFY BY HAND
+/// *****************************************************
+///  FlutterGen
+/// *****************************************************
+
+// coverage:ignore-file
+// ignore_for_file: type=lint
+// ignore_for_file: directives_ordering,unnecessary_import,implicit_dynamic_list_literal,deprecated_member_use
+
+import 'package:flutter/painting.dart';
+import 'package:flutter/material.dart';
+
+class ColorName {
+  ColorName._();
+
+  /// Color: #FF000000
+  static const Color black = Color(0xFF000000);
+
+  /// Color: #1A000000
+  static const Color black10 = Color(0x1A000000);
+
+  /// Color: #26000000
+  static const Color black15 = Color(0x26000000);
+
+  /// Color: #33000000
+  static const Color black20 = Color(0x33000000);
+
+  /// Color: #40000000
+  static const Color black25 = Color(0x40000000);
+
+  /// Color: #4D000000
+  static const Color black30 = Color(0x4D000000);
+
+  /// Color: #59000000
+  static const Color black35 = Color(0x59000000);
+
+  /// Color: #66000000
+  static const Color black40 = Color(0x66000000);
+
+  /// Color: #73000000
+  static const Color black45 = Color(0x73000000);
+
+  /// Color: #0D000000
+  static const Color black5 = Color(0x0D000000);
+
+  /// Color: #80000000
+  static const Color black50 = Color(0x80000000);
+
+  /// Color: #8C000000
+  static const Color black55 = Color(0x8C000000);
+
+  /// Color: #99000000
+  static const Color black60 = Color(0x99000000);
+
+  /// Color: #A6000000
+  static const Color black65 = Color(0xA6000000);
+
+  /// Color: #B3000000
+  static const Color black70 = Color(0xB3000000);
+
+  /// Color: #B000000F
+  static const Color black75 = Color(0xB000000F);
+
+  /// Color: #CC000000
+  static const Color black80 = Color(0xCC000000);
+
+  /// Color: #D9000000
+  static const Color black85 = Color(0xD9000000);
+
+  /// Color: #E6000000
+  static const Color black90 = Color(0xE6000000);
+
+  /// Color: #F2000000
+  static const Color black95 = Color(0xF2000000);
+
+  /// Color: #FFFFFFFF
+  static const Color white = Color(0xFFFFFFFF);
+
+  /// Color: #1AFFFFFF
+  static const Color white10 = Color(0x1AFFFFFF);
+
+  /// Color: #26FFFFFF
+  static const Color white15 = Color(0x26FFFFFF);
+
+  /// Color: #33FFFFFF
+  static const Color white20 = Color(0x33FFFFFF);
+
+  /// Color: #40FFFFFF
+  static const Color white25 = Color(0x40FFFFFF);
+
+  /// Color: #4DFFFFFF
+  static const Color white30 = Color(0x4DFFFFFF);
+
+  /// Color: #59FFFFFF
+  static const Color white35 = Color(0x59FFFFFF);
+
+  /// Color: #66FFFFFF
+  static const Color white40 = Color(0x66FFFFFF);
+
+  /// Color: #73FFFFFF
+  static const Color white45 = Color(0x73FFFFFF);
+
+  /// Color: #0DFFFFFF
+  static const Color white5 = Color(0x0DFFFFFF);
+
+  /// Color: #80FFFFFF
+  static const Color white50 = Color(0x80FFFFFF);
+
+  /// Color: #8CFFFFFF
+  static const Color white55 = Color(0x8CFFFFFF);
+
+  /// Color: #99FFFFFF
+  static const Color white60 = Color(0x99FFFFFF);
+
+  /// Color: #A6FFFFFF
+  static const Color white65 = Color(0xA6FFFFFF);
+
+  /// Color: #B3FFFFFF
+  static const Color white70 = Color(0xB3FFFFFF);
+
+  /// Color: #BFFFFFFF
+  static const Color white75 = Color(0xBFFFFFFF);
+
+  /// Color: #CCFFFFFF
+  static const Color white80 = Color(0xCCFFFFFF);
+
+  /// Color: #D9FFFFFF
+  static const Color white85 = Color(0xD9FFFFFF);
+
+  /// Color: #DEFFFFFF
+  static const Color white87 = Color(0xDEFFFFFF);
+
+  /// Color: #E6FFFFFF
+  static const Color white90 = Color(0xE6FFFFFF);
+
+  /// Color: #F2FFFFFF
+  static const Color white95 = Color(0xF2FFFFFF);
+}

+ 10 - 0
lib/resource/string_source.dart

@@ -0,0 +1,10 @@
+import 'package:get/get.dart';
+
+class StringResource extends Translations {
+  @override
+  Map<String, Map<String, String>> get keys => {
+        'zh_CN': {
+          'app_name': '电子秘书',
+        },
+      };
+}

+ 18 - 0
lib/router/app_pages.dart

@@ -0,0 +1,18 @@
+import 'package:electronic_assistant/router/route_path.dart';
+import 'package:get/get_navigation/src/routes/get_route.dart';
+
+import '../module/login/view.dart';
+import '../module/main/view.dart';
+import '../module/splash/view.dart';
+
+abstract class AppPage {
+  static final pages = <GetPage>[
+    ...generalPages,
+  ];
+}
+
+final generalPages = [
+  GetPage(name: RoutePath.splash, page: () => SplashPage()),
+  GetPage(name: RoutePath.login, page: () => LoginPage()),
+  GetPage(name: RoutePath.mainTab, page: () => MainTabPage()),
+];

+ 7 - 0
lib/router/route_path.dart

@@ -0,0 +1,7 @@
+abstract class RoutePath {
+  static const splash = '/';
+
+  static const login = '/login';
+
+  static const mainTab = '/mainTab';
+}

+ 12 - 9
pubspec.yaml

@@ -31,9 +31,6 @@ dependencies:
   flutter:
     sdk: flutter
 
-
-  # The following adds the Cupertino Icons font to your application.
-  # Use with the CupertinoIcons class for iOS style icons.
   cupertino_icons: ^1.0.6
 
   # 状态管理
@@ -62,9 +59,17 @@ dev_dependencies:
   retrofit_generator: '>=7.0.0 <8.0.0'
   build_runner: '>=2.3.0 <4.0.0'
   json_serializable: ^6.6.2
+  flutter_gen_runner:
+
+
+#----------gen配置---------------
+flutter_gen:
+  output: lib/resource/
+  colors:
+    inputs:
+      - assets/color/common_color.xml
+      - assets/color/color.xml
 
-# For information on the generic Dart part of this file, see the
-# following page: https://dart.dev/tools/pub/pubspec
 
 # The following section is specific to Flutter packages.
 flutter:
@@ -74,10 +79,8 @@ flutter:
   # the material Icons class.
   uses-material-design: true
 
-  # To add assets to your application, add an assets section, like this:
-  # assets:
-  #   - images/a_dot_burr.jpeg
-  #   - images/a_dot_ham.jpeg
+  assets:
+    - assets/images/
 
   # An image asset can refer to one or more resolution-specific "variants", see
   # https://flutter.dev/assets-and-images/#resolution-aware