From 166d957f9dea7e7aca939238cd3218c92f00687c Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 2 Nov 2020 09:25:38 +0800 Subject: [PATCH] add qrcode scan add aku scaffold add aku backbutton add settings page --- android/app/build.gradle | 2 +- ios/Flutter/Debug.xcconfig | 1 + ios/Flutter/Release.xcconfig | 1 + ios/Podfile | 41 +++++++++++ lib/main.dart | 12 ++-- lib/style/app_style.dart | 2 + lib/tools/screen_tool.dart | 1 + lib/ui/home/home_page.dart | 15 ++-- lib/ui/home/personal_draw.dart | 10 ++- lib/ui/settings/settings_page.dart | 19 +++++ lib/ui/tool_pages/scan_page.dart | 52 ++++++++++++++ lib/ui/widgets/common/aku_back_button.dart | 33 +++++++++ lib/ui/widgets/common/aku_scaffold.dart | 81 ++++++++++++++++++++++ pubspec.lock | 14 ++++ pubspec.yaml | 12 ++-- 15 files changed, 276 insertions(+), 20 deletions(-) create mode 100644 ios/Podfile create mode 100644 lib/ui/settings/settings_page.dart create mode 100644 lib/ui/tool_pages/scan_page.dart create mode 100644 lib/ui/widgets/common/aku_back_button.dart create mode 100644 lib/ui/widgets/common/aku_scaffold.dart diff --git a/android/app/build.gradle b/android/app/build.gradle index 3eec671..a008811 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -39,7 +39,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.akucommunity.aku_community_manager" - minSdkVersion 16 + minSdkVersion 24 targetSdkVersion 29 versionCode flutterVersionCode.toInteger() versionName flutterVersionName diff --git a/ios/Flutter/Debug.xcconfig b/ios/Flutter/Debug.xcconfig index 592ceee..e8efba1 100644 --- a/ios/Flutter/Debug.xcconfig +++ b/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/ios/Flutter/Release.xcconfig b/ios/Flutter/Release.xcconfig index 592ceee..399e934 100644 --- a/ios/Flutter/Release.xcconfig +++ b/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/ios/Podfile b/ios/Podfile new file mode 100644 index 0000000..1e8c3c9 --- /dev/null +++ b/ios/Podfile @@ -0,0 +1,41 @@ +# Uncomment this line to define a global platform for your project +# platform :ios, '9.0' + +# CocoaPods analytics sends network stats synchronously affecting flutter build latency. +ENV['COCOAPODS_DISABLE_STATS'] = 'true' + +project 'Runner', { + 'Debug' => :debug, + 'Profile' => :release, + 'Release' => :release, +} + +def flutter_root + generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__) + unless File.exist?(generated_xcode_build_settings_path) + raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first" + end + + File.foreach(generated_xcode_build_settings_path) do |line| + matches = line.match(/FLUTTER_ROOT\=(.*)/) + return matches[1].strip if matches + end + raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get" +end + +require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root) + +flutter_ios_podfile_setup + +target 'Runner' do + use_frameworks! + use_modular_headers! + + flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__)) +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + flutter_additional_ios_build_settings(target) + end +end diff --git a/lib/main.dart b/lib/main.dart index f344cf6..b91df4b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,6 @@ import 'package:aku_community_manager/provider/user_provider.dart'; import 'package:aku_community_manager/ui/home/home_page.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:provider/provider.dart'; @@ -13,13 +14,16 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MultiProvider( - providers:[ - ChangeNotifierProvider(create: (context)=>UserProvider()), + providers: [ + ChangeNotifierProvider(create: (context) => UserProvider()), ], - child: GetMaterialApp( + child: GetMaterialApp( title: '小蜜蜂管家', home: HomePage(), - + builder: BotToastInit(), + navigatorObservers: [ + BotToastNavigatorObserver(), + ], ), ); } diff --git a/lib/style/app_style.dart b/lib/style/app_style.dart index 82ef835..79324b2 100644 --- a/lib/style/app_style.dart +++ b/lib/style/app_style.dart @@ -5,7 +5,9 @@ class AppStyle { static const minorColor=Color(0xFFFFDF5D); //字体 + ///主字体颜色 static const primaryTextColor=Color(0xFF333333); + ///次字体颜色 static const minorTextColor=Color(0xFF999999); } \ No newline at end of file diff --git a/lib/tools/screen_tool.dart b/lib/tools/screen_tool.dart index a2f3910..786275d 100644 --- a/lib/tools/screen_tool.dart +++ b/lib/tools/screen_tool.dart @@ -1,3 +1,4 @@ import 'package:flutter_screenutil/flutter_screenutil.dart'; +export 'package:flutter_screenutil/flutter_screenutil.dart'; double get statusBarHeight => ScreenUtil().statusBarHeight; diff --git a/lib/ui/home/home_page.dart b/lib/ui/home/home_page.dart index 222a0ca..b73ca35 100644 --- a/lib/ui/home/home_page.dart +++ b/lib/ui/home/home_page.dart @@ -3,6 +3,7 @@ import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/tools/screen_tool.dart'; import 'package:aku_community_manager/tools/widget_tool.dart'; import 'package:aku_community_manager/ui/home/personal_draw.dart'; +import 'package:aku_community_manager/ui/tool_pages/scan_page.dart'; import 'package:aku_ui/aku_ui.dart'; import 'package:aku_ui/common_widgets/aku_material_button.dart'; import 'package:flutter/material.dart'; @@ -80,7 +81,7 @@ Widget _card(String number, String text, Color color) { class _HomePageState extends State { @override Widget build(BuildContext context) { - final userProvider=Provider.of(context); + final userProvider = Provider.of(context); ScreenUtil.init(context, designSize: Size(750, 1334), allowFontScaling: true); return Scaffold( @@ -124,9 +125,11 @@ class _HomePageState extends State { onPressed: () { Scaffold.of(context).openDrawer(); }, - child: CircleAvatar(radius: 36.w, - backgroundColor: Colors.grey, - child: userProvider.isSigned?null:null,), + child: CircleAvatar( + radius: 36.w, + backgroundColor: Colors.grey, + child: userProvider.isSigned ? null : null, + ), ); })), SizedBox(width: 16.w), @@ -173,7 +176,9 @@ class _HomePageState extends State { height: double.infinity, minWidth: 78.w, padding: EdgeInsets.zero, - onPressed: () {}, + onPressed: () { + Get.to(ScanPage()); + }, child: Column(children: [ Icon( Icons.access_alarm, diff --git a/lib/ui/home/personal_draw.dart b/lib/ui/home/personal_draw.dart index 5635a57..321be78 100644 --- a/lib/ui/home/personal_draw.dart +++ b/lib/ui/home/personal_draw.dart @@ -1,9 +1,11 @@ import 'package:aku_community_manager/provider/user_provider.dart'; import 'package:aku_community_manager/style/app_style.dart'; +import 'package:aku_community_manager/ui/settings/settings_page.dart'; import 'package:aku_ui/common_widgets/aku_button.dart'; import 'package:aku_ui/common_widgets/aku_round_button.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; import 'package:provider/provider.dart'; class PersonalDraw extends StatefulWidget { @@ -14,9 +16,9 @@ class PersonalDraw extends StatefulWidget { } class _PersonalDrawState extends State { - Widget _myListTile(IconData iconData, String text) { + Widget _myListTile(IconData iconData, String text, {VoidCallback onPressed}) { return AkuButton( - onPressed: () {}, + onPressed: onPressed, child: Container( width: double.infinity, height: 96.w, @@ -108,7 +110,9 @@ class _PersonalDrawState extends State { ), _myListTile(Icons.contact_page, '个人信息'), _myListTile(Icons.supervised_user_circle, '联系客服'), - _myListTile(Icons.settings, '设置'), + _myListTile(Icons.settings, '设置', onPressed: () { + Get.to(SettingsPage()); + }), ], ), ); diff --git a/lib/ui/settings/settings_page.dart b/lib/ui/settings/settings_page.dart new file mode 100644 index 0000000..65f861a --- /dev/null +++ b/lib/ui/settings/settings_page.dart @@ -0,0 +1,19 @@ +import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; +import 'package:flutter/material.dart'; + +class SettingsPage extends StatefulWidget { + SettingsPage({Key key}) : super(key: key); + + @override + _SettingsPageState createState() => _SettingsPageState(); +} + +class _SettingsPageState extends State { + @override + Widget build(BuildContext context) { + return AkuScaffold( + title: '设置', + body: Text('test'), + ); + } +} diff --git a/lib/ui/tool_pages/scan_page.dart b/lib/ui/tool_pages/scan_page.dart new file mode 100644 index 0000000..cd7c3c7 --- /dev/null +++ b/lib/ui/tool_pages/scan_page.dart @@ -0,0 +1,52 @@ +import 'package:bot_toast/bot_toast.dart'; +import 'package:flutter/material.dart'; +import 'package:qr_code_scanner/qr_code_scanner.dart'; + +class ScanPage extends StatefulWidget { + ScanPage({Key key}) : super(key: key); + + @override + _ScanPageState createState() => _ScanPageState(); +} + +class _ScanPageState extends State { + GlobalKey qrKey = GlobalKey(debugLabel: 'QR'); + QRViewController _qrViewController; + + @override + void dispose() { + _qrViewController?.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + body: Stack( + children: [ + QRView( + key: qrKey, + onQRViewCreated: (controller) { + _qrViewController = controller; + controller.scannedDataStream.listen((event) { + BotToast.showText(text: event); + }); + }, + ), + Center( + child: Container( + height: 200, + width: 200, + decoration: BoxDecoration( + border: Border.all( + color: Colors.red, + width: 1, + ), + ), + ), + ), + ], + ), + ); + } +} diff --git a/lib/ui/widgets/common/aku_back_button.dart b/lib/ui/widgets/common/aku_back_button.dart new file mode 100644 index 0000000..e3c49e9 --- /dev/null +++ b/lib/ui/widgets/common/aku_back_button.dart @@ -0,0 +1,33 @@ +import 'package:flutter/material.dart'; +import 'package:aku_community_manager/tools/screen_tool.dart'; + +class AkuBackButton extends StatefulWidget { + final Brightness brightness; + AkuBackButton({ + Key key, + this.brightness = Brightness.light, + }) : super(key: key); + + @override + _AkuBackButtonState createState() => _AkuBackButtonState(); +} + +class _AkuBackButtonState extends State { + @override + Widget build(BuildContext context) { + return Navigator.canPop(context) + ? IconButton( + icon: Icon( + Icons.arrow_back_ios, + size: 32.w, + color: widget.brightness == Brightness.light + ? Color(0xFF333333) + : Color(0xFFEEEEEE), + ), + onPressed: () { + Navigator.pop(context); + }, + ) + : SizedBox(); + } +} diff --git a/lib/ui/widgets/common/aku_scaffold.dart b/lib/ui/widgets/common/aku_scaffold.dart new file mode 100644 index 0000000..c34817c --- /dev/null +++ b/lib/ui/widgets/common/aku_scaffold.dart @@ -0,0 +1,81 @@ +import 'package:aku_community_manager/ui/widgets/common/aku_back_button.dart'; +import 'package:flutter/material.dart'; +import 'package:aku_community_manager/tools/screen_tool.dart'; + +///用法大致同Scaffold + +class AkuScaffold extends StatefulWidget { + ///AppBar 使用该值 `title`,`titleStyle`,`leading`,`brightness`将失效 + final PreferredSizeWidget appBar; + + ///title + final String title; + + ///title style + /// + ///默认 + /// + ///``` + ///TextStyle( + /// fontWeight: FontWeight.bold, + /// color: Color(0xFF333333), + /// fontSize: 36.sp, + ///) + ///``` + final TextStyle titleStyle; + + ///leading + /// + ///默认使用 `AkuBackButton` + final Widget leading; + + ///brightness + final Brightness brightness; + + ///body + final Widget body; + + ///背景色 + /// + ///默认`0xFFF9F9F9` + final Color backgroundColor; + AkuScaffold({ + Key key, + this.appBar, + this.title, + this.titleStyle, + this.leading, + this.brightness = Brightness.light, + this.body, + this.backgroundColor = const Color(0XFFF9F9F9), + }) : super(key: key); + + @override + _AkuScaffoldState createState() => _AkuScaffoldState(); +} + +class _AkuScaffoldState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + backgroundColor: widget.backgroundColor, + appBar: AppBar( + backgroundColor: Colors.white, + leading: widget.leading ?? AkuBackButton(), + brightness: widget.brightness, + elevation: 0, + centerTitle: true, + title: DefaultTextStyle( + style: widget.titleStyle ?? + TextStyle( + fontWeight: FontWeight.bold, + color: Color(0xFF333333), + fontSize: 36.sp, + ), + child: Text(widget.title), + ), + ), + body: widget.body, + ); + } +} diff --git a/pubspec.lock b/pubspec.lock index a6882f8..cdf4490 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -24,6 +24,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0-nullsafety.1" + bot_toast: + dependency: "direct main" + description: + name: bot_toast + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.0.4" characters: dependency: transitive description: @@ -132,6 +139,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "4.3.2+2" + qr_code_scanner: + dependency: "direct main" + description: + name: qr_code_scanner + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.13" sky_engine: dependency: transitive description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index df70e45..f84c33f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: A new Flutter application. # The following line prevents the package from being accidentally published to # pub.dev using `pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev +publish_to: "none" # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 @@ -24,7 +24,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.0 @@ -36,6 +35,10 @@ dependencies: get: ^3.15.0 #刷新 flutter_easyrefresh: ^2.1.6 + #qrcode san + qr_code_scanner: ^0.0.13 + #toast + bot_toast: ^3.0.4 aku_ui: git: @@ -50,23 +53,18 @@ dev_dependencies: # The following section is specific to Flutter. flutter: - # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # 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 - # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware. - # For details regarding adding assets from package dependencies, see # https://flutter.dev/assets-and-images/#from-packages - # To add custom fonts to your application, add a fonts section here, # in this "flutter" section. Each entry in this list should have a # "family" key with the font family name, and a "fonts" key with a