完成Dialog

null_safety
小赖 4 years ago
parent 3564cb0472
commit ee90d3356b

@ -3,8 +3,6 @@ import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
class ExampleDialog extends StatefulWidget { class ExampleDialog extends StatefulWidget {
ExampleDialog({Key key}) : super(key: key);
@override @override
_ExampleDialogState createState() => _ExampleDialogState(); _ExampleDialogState createState() => _ExampleDialogState();
} }
@ -19,7 +17,20 @@ class _ExampleDialogState extends State<ExampleDialog> {
ASButton.info( ASButton.info(
title: '打开对话框', title: '打开对话框',
onPressed: () { onPressed: () {
Get.dialog(ASDialog()); Get.dialog(ASDialog(
close: true,
child: Text('确认吗'),
items: [
ASDialogButton.outline(
title: '确认',
onPressed: () {},
),
ASDialogButton(
title: '确认',
onPressed: () {},
),
],
));
}), }),
], ],
), ),

@ -60,7 +60,7 @@ class _ExampleListTileState extends State<ExampleListTile> {
20.hb, 20.hb,
ASOptionTile.single( ASOptionTile.single(
item: ASVerticalTileItem( item: ASVerticalTileItem(
title: 'AS Vertical Tile', title: Text('AS Vertical Tile'),
child: TextField(), child: TextField(),
), ),
), ),

@ -13,7 +13,9 @@ export 'bar/as_tabbar.dart';
export 'drawer/as_drawer.dart'; export 'drawer/as_drawer.dart';
export 'pickers/as_date_picker.dart'; export 'pickers/as_date_picker.dart';
export 'pickers/as_picker_box.dart'; export 'pickers/as_picker_box.dart';
export 'dialog/as_dialog.dart'; export 'dialog/as_dialog.dart';
export 'dialog/as_dialog_button.dart';
export 'list_tile/as_list_tile.dart'; export 'list_tile/as_list_tile.dart';
export 'list_tile/as_option_tile.dart'; export 'list_tile/as_option_tile.dart';

@ -113,8 +113,6 @@ class _ASLongButtonState extends State<ASLongButton> {
borderRadius: BorderRadius.circular(widget.radius ?? 22.5.w)), borderRadius: BorderRadius.circular(widget.radius ?? 22.5.w)),
color: widget.bgColor ?? kForegroundColor, color: widget.bgColor ?? kForegroundColor,
elevation: 0, elevation: 0,
// // focusElevation: 0,
// // hoverElevation: 0,
highlightElevation: 0, highlightElevation: 0,
); );
} }

@ -2,15 +2,52 @@ import 'package:ansu_ui/styles/as_colors.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ansu_ui/extension/sizedbox_extension.dart';
class ASDialog extends StatefulWidget { class ASDialog extends StatefulWidget {
ASDialog({Key key}) : super(key: key); final bool close;
///
final List<Widget> 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 @override
_ASDialogState createState() => _ASDialogState(); _ASDialogState createState() => _ASDialogState();
} }
class _ASDialogState extends State<ASDialog> { class _ASDialogState extends State<ASDialog> {
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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Center( return Center(
@ -23,15 +60,35 @@ class _ASDialogState extends State<ASDialog> {
), ),
child: Stack( child: Stack(
children: [ children: [
Column( Padding(
padding: _widgetPadding,
child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Container( Center(
height: 100, 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;
}),
], ],
), ),
Positioned( ),
widget.close
? Positioned(
right: 0, right: 0,
top: 0, top: 0,
child: IconButton( child: IconButton(
@ -43,7 +100,8 @@ class _ASDialogState extends State<ASDialog> {
onPressed: () => Navigator.pop(context), onPressed: () => Navigator.pop(context),
splashRadius: 16.w, splashRadius: 16.w,
), ),
), )
: SizedBox(),
], ],
), ),
), ),

@ -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,
),
);
}
}

@ -2,10 +2,13 @@ import 'package:ansu_ui/ansu_ui.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
extension SizedBoxExt on num { extension NumExt on num {
/// SizedBox /// SizedBox
Widget get wb => SizedBox(width: ScreenUtil().setWidth(this)); Widget get wb => SizedBox(width: this.w);
/// SizedBox /// SizedBox
Widget get hb => SizedBox(height: ScreenUtil().setWidth(this)); Widget get hb => SizedBox(height: this.w);
///
BorderRadius get radius => BorderRadius.circular(this.w);
} }

@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
class ASVerticalTileItem extends StatelessWidget { class ASVerticalTileItem extends StatelessWidget {
/// ///
final String title; final Widget title;
///child ///child
final Widget child; final Widget child;
@ -32,12 +32,12 @@ class ASVerticalTileItem extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Text( DefaultTextStyle(
title,
style: TextStyle( style: TextStyle(
color: kTextSubColor, color: kTextSubColor,
fontSize: 14.sp, fontSize: 14.sp,
), ),
child: title,
), ),
13.hb, 13.hb,
ASDivider(), ASDivider(),

Loading…
Cancel
Save