diff --git a/analysis_options.yaml b/analysis_options.yaml index 61b6c4d..9172093 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -22,6 +22,27 @@ linter: # `// ignore_for_file: name_of_lint` syntax on the line or in the file # producing the lint. rules: + library_private_types_in_public_api: false + always_use_package_import: true + use_super_parameters: true + use_decorated_box: true + use_colored_box: true + use_full_hex_values_for_flutter_colors: true + use_if_null_to_convert_nulls_to_bools: true + unnecessary_this: true + avoid_type_to_string: true + cancel_subscriptions: true + literal_only_boolean_expressions: true + unnecessary_statements: true + file_names: true + missing_whitespace_between_adjacent_strings: true + no_runtimeType_toString: true + prefer_null_aware_method_calls: true + avoid_positional_boolean_parameters: true + avoid_bool_literals_in_conditional_expressions: true + prefer_function_declarations_over_variables: true + prefer_interpolation_to_compose_strings: true + prefer_null_aware_operators: true # avoid_print: false # Uncomment to disable the `avoid_print` rule # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule diff --git a/lib/constants/api/app_theme.dart b/lib/constants/api/app_theme.dart deleted file mode 100644 index 616e69f..0000000 --- a/lib/constants/api/app_theme.dart +++ /dev/null @@ -1,193 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_screenutil/flutter_screenutil.dart'; - -class AppTheme { - static ThemeData get theme { - return ThemeData(primarySwatch: Colors.blue).copyWith( - primaryColor: const Color(0xFF027AFF), - extensions: >[ - MyAppStyle( - mainColor: Colors.blue, - bodyText3: TextStyle( - fontSize: 30.sp, - color: const Color(0xFF333333), - ), - ) - ], - textTheme: ThemeData.light().textTheme.copyWith( - headline3: TextStyle( - fontSize: 40.sp, - color: const Color(0xFF333333), - fontWeight: FontWeight.bold, - ), - headline4: TextStyle( - fontSize: 36.sp, - color: const Color(0xFF111111), - fontWeight: FontWeight.bold, - ), - subtitle1: TextStyle( - fontSize: 32.sp, - color: const Color(0xFF333333), - ), - subtitle2: TextStyle( - fontSize: 28.sp, - color: const Color(0xFF333333), - ), - bodyText1: TextStyle( - fontSize: 24.sp, - color: const Color(0xFF333333), - ), - bodyText2: TextStyle( - fontSize: 28.sp, - color: const Color(0xFF333333), - ), - ), - floatingActionButtonTheme: const FloatingActionButtonThemeData().copyWith( - backgroundColor: const Color(0xFFFFD000), - ), - appBarTheme: AppBarTheme( - elevation: 0, - centerTitle: true, - iconTheme: const IconThemeData( - color: Color(0xFF333333), - ), - systemOverlayStyle: SystemUiOverlayStyle.dark, - toolbarTextStyle: TextTheme( - headline6: TextStyle( - color: const Color(0xFF333333), - fontSize: 36.sp, - fontWeight: FontWeight.bold, - ), - ).bodyText2, - titleTextStyle: TextTheme( - headline6: TextStyle( - color: const Color(0xFF333333), - fontSize: 36.sp, - fontWeight: FontWeight.bold, - ), - ).headline6, - ), - tabBarTheme: TabBarTheme( - labelColor: const Color(0xFF333333), - labelStyle: TextStyle( - fontSize: 28.sp, - fontWeight: FontWeight.w600, - ), - unselectedLabelStyle: TextStyle( - fontSize: 28.sp, - ), - indicatorSize: TabBarIndicatorSize.label, - ), - bottomNavigationBarTheme: const BottomNavigationBarThemeData( - selectedItemColor: Color(0xFF333333), - selectedLabelStyle: TextStyle( - fontWeight: FontWeight.bold, - ), - type: BottomNavigationBarType.fixed, - unselectedLabelStyle: TextStyle(), - ), - radioTheme: RadioThemeData( - fillColor: MaterialStateProperty.resolveWith((states) { - if (states.contains(MaterialState.selected)) { - return const Color(0xFFFFD000); - } - return null; - }), - ), - elevatedButtonTheme: ElevatedButtonThemeData( - style: ButtonStyle( - backgroundColor: MaterialStateProperty.resolveWith((states) { - if (states.contains(MaterialState.disabled)) { - return const Color(0xFFFFF4D7); - } - return const Color(0xFFFFD000); - }), - elevation: MaterialStateProperty.all(0), - foregroundColor: MaterialStateProperty.resolveWith((states) { - if (states.contains(MaterialState.disabled)) { - return const Color(0xFF666666); - } - return const Color(0xFF333333); - }), - textStyle: MaterialStateProperty.all(TextStyle( - fontSize: 32.sp, - fontWeight: FontWeight.bold, - )), - padding: MaterialStateProperty.all( - EdgeInsets.symmetric(horizontal: 76.w, vertical: 22.w), - ), - enableFeedback: true, - ), - ), - textButtonTheme: TextButtonThemeData( - style: ButtonStyle( - overlayColor: MaterialStateProperty.resolveWith((states) { - if (states.contains(MaterialState.disabled)) { - return const Color(0xFFFFF4D7); - } - return const Color(0xFFFFD000).withOpacity(0.2); - }), - foregroundColor: MaterialStateProperty.resolveWith((states) { - if (states.contains(MaterialState.disabled)) { - return const Color(0xFF666666); - } - return const Color(0xFF333333); - }), - ), - ), - materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, - dividerColor: const Color(0xFFE8E8E8), - colorScheme: ColorScheme.fromSwatch() - .copyWith(secondary: const Color(0xFF027AFF)) - .copyWith(secondary: const Color(0xFF027AFF)), - ); - } -} - -class SystemStyle { - static const initial = SystemUiOverlayStyle( - statusBarIconBrightness: Brightness.light, - systemNavigationBarColor: Colors.white, - ); - - static const yellowBottomBar = SystemUiOverlayStyle( - statusBarIconBrightness: Brightness.light, - systemNavigationBarColor: Color(0xFFFFD000), - ); - - static genStyle({required Color bottom}) { - return SystemUiOverlayStyle( - statusBarIconBrightness: Brightness.light, - systemNavigationBarColor: bottom, - ); - } -} - -@immutable -class MyAppStyle extends ThemeExtension { - final TextStyle? bodyText3; - final Color? mainColor; - @override - MyAppStyle copyWith({Color? mainColor, TextStyle? bodyText3}) { - return MyAppStyle( - mainColor: mainColor ?? this.mainColor, - bodyText3: bodyText3 ?? this.bodyText3); - } - - @override - ThemeExtension lerp(ThemeExtension? other, double t) { - if (other is! MyAppStyle) { - return this; - } - return MyAppStyle( - mainColor: Color.lerp(mainColor, other.mainColor, t), - bodyText3: TextStyle.lerp(bodyText3, other.bodyText3, t), - ); - } - - const MyAppStyle({ - this.bodyText3, - this.mainColor, - }); -} diff --git a/lib/constants/app_ theme.dart b/lib/constants/app_theme.dart similarity index 70% rename from lib/constants/app_ theme.dart rename to lib/constants/app_theme.dart index 1245f52..f08b073 100644 --- a/lib/constants/app_ theme.dart +++ b/lib/constants/app_theme.dart @@ -3,46 +3,38 @@ import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; class AppTheme { - static ThemeData get theme { + static ThemeData get defaultTheme { return ThemeData(primarySwatch: Colors.blue).copyWith( primaryColor: const Color(0xFF027AFF), - extensions: >[ - MyAppStyle( - mainColor: Colors.blue, - bodyText3: TextStyle( - fontSize: 30.sp, - color: const Color(0xFF333333), - ), - ) - ], + extensions: >[MyAppStyle.def()], textTheme: ThemeData.light().textTheme.copyWith( - headline3: TextStyle( - fontSize: 40.sp, - color: const Color(0xFF333333), - fontWeight: FontWeight.bold, - ), - headline4: TextStyle( - fontSize: 36.sp, - color: const Color(0xFF111111), - fontWeight: FontWeight.bold, - ), - subtitle1: TextStyle( - fontSize: 32.sp, - color: const Color(0xFF333333), - ), - subtitle2: TextStyle( - fontSize: 28.sp, - color: const Color(0xFF333333), - ), - bodyText1: TextStyle( - fontSize: 24.sp, - color: const Color(0xFF333333), - ), - bodyText2: TextStyle( - fontSize: 28.sp, - color: const Color(0xFF333333), - ), - ), + headline3: TextStyle( + fontSize: 40.sp, + color: const Color(0xFF333333), + fontWeight: FontWeight.bold, + ), + headline4: TextStyle( + fontSize: 36.sp, + color: const Color(0xFF111111), + fontWeight: FontWeight.bold, + ), + subtitle1: TextStyle( + fontSize: 32.sp, + color: const Color(0xFF333333), + ), + subtitle2: TextStyle( + fontSize: 28.sp, + color: const Color(0xFF333333), + ), + bodyText1: TextStyle( + fontSize: 24.sp, + color: const Color(0xFF333333), + ), + bodyText2: TextStyle( + fontSize: 28.sp, + color: const Color(0xFF333333), + ), + ), floatingActionButtonTheme: const FloatingActionButtonThemeData().copyWith( backgroundColor: Colors.blue, ), @@ -166,13 +158,22 @@ class SystemStyle { @immutable class MyAppStyle extends ThemeExtension { - final TextStyle? bodyText3; final Color? mainColor; + + ///底部按钮风格 + final BoxDecoration? bottomButtonDecoration; + final TextStyle? bottomButtonText; + @override - MyAppStyle copyWith({Color? mainColor, TextStyle? bodyText3}) { + MyAppStyle copyWith( + {Color? mainColor, + TextStyle? bottomButtonText, + BoxDecoration? bottomButtonDecoration}) { return MyAppStyle( mainColor: mainColor ?? this.mainColor, - bodyText3: bodyText3 ?? this.bodyText3); + bottomButtonDecoration: + bottomButtonDecoration ?? this.bottomButtonDecoration, + bottomButtonText: bottomButtonText ?? this.bottomButtonText); } @override @@ -182,12 +183,30 @@ class MyAppStyle extends ThemeExtension { } return MyAppStyle( mainColor: Color.lerp(mainColor, other.mainColor, t), - bodyText3: TextStyle.lerp(bodyText3, other.bodyText3, t), + bottomButtonDecoration: BoxDecoration.lerp( + bottomButtonDecoration, other.bottomButtonDecoration, t), + bottomButtonText: + TextStyle.lerp(bottomButtonText, other.bottomButtonText, t), ); } const MyAppStyle({ - this.bodyText3, + this.bottomButtonText, this.mainColor, + this.bottomButtonDecoration, }); + + MyAppStyle.def() + : mainColor = Colors.blue, + bottomButtonDecoration = + BoxDecoration( + gradient: const LinearGradient( + begin: Alignment.centerLeft, + end: Alignment.centerRight, + colors: [Color(0xFF0593FF), Color(0xFF027AFF)]), + borderRadius: BorderRadius.circular(8.w)), + bottomButtonText = TextStyle( + fontSize: 30.sp, + color: const Color(0xFF333333), + ); } diff --git a/lib/main.dart b/lib/main.dart index c443b60..427fe9e 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,7 @@ import 'package:bot_toast/bot_toast.dart'; +import 'package:cloud_car_internal/constants/app_theme.dart'; import 'package:cloud_car_internal/providers/user_provider.dart'; +import 'package:cloud_car_internal/ui/splash/splash.dart'; import 'package:cloud_car_internal/utils/api_client.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -11,35 +13,34 @@ import 'package:flutter_ume_kit_perf/flutter_ume_kit_perf.dart'; // 性能插件 import 'package:flutter_ume_kit_show_code/flutter_ume_kit_show_code.dart'; // 代码查看插件包 import 'package:flutter_ume_kit_device/flutter_ume_kit_device.dart'; // 设备信息插件包 import 'package:flutter_ume_kit_console/flutter_ume_kit_console.dart'; // debugPrint 插件包 -import 'package:flutter_ume_kit_dio/flutter_ume_kit_dio.dart'; +import 'package:flutter_ume_kit_dio/flutter_ume_kit_dio.dart'; // Dio 网络请求调试工具 import 'package:get/get_navigation/src/root/get_material_app.dart'; import 'package:provider/provider.dart'; -import 'constants/api/app_theme.dart'; // Dio 网络请求调试工具 void main() { if (kDebugMode) { PluginManager.instance // 注册插件 - ..register(WidgetInfoInspector()) - ..register(WidgetDetailInspector()) - ..register(ColorSucker()) + ..register(const WidgetInfoInspector()) + ..register(const WidgetDetailInspector()) + ..register(const ColorSucker()) ..register(AlignRuler()) - ..register(ColorPicker()) // 新插件 - ..register(TouchIndicator()) // 新插件 + ..register(const ColorPicker()) // 新插件 + ..register(const TouchIndicator()) // 新插件 ..register(Performance()) - ..register(ShowCode()) - ..register(MemoryInfoPage()) + ..register(const ShowCode()) + ..register(const MemoryInfoPage()) ..register(CpuInfoPage()) - ..register(DeviceInfoPanel()) + ..register(const DeviceInfoPanel()) ..register(Console()) ..register(DioInspector(dio: apiClient.dio)); - runApp(UMEWidget(child: MyApp(), enable: true)); // 初始 + runApp(const UMEWidget(enable: true, child: MyApp())); // 初始 } else { - runApp(MyApp()); + runApp(const MyApp()); } } class MyApp extends StatelessWidget { - const MyApp({Key? key}) : super(key: key); + const MyApp({super.key}); // This widget is the root of your application. @override @@ -63,8 +64,8 @@ class MyApp extends StatelessWidget { child: GetMaterialApp( onGenerateTitle: (context) => '云云问车', debugShowCheckedModeBanner: false, - theme: AppTheme.theme, - home: MyHomePage(title: ''), + theme: AppTheme.defaultTheme, + home: const SplashPage(), supportedLocales: const [Locale('zh')], locale: const Locale('zh'), localizationsDelegates: GlobalMaterialLocalizations.delegates, @@ -84,88 +85,3 @@ class MyApp extends StatelessWidget { ); } } - -class MyHomePage extends StatefulWidget { - const MyHomePage({Key? key, required this.title}) : super(key: key); - - // 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( - // 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. - // - // Invoke "debug painting" (press "p" in the console, choose the - // "Toggle Debug Paint" action from the Flutter Inspector in Android - // Studio, or the "Toggle Debug Paint" command in Visual Studio Code) - // to see the wireframe for each widget. - // - // 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). - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text( - 'You have pushed the button this many times:', - ), - Text( - '$_counter', - style: Theme.of(context).textTheme.headline4, - ), - ], - ), - ), - floatingActionButton: FloatingActionButton( - onPressed: _incrementCounter, - tooltip: 'Increment', - child: const Icon(Icons.add), - ), // This trailing comma makes auto-formatting nicer for build methods. - ); - } -} diff --git a/lib/models/inner_models/base_list_model.dart b/lib/models/inner_models/base_list_model.dart index c620832..e993d83 100644 --- a/lib/models/inner_models/base_list_model.dart +++ b/lib/models/inner_models/base_list_model.dart @@ -17,6 +17,8 @@ class BaseListModel { factory BaseListModel.fromJson(Map json) => _$BaseListModelFromJson(json); + Map toJson() => _$BaseListModelToJson(this); + List get nullSafetyList { if (data == null) { return []; @@ -48,4 +50,6 @@ class ListInnerModel { factory ListInnerModel.fromJson(Map json) => _$ListInnerModelFromJson(json); + + Map toJson() => _$ListInnerModelToJson(this); } diff --git a/lib/models/inner_models/base_model.dart b/lib/models/inner_models/base_model.dart index 68cc933..9a6a82c 100644 --- a/lib/models/inner_models/base_model.dart +++ b/lib/models/inner_models/base_model.dart @@ -31,6 +31,8 @@ class BaseModel { msg: err.message, ); + Map toJson() => _$BaseModelToJson(this); + factory BaseModel.fromJson(Map json) => _$BaseModelFromJson(json) as BaseModel; } diff --git a/lib/providers/user_provider.dart b/lib/providers/user_provider.dart index 514e5e8..4d7939b 100644 --- a/lib/providers/user_provider.dart +++ b/lib/providers/user_provider.dart @@ -3,10 +3,6 @@ import 'package:cloud_car_internal/utils/api_client.dart'; import 'package:cloud_car_internal/utils/hive_util.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:hive/hive.dart'; - -import '../constants/api/api.dart'; -import '../utils/toast/cloud_toast.dart'; class UserProvider extends ChangeNotifier { bool _isLogin = false; @@ -30,8 +26,10 @@ class UserProvider extends ChangeNotifier { } } - Future setToken(String token, ) async { -var appBox = await HiveUtil().openAppBox; + Future setToken( + String token, + ) async { + var appBox = await HiveUtil().openAppBox; apiClient.setToken(token); await appBox.put('token', token); _isLogin = true; diff --git a/lib/ui/login/login_page.dart b/lib/ui/login/login_page.dart new file mode 100644 index 0000000..2f7a6fb --- /dev/null +++ b/lib/ui/login/login_page.dart @@ -0,0 +1,15 @@ +import 'package:flutter/material.dart'; + +class LoginPage extends StatefulWidget { + const LoginPage({super.key}); + + @override + _LoginPageState createState() => _LoginPageState(); +} + +class _LoginPageState extends State { + @override + Widget build(BuildContext context) { + return Container(); + } +} diff --git a/lib/ui/splash/splash.dart b/lib/ui/splash/splash.dart new file mode 100644 index 0000000..bdf8355 --- /dev/null +++ b/lib/ui/splash/splash.dart @@ -0,0 +1,117 @@ +import 'package:cloud_car_internal/ui/login/login_page.dart'; +import 'package:cloud_car_internal/ui/tab_navigator.dart'; +import 'package:cloud_car_internal/utils/hive_util.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:provider/provider.dart'; + +import '../../constants/environment/environment.dart'; +import '../../providers/user_provider.dart'; + +class SplashPage extends StatefulWidget { + const SplashPage({super.key}); + + @override + _SplashPageState createState() => _SplashPageState(); +} + +class _SplashPageState extends State { + final TapGestureRecognizer _agreementRecognizer = TapGestureRecognizer(); + final TapGestureRecognizer _privacyRecognizer = TapGestureRecognizer(); + + Future initialAll() async { + ///第三方加载 + await HiveUtil.init(); + // var agreement = await HiveStore.appBox?.get('agreement') ?? false; + // if (!agreement) { + // var result = await _showLoginVerify(); + // if (result == null || !result) { + // await SystemNavigator.pop(); + // await HiveStore.appBox?.put('agreement', false); + // } else { + // await HiveStore.appBox?.put('agreement', true); + // } + // } + ///Providers 初始化 + } + + Future _showLoginVerify() async { + return await showCupertinoDialog( + barrierDismissible: false, + context: context, + builder: (context) { + return CupertinoAlertDialog( + title: const Text('隐私政策和用户协议'), + content: RichText( + text: TextSpan( + text: '点击登录即表示您已阅读并同意', + style: const TextStyle(color: Colors.black), + children: [ + TextSpan( + text: '《用户协议》', + style: const TextStyle(color: Colors.blue), + recognizer: _agreementRecognizer + ..onTap = () { + // Get.to(() => AgreementPage()); + }), + TextSpan( + text: '《隐私政策》', + style: const TextStyle(color: Colors.blue), + recognizer: _privacyRecognizer + ..onTap = () { + // Get.to(() => PrivacyPage()); + }), + const TextSpan( + style: TextStyle(color: Colors.black), + text: + '(特别是免除或限制责任、管辖等粗体下划线标注的条款)。如您不同意上述协议的任何条款,您应立即停止登录及使用本软件及服务。') + ]), + ), + + // ), + actions: [ + CupertinoDialogAction( + onPressed: () => Get.back(result: true), + child: const Text('同意'), + ), + CupertinoDialogAction( + onPressed: () => Get.back(result: false), + child: const Text('拒绝'), + ), + ], + ); + }, + ); + } + + @override + void initState() { + super.initState(); + final userProvider = Provider.of(context, listen: false); + var env = const String.fromEnvironment('ENV', defaultValue: 'dev'); + if (kDebugMode) { + print('env :$env'); + } + DevEV.instance.setEnvironment( context, environment: env == 'dev',); + Future.delayed(const Duration(milliseconds: 1000), () async { + await initialAll(); + if (!await userProvider.init()) { + await Get.offAll(() => const LoginPage()); + } else { + await Get.offAll(() => const TabNavigator()); + } + }); + } + + @override + Widget build(BuildContext context) { + return const Scaffold( + body: Center( + child: CircularProgressIndicator(), + ), + ); + } +} diff --git a/lib/ui/tab_navigator.dart b/lib/ui/tab_navigator.dart new file mode 100644 index 0000000..d071ba3 --- /dev/null +++ b/lib/ui/tab_navigator.dart @@ -0,0 +1,15 @@ +import 'package:flutter/material.dart'; + +class TabNavigator extends StatefulWidget { + const TabNavigator({super.key}); + + @override + _TabNavigatorState createState() => _TabNavigatorState(); +} + +class _TabNavigatorState extends State { + @override + Widget build(BuildContext context) { + return Container(); + } +} diff --git a/lib/utils/hive_util.dart b/lib/utils/hive_util.dart index 96be4ad..b95b152 100644 --- a/lib/utils/hive_util.dart +++ b/lib/utils/hive_util.dart @@ -3,7 +3,7 @@ import 'package:hive/hive.dart'; import 'package:path_provider/path_provider.dart'; class HiveUtil { - static late final HiveUtil _instance = HiveUtil._(); + static final HiveUtil _instance = HiveUtil._(); factory HiveUtil() => _instance; diff --git a/lib/utils/user_tool.dart b/lib/utils/user_tool.dart index 782d675..dccecb7 100644 --- a/lib/utils/user_tool.dart +++ b/lib/utils/user_tool.dart @@ -1,9 +1,9 @@ -import 'package:cloud_car_internal/constants/api/app_theme.dart'; +import 'package:cloud_car_internal/constants/app_theme.dart'; +import 'package:cloud_car_internal/providers/user_provider.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:provider/provider.dart'; -import '../providers/user_provider.dart'; class UserTool { static UserProvider userProvider = diff --git a/lib/widget/buttons/cloud_back_button.dart b/lib/widget/buttons/cloud_back_button.dart new file mode 100644 index 0000000..bc83f87 --- /dev/null +++ b/lib/widget/buttons/cloud_back_button.dart @@ -0,0 +1,32 @@ + +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; + +class CloudBackButton extends StatelessWidget { + final Color color; + final bool isSpecial; + + const CloudBackButton({ + super.key, + this.color = const Color(0xFF111111), + this.isSpecial = false, + }); + + @override + Widget build(BuildContext context) { + return Navigator.canPop(context) + ? Padding( + padding: isSpecial ? EdgeInsets.only(left: 8.w) : EdgeInsets.zero, + child: IconButton( + onPressed: () => Get.back(), + icon: Icon( + CupertinoIcons.chevron_back, + color: color, + ), + ), + ) + : const SizedBox(); + } +} diff --git a/lib/widget/buttons/cloud_bottom_button.dart b/lib/widget/buttons/cloud_bottom_button.dart new file mode 100644 index 0000000..f2f2e38 --- /dev/null +++ b/lib/widget/buttons/cloud_bottom_button.dart @@ -0,0 +1,39 @@ +import 'package:cloud_car_internal/utils/user_tool.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +class CloudBottomButton extends StatefulWidget { + final String text; + final BoxDecoration? decoration; + final Function() onTap; + const CloudBottomButton({ + super.key, + this.text = '返回首页', + required this.onTap, this.decoration, + }); + + @override + State createState() => _CloudBottomButtonState(); +} + +class _CloudBottomButtonState extends State { + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap:widget.onTap, + child: Material( + color:Colors.transparent, + child: Container( + alignment: Alignment.center, + padding: EdgeInsets.symmetric(vertical: 15.w), + margin: EdgeInsets.symmetric(horizontal: 32.w), + decoration:widget.decoration?? UserTool.myAppStyle.bottomButtonDecoration!, + child: Text( + widget.text, + style: UserTool.myAppStyle.bottomButtonText, + ), + ), + ), + ); + } +} diff --git a/lib/widget/scaffold/cloud_scaffold.dart b/lib/widget/scaffold/cloud_scaffold.dart new file mode 100644 index 0000000..9479d03 --- /dev/null +++ b/lib/widget/scaffold/cloud_scaffold.dart @@ -0,0 +1,75 @@ + +import 'package:cloud_car_internal/constants/app_theme.dart'; +import 'package:cloud_car_internal/widget/buttons/cloud_back_button.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +class CloudScaffold extends StatelessWidget { + final Widget? body; + final Widget? appbar; + final Color bodyColor; + final Widget? bottomNavi; + final FloatingActionButton? fab; + final bool extendBody; + final String? path; + final SystemUiOverlayStyle systemStyle; + final String? title; + final List actions; + final Color? appBarBackColor; + final PreferredSizeWidget? appBarBottom; + final Widget? endDrawer; + + const CloudScaffold( + {super.key, + this.body, + this.appbar, + this.bodyColor = const Color(0xFFF9F9F9), + this.bottomNavi, + this.fab, + this.systemStyle = SystemStyle.initial, + this.extendBody = false, + this.path, + this.title, + this.appBarBackColor = Colors.white, + this.appBarBottom, + this.actions = const [], + this.endDrawer}) + : assert(title != null || appbar != null); + + @override + Widget build(BuildContext context) { + SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light); + return AnnotatedRegion( + value: systemStyle, + child: Scaffold( + endDrawer: endDrawer, + backgroundColor: bodyColor, + extendBodyBehindAppBar: extendBody, + extendBody: extendBody, + body: body, + appBar: PreferredSize( + preferredSize: Size.fromHeight(176.w), + child: title == null + ? appbar! + : AppBar( + bottom: appBarBottom, + backgroundColor: + extendBody ? Colors.transparent : appBarBackColor, + leading: const CloudBackButton(), + title: Text( + title!, + style: TextStyle( + color: Colors.black, + fontWeight: FontWeight.bold, + fontSize: 32.sp), + ), + actions: actions, + ), + ), + bottomNavigationBar: bottomNavi, + floatingActionButton: fab, + ), + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index d39009a..8352fdb 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -360,49 +360,49 @@ packages: source: sdk version: "0.0.0" flutter_ume: - dependency: "direct dev" + dependency: "direct main" description: name: flutter_ume url: "https://pub.dartlang.org" source: hosted version: "0.3.0+1" flutter_ume_kit_console: - dependency: "direct dev" + dependency: "direct main" description: name: flutter_ume_kit_console url: "https://pub.dartlang.org" source: hosted version: "0.3.0" flutter_ume_kit_device: - dependency: "direct dev" + dependency: "direct main" description: name: flutter_ume_kit_device url: "https://pub.dartlang.org" source: hosted version: "0.3.0" flutter_ume_kit_dio: - dependency: "direct dev" + dependency: "direct main" description: name: flutter_ume_kit_dio url: "https://pub.dartlang.org" source: hosted version: "0.3.0" flutter_ume_kit_perf: - dependency: "direct dev" + dependency: "direct main" description: name: flutter_ume_kit_perf url: "https://pub.dartlang.org" source: hosted version: "0.3.0" flutter_ume_kit_show_code: - dependency: "direct dev" + dependency: "direct main" description: name: flutter_ume_kit_show_code url: "https://pub.dartlang.org" source: hosted version: "0.3.0" flutter_ume_kit_ui: - dependency: "direct dev" + dependency: "direct main" description: path: "kits/flutter_ume_kit_ui" ref: HEAD diff --git a/pubspec.yaml b/pubspec.yaml index cfa5749..3d83238 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,12 +47,6 @@ dependencies: equatable: ^2.0.3 #工具类 common_utils: ^2.1.0 - - cupertino_icons: ^1.0.2 - -dev_dependencies: - flutter_test: - sdk: flutter #应用内调试工具 flutter_ume: ^0.3.0+1 flutter_ume_kit_ui: @@ -64,6 +58,12 @@ dev_dependencies: flutter_ume_kit_show_code: ^0.3.0 flutter_ume_kit_console: ^0.3.0 flutter_ume_kit_dio: ^0.3.0 + + cupertino_icons: ^1.0.2 + +dev_dependencies: + flutter_test: + sdk: flutter #导入包整理 import_sorter: ^4.5.1 hive_generator: ^1.1.0