From dddb1fb09d64027c5c703c89ff2b3d7c71697b60 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 19 Apr 2021 09:49:50 +0800 Subject: [PATCH] update scaffold --- example/lib/main.dart | 5 ++-- example/pubspec.lock | 10 +++---- lib/ansu_ui.dart | 2 ++ lib/pickers/as_picker_box.dart | 17 ++++-------- lib/scaffold/as_scaffold.dart | 40 ++++++++++++--------------- lib/theme/as_theme.dart | 50 ++++++++++++++++++++++++++++++++++ pubspec.lock | 10 +++---- pubspec.yaml | 5 +--- 8 files changed, 86 insertions(+), 53 deletions(-) create mode 100644 lib/theme/as_theme.dart diff --git a/example/lib/main.dart b/example/lib/main.dart index b911899..123db8d 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -22,6 +22,7 @@ class MyApp extends StatelessWidget { title: 'Flutter Demo', home: MyHomePage(), builder: BotToastInit(), + theme: ASTheme.lightTheme, navigatorObservers: [BotToastNavigatorObserver()], localizationsDelegates: [ GlobalMaterialLocalizations.delegate, @@ -49,9 +50,7 @@ class _MyHomePageState extends State with TickerProviderStateMixin { @override void initState() { super.initState(); - SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith( - statusBarColor: Colors.transparent, - )); + ASTheme.init(); _tabController = TabController(length: 3, vsync: this); } diff --git a/example/pubspec.lock b/example/pubspec.lock index 3097693..5983b84 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -116,12 +116,10 @@ packages: flutter_easyrefresh: dependency: transitive description: - path: "." - ref: v2 - resolved-ref: "73f03412c46b4662db6fb92fa18902d82c52e6b6" - url: "https://github.com/xuelongqy/flutter_easyrefresh" - source: git - version: "2.2.0" + name: flutter_easyrefresh + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.1" flutter_localizations: dependency: "direct main" description: flutter diff --git a/lib/ansu_ui.dart b/lib/ansu_ui.dart index 7d76823..eaf9d47 100644 --- a/lib/ansu_ui.dart +++ b/lib/ansu_ui.dart @@ -71,3 +71,5 @@ export 'extension/string_extension.dart'; export 'extension/text_style_extension.dart'; export 'extension/image_extension.dart'; export 'package:velocity_x/velocity_x.dart'; + +export 'theme/as_theme.dart'; diff --git a/lib/pickers/as_picker_box.dart b/lib/pickers/as_picker_box.dart index 8566491..53c4c8a 100644 --- a/lib/pickers/as_picker_box.dart +++ b/lib/pickers/as_picker_box.dart @@ -21,19 +21,12 @@ class ASPickerBox extends StatelessWidget { required String title, required VoidCallback? onPressed, }) { - return TextButton( - style: ButtonStyle( - foregroundColor: MaterialStateProperty.all(kPrimaryColor), - overlayColor: MaterialStateProperty.all(kPrimaryColor.withOpacity(0.2)), - padding: - MaterialStateProperty.all(EdgeInsets.symmetric(horizontal: 20.w)), - textStyle: MaterialStateProperty.all(TextStyle( - fontSize: 16.sp, - fontWeight: FontWeight.w500, - )), + return SizedBox( + height: 48.w, + child: TextButton( + onPressed: onPressed, + child: Text(title), ), - onPressed: onPressed, - child: Text(title), ); } diff --git a/lib/scaffold/as_scaffold.dart b/lib/scaffold/as_scaffold.dart index ba6019f..59b4231 100644 --- a/lib/scaffold/as_scaffold.dart +++ b/lib/scaffold/as_scaffold.dart @@ -1,7 +1,8 @@ +import 'package:ansu_ui/theme/as_theme.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:ansu_ui/styles/as_colors.dart'; import 'package:ansu_ui/buttons/as_back_button.dart'; +import 'package:flutter/services.dart'; ///ASScaffold /// @@ -41,6 +42,8 @@ class ASScaffold extends StatelessWidget { /// `AppBar` appBar final Widget? appBar; + final SystemUiOverlayStyle? systemStyle; + ///背景色 final Color backgroundColor; final Widget? floatingActionButton; @@ -56,31 +59,21 @@ class ASScaffold extends StatelessWidget { this.backgroundColor = kBackgroundColor, this.actions, this.floatingActionButton, + this.systemStyle, }) : super(key: key); Widget get _title { if (title is String) return Text(title); - return title ?? SizedBox(); + return title; } Widget? get _appBar { if (title == null && appBar == null && appBarBottom == null) return null; return appBar ?? AppBar( - brightness: Brightness.light, - backgroundColor: kForegroundColor, - elevation: 0, leading: leading ?? ASBackButton(), actions: actions ?? [], - centerTitle: true, - title: DefaultTextStyle( - style: TextStyle( - color: kTextColor, - fontSize: 18.sp, - fontWeight: FontWeight.bold, - ), - child: _title, - ), + title: _title, bottom: appBarBottom ?? PreferredSize( child: SizedBox(), @@ -91,14 +84,17 @@ class ASScaffold extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - key: key, - endDrawer: endDrawer, - backgroundColor: backgroundColor, - bottomNavigationBar: bottomNavigationBar, - floatingActionButton: floatingActionButton, - appBar: _appBar as PreferredSizeWidget?, - body: body, + return AnnotatedRegion( + value: systemStyle ?? ASTheme.defaultSystemStyle, + child: Scaffold( + key: key, + endDrawer: endDrawer, + backgroundColor: backgroundColor, + bottomNavigationBar: bottomNavigationBar, + floatingActionButton: floatingActionButton, + appBar: _appBar as PreferredSizeWidget?, + body: body, + ), ); } } diff --git a/lib/theme/as_theme.dart b/lib/theme/as_theme.dart new file mode 100644 index 0000000..435c9da --- /dev/null +++ b/lib/theme/as_theme.dart @@ -0,0 +1,50 @@ +import 'package:ansu_ui/styles/as_colors.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +class ASTheme { + static init() { + SystemChrome.setSystemUIOverlayStyle(defaultSystemStyle); + } + + static SystemUiOverlayStyle get defaultSystemStyle => SystemUiOverlayStyle( + systemNavigationBarColor: Colors.white, + statusBarColor: Colors.transparent, + statusBarIconBrightness: Brightness.light, + statusBarBrightness: Brightness.light, + ); + + static ThemeData get lightTheme => + ThemeData(primarySwatch: Colors.yellow).copyWith( + textTheme: TextTheme().apply(displayColor: Color(0xFF333333)), + primaryColor: kPrimaryColor, + textButtonTheme: TextButtonThemeData( + style: ButtonStyle( + foregroundColor: MaterialStateProperty.all(kPrimaryColor), + overlayColor: + MaterialStateProperty.all(kPrimaryColor.withOpacity(0.2)), + padding: MaterialStateProperty.all( + EdgeInsets.symmetric(horizontal: 20.w), + ), + textStyle: MaterialStateProperty.all(TextStyle( + fontSize: 16.sp, + fontWeight: FontWeight.w500, + )), + ), + ), + appBarTheme: AppBarTheme( + brightness: Brightness.light, + backgroundColor: kForegroundColor, + elevation: 0, + centerTitle: true, + textTheme: TextTheme( + headline6: TextStyle( + color: kTextColor, + fontSize: 18.sp, + fontWeight: FontWeight.bold, + ), + ), + ), + ); +} diff --git a/pubspec.lock b/pubspec.lock index 28695ab..d392066 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -95,12 +95,10 @@ packages: flutter_easyrefresh: dependency: "direct main" description: - path: "." - ref: v2 - resolved-ref: "73f03412c46b4662db6fb92fa18902d82c52e6b6" - url: "https://github.com/xuelongqy/flutter_easyrefresh" - source: git - version: "2.2.0" + name: flutter_easyrefresh + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.1" flutter_plugin_android_lifecycle: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index c6a9a22..b680946 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -11,10 +11,7 @@ dependencies: flutter: sdk: flutter flutter_screenutil: ^5.0.0 - flutter_easyrefresh: - git: - url: https://github.com/xuelongqy/flutter_easyrefresh - ref: v2 + flutter_easyrefresh: ^2.2.1 lpinyin: ^2.0.1 image_picker: ^0.7.2 bot_toast: ^4.0.0+1