From ee90d3356b6fc654579c12a8b20cc817fe86ec5c Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 30 Nov 2020 11:20:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90Dialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/lib/example_dialog.dart | 17 +++- example/lib/example_listtile.dart | 2 +- lib/ansu_ui.dart | 2 + lib/buttons/as_longbutton.dart | 2 - lib/dialog/as_dialog.dart | 98 +++++++++++++++++++----- lib/dialog/as_dialog_button.dart | 32 ++++++++ lib/extension/sizedbox_extension.dart | 9 ++- lib/list_tile/as_vertical_tile_item.dart | 6 +- 8 files changed, 136 insertions(+), 32 deletions(-) create mode 100644 lib/dialog/as_dialog_button.dart diff --git a/example/lib/example_dialog.dart b/example/lib/example_dialog.dart index 880f34f..2687c59 100644 --- a/example/lib/example_dialog.dart +++ b/example/lib/example_dialog.dart @@ -3,8 +3,6 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; class ExampleDialog extends StatefulWidget { - ExampleDialog({Key key}) : super(key: key); - @override _ExampleDialogState createState() => _ExampleDialogState(); } @@ -19,7 +17,20 @@ class _ExampleDialogState extends State { ASButton.info( title: '打开对话框', onPressed: () { - Get.dialog(ASDialog()); + Get.dialog(ASDialog( + close: true, + child: Text('确认吗'), + items: [ + ASDialogButton.outline( + title: '确认', + onPressed: () {}, + ), + ASDialogButton( + title: '确认', + onPressed: () {}, + ), + ], + )); }), ], ), diff --git a/example/lib/example_listtile.dart b/example/lib/example_listtile.dart index 55bcb4a..ad377f5 100644 --- a/example/lib/example_listtile.dart +++ b/example/lib/example_listtile.dart @@ -60,7 +60,7 @@ class _ExampleListTileState extends State { 20.hb, ASOptionTile.single( item: ASVerticalTileItem( - title: 'AS Vertical Tile', + title: Text('AS Vertical Tile'), child: TextField(), ), ), diff --git a/lib/ansu_ui.dart b/lib/ansu_ui.dart index 9b928a1..e91c95e 100644 --- a/lib/ansu_ui.dart +++ b/lib/ansu_ui.dart @@ -13,7 +13,9 @@ export 'bar/as_tabbar.dart'; export 'drawer/as_drawer.dart'; export 'pickers/as_date_picker.dart'; export 'pickers/as_picker_box.dart'; + export 'dialog/as_dialog.dart'; +export 'dialog/as_dialog_button.dart'; export 'list_tile/as_list_tile.dart'; export 'list_tile/as_option_tile.dart'; diff --git a/lib/buttons/as_longbutton.dart b/lib/buttons/as_longbutton.dart index 9917e74..89a9e09 100644 --- a/lib/buttons/as_longbutton.dart +++ b/lib/buttons/as_longbutton.dart @@ -113,8 +113,6 @@ class _ASLongButtonState extends State { borderRadius: BorderRadius.circular(widget.radius ?? 22.5.w)), color: widget.bgColor ?? kForegroundColor, elevation: 0, - // // focusElevation: 0, - // // hoverElevation: 0, highlightElevation: 0, ); } diff --git a/lib/dialog/as_dialog.dart b/lib/dialog/as_dialog.dart index 1d11278..dd9cb3c 100644 --- a/lib/dialog/as_dialog.dart +++ b/lib/dialog/as_dialog.dart @@ -2,15 +2,52 @@ import 'package:ansu_ui/styles/as_colors.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:ansu_ui/extension/sizedbox_extension.dart'; class ASDialog extends StatefulWidget { - ASDialog({Key key}) : super(key: key); + final bool close; + + ///按钮组 + final List items; + + ///按钮与按钮之间的间距 + final double spacer; + + final EdgeInsets padding; + + final Widget child; + + final EdgeInsets childPadding; + + ASDialog({ + Key key, + this.close = false, + this.items, + this.spacer, + this.padding, + @required this.child, + this.childPadding, + }) : super(key: key); @override _ASDialogState createState() => _ASDialogState(); } class _ASDialogState extends State { + double get _widgetSpacer => widget.spacer ?? 20.w; + EdgeInsets get _widgetPadding => + widget.padding ?? + EdgeInsets.only( + top: 13.w, + bottom: 20.w, + ); + + EdgeInsets get _childPadding => + widget.childPadding ?? + EdgeInsets.only( + top: 40.w, + bottom: 50.w, + ); @override Widget build(BuildContext context) { return Center( @@ -23,27 +60,48 @@ class _ASDialogState extends State { ), child: Stack( children: [ - Column( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - height: 100, - ), - ], - ), - Positioned( - right: 0, - top: 0, - child: IconButton( - iconSize: 20.w, - icon: Icon( - CupertinoIcons.clear_circled, - color: Color(0xFF060606).withOpacity(0.85), - ), - onPressed: () => Navigator.pop(context), - splashRadius: 16.w, + Padding( + padding: _widgetPadding, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Center( + child: DefaultTextStyle( + style: TextStyle( + color: kTextColor, + fontSize: 20.sp, + fontWeight: FontWeight.bold, + ), + child: Padding( + padding: _childPadding, + child: widget.child, + ), + ), + ), + ...List.generate(widget.items.length * 2 - 1, (index) { + if (index.isEven) + return widget.items[index ~/ 2]; + else + return _widgetSpacer.hb; + }), + ], ), ), + widget.close + ? Positioned( + right: 0, + top: 0, + child: IconButton( + iconSize: 20.w, + icon: Icon( + CupertinoIcons.clear_circled, + color: Color(0xFF060606).withOpacity(0.85), + ), + onPressed: () => Navigator.pop(context), + splashRadius: 16.w, + ), + ) + : SizedBox(), ], ), ), diff --git a/lib/dialog/as_dialog_button.dart b/lib/dialog/as_dialog_button.dart new file mode 100644 index 0000000..3b04c15 --- /dev/null +++ b/lib/dialog/as_dialog_button.dart @@ -0,0 +1,32 @@ +import 'package:ansu_ui/buttons/as_longbutton.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +class ASDialogButton extends StatelessWidget { + final String title; + final VoidCallback onPressed; + final bool outline; + const ASDialogButton( + {Key key, this.title, this.onPressed, this.outline = false}) + : super(key: key); + + const ASDialogButton.outline({Key key, this.title, this.onPressed}) + : outline = true, + super(key: key); + + @override + Widget build(BuildContext context) { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 36.w), + child: outline + ? ASLongButton.hollow( + title: title, + onPressed: onPressed, + ) + : ASLongButton.solid( + title: title, + onPressed: onPressed, + ), + ); + } +} diff --git a/lib/extension/sizedbox_extension.dart b/lib/extension/sizedbox_extension.dart index 576d508..5c5a0b9 100644 --- a/lib/extension/sizedbox_extension.dart +++ b/lib/extension/sizedbox_extension.dart @@ -2,10 +2,13 @@ import 'package:ansu_ui/ansu_ui.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; -extension SizedBoxExt on num { +extension NumExt on num { ///获取宽 SizedBox - Widget get wb => SizedBox(width: ScreenUtil().setWidth(this)); + Widget get wb => SizedBox(width: this.w); ///获取高 SizedBox - Widget get hb => SizedBox(height: ScreenUtil().setWidth(this)); + Widget get hb => SizedBox(height: this.w); + + ///圆角 + BorderRadius get radius => BorderRadius.circular(this.w); } diff --git a/lib/list_tile/as_vertical_tile_item.dart b/lib/list_tile/as_vertical_tile_item.dart index c977590..5a967b6 100644 --- a/lib/list_tile/as_vertical_tile_item.dart +++ b/lib/list_tile/as_vertical_tile_item.dart @@ -4,7 +4,7 @@ import 'package:flutter/material.dart'; class ASVerticalTileItem extends StatelessWidget { ///标题 - final String title; + final Widget title; ///child final Widget child; @@ -32,12 +32,12 @@ class ASVerticalTileItem extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [ - Text( - title, + DefaultTextStyle( style: TextStyle( color: kTextSubColor, fontSize: 14.sp, ), + child: title, ), 13.hb, ASDivider(),