From 92f82b13499814433d13029e554db67dad05f8b8 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 25 Jan 2021 09:49:09 +0800 Subject: [PATCH] add global auto unfocus finish advice page add image preview page --- lib/main.dart | 46 ++++++++++------- lib/ui/manager/advice/new_advice_page.dart | 29 +++++++++++ lib/widget/bottom_button.dart | 9 +++- lib/widget/picker/bee_image_preview.dart | 33 +++++++++++++ lib/widget/picker/grid_image_picker.dart | 57 ++++++++++++---------- 5 files changed, 130 insertions(+), 44 deletions(-) create mode 100644 lib/widget/picker/bee_image_preview.dart diff --git a/lib/main.dart b/lib/main.dart index 501f7bcf..66148ab7 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'package:akuCommunity/utils/developer_util.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; +import 'package:flutter/services.dart'; import 'package:fluwx/fluwx.dart'; import 'package:get/get.dart'; import 'package:provider/provider.dart'; @@ -41,23 +42,34 @@ class _MyAppState extends State { ChangeNotifierProvider(create: (context) => UserProvider()), ChangeNotifierProvider(create: (context) => SignUpProvider()), ], - child: GetMaterialApp( - title: '智慧社区', - debugShowCheckedModeBanner: false, - theme: ThemeData(primarySwatch: Colors.yellow), - home: SplashPage(), - //国际化支持 - localizationsDelegates: [ - PickerLocalizationsDelegate.delegate, - RefreshLocalizations.delegate, - GlobalMaterialLocalizations.delegate, - GlobalWidgetsLocalizations.delegate, - GlobalCupertinoLocalizations.delegate, - ], - supportedLocales: [const Locale('zh', 'CH')], - locale: Locale('zh'), - builder: BotToastInit(), - navigatorObservers: [BotToastNavigatorObserver()], + child: GestureDetector( + onTap: () { + //点击输入框外部隐藏键盘⌨️ + //只能响应点击非手势识别的组件 + FocusScopeNode currentFocus = FocusScope.of(context); + if (!currentFocus.hasPrimaryFocus && + currentFocus.focusedChild != null) { + FocusManager.instance.primaryFocus.unfocus(); + } + }, + child: GetMaterialApp( + title: '智慧社区', + debugShowCheckedModeBanner: false, + theme: ThemeData(primarySwatch: Colors.yellow), + home: SplashPage(), + //国际化支持 + localizationsDelegates: [ + PickerLocalizationsDelegate.delegate, + RefreshLocalizations.delegate, + GlobalMaterialLocalizations.delegate, + GlobalWidgetsLocalizations.delegate, + GlobalCupertinoLocalizations.delegate, + ], + supportedLocales: [const Locale('zh', 'CH')], + locale: Locale('zh'), + builder: BotToastInit(), + navigatorObservers: [BotToastNavigatorObserver()], + ), ), ); } diff --git a/lib/ui/manager/advice/new_advice_page.dart b/lib/ui/manager/advice/new_advice_page.dart index 64c97cfb..66d3a58c 100644 --- a/lib/ui/manager/advice/new_advice_page.dart +++ b/lib/ui/manager/advice/new_advice_page.dart @@ -1,7 +1,11 @@ +import 'dart:io'; + import 'package:akuCommunity/const/resource.dart'; import 'package:akuCommunity/ui/manager/advice/advice_page.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart'; import 'package:akuCommunity/utils/headers.dart'; +import 'package:akuCommunity/widget/buttons/bottom_button.dart'; +import 'package:akuCommunity/widget/picker/grid_image_picker.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:velocity_x/velocity_x.dart'; @@ -16,6 +20,7 @@ class NewAdvicePage extends StatefulWidget { class _NewAdvicePageState extends State { int _type = 0; + List _files = []; String get title { switch (widget.type) { case AdviceType.SUGGESTION: @@ -106,12 +111,36 @@ class _NewAdvicePageState extends State { 24.hb, TextField( // controller: , + minLines: 6, + maxLines: 99, decoration: InputDecoration( border: OutlineInputBorder(), + isDense: true, + contentPadding: EdgeInsets.symmetric( + horizontal: 22.w, + vertical: 32.w, + ), + hintText: '您对我们的工作有什么建议吗?欢迎您提给我们宝贵的建议,谢谢', + hintStyle: TextStyle( + fontSize: 28.sp, + color: Color(0xFF999999), + ), ), ), + 32.hb, + '添加图片信息(${_files.length}/9)'.text.size(28.sp).make(), + 24.hb, + GridImagePicker( + onChange: (files) { + _files = files; + }, + ), ], ), + bottomNavi: BottomButton( + onPressed: () {}, + child: '确认提交'.text.make(), + ), ); } } diff --git a/lib/widget/bottom_button.dart b/lib/widget/bottom_button.dart index d1652451..775fe45f 100644 --- a/lib/widget/bottom_button.dart +++ b/lib/widget/bottom_button.dart @@ -3,8 +3,13 @@ import 'package:flutter/cupertino.dart'; import 'package:akuCommunity/utils/headers.dart'; import 'package:akuCommunity/base/base_style.dart'; -//TODO CLEAN BOTTOM CODES. -//THIS IS SHIT BUTTON +///TODO CLEAN BOTTOM CODES. +/// +///THIS IS SHIT BUTTON +/// +///use `widget/buttons/bottom_button` instead of this widget. +/// +///try import `'package:akuCommunity/widget/buttons/bottom_button.dart'` @Deprecated("sh*t bottom_button need to be cleaned.") class BottomButton extends StatefulWidget { final String title; diff --git a/lib/widget/picker/bee_image_preview.dart b/lib/widget/picker/bee_image_preview.dart new file mode 100644 index 00000000..bb6781c9 --- /dev/null +++ b/lib/widget/picker/bee_image_preview.dart @@ -0,0 +1,33 @@ +import 'dart:io'; + +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; + +class BeeImagePreview extends StatefulWidget { + final File file; + BeeImagePreview({Key key, @required this.file}) : super(key: key); + + @override + _BeeImagePreviewState createState() => _BeeImagePreviewState(); +} + +class _BeeImagePreviewState extends State { + @override + Widget build(BuildContext context) { + return GestureDetector( + onTap: Get.back, + child: Scaffold( + backgroundColor: Colors.black54, + body: Center( + child: InteractiveViewer( + minScale: 0.2, + child: Hero( + tag: widget.file.hashCode, + child: Image.file(widget.file), + ), + ), + ), + ), + ); + } +} diff --git a/lib/widget/picker/grid_image_picker.dart b/lib/widget/picker/grid_image_picker.dart index 49e8c42f..9f25c839 100644 --- a/lib/widget/picker/grid_image_picker.dart +++ b/lib/widget/picker/grid_image_picker.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:akuCommunity/painters/plus_painter.dart'; import 'package:akuCommunity/widget/picker/bee_image_picker.dart'; +import 'package:akuCommunity/widget/picker/bee_image_preview.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -64,32 +65,38 @@ class _GridImagePickerState extends State { } Widget _buildItem(File file) { - return Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(8.w), - image: DecorationImage( - image: FileImage(file), + return Hero( + tag: file.hashCode, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(8.w), + image: DecorationImage( + image: FileImage(file), + fit: BoxFit.cover, + ), + ), + child: MaterialButton( + onPressed: () { + Get.to(BeeImagePreview(file: file),opaque: false); + }, + onLongPress: () async { + bool result = await Get.dialog(CupertinoAlertDialog( + title: '删除该图片?'.text.isIntrinsic.make(), + actions: [ + CupertinoDialogAction( + child: '取消'.text.isIntrinsic.make(), + onPressed: Get.back, + ), + CupertinoDialogAction( + child: '确定'.text.red600.isIntrinsic.make(), + onPressed: () => Get.back(result: true), + ), + ], + )); + if (result == true) _files.remove(file); + setState(() {}); + }, ), - ), - child: MaterialButton( - onPressed: () {}, - onLongPress: () async { - bool result = await Get.dialog(CupertinoAlertDialog( - title: '删除该图片?'.text.isIntrinsic.make(), - actions: [ - CupertinoDialogAction( - child: '取消'.text.isIntrinsic.make(), - onPressed: Get.back, - ), - CupertinoDialogAction( - child: '确定'.text.red600.isIntrinsic.make(), - onPressed: () => Get.back(result: true), - ), - ], - )); - if (result == true) _files.remove(file); - setState(() {}); - }, ), ); }