parent
ebe4c5187d
commit
870ea1b121
After Width: | Height: | Size: 7.0 KiB |
@ -0,0 +1,39 @@
|
||||
import 'package:ansu_ui/ansu_ui.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class ExamplePicker extends StatefulWidget {
|
||||
ExamplePicker({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ExamplePickerState createState() => _ExamplePickerState();
|
||||
}
|
||||
|
||||
class _ExamplePickerState extends State<ExamplePicker> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ASScaffold(
|
||||
title: '选择器',
|
||||
body: ListView(
|
||||
children: [
|
||||
ASButton(
|
||||
title: '日期选择器 DatePicker',
|
||||
onPressed: () async {
|
||||
DateTime date = await asDatePicker(context);
|
||||
Get.snackbar(date.toString(), 'MESSAGE');
|
||||
},
|
||||
),
|
||||
ASButton(
|
||||
title: '自定义选择器',
|
||||
onPressed: () async {
|
||||
Get.bottomSheet(ASPickerBox(
|
||||
title: '自定义选择器',
|
||||
child: Text('CHILD'),
|
||||
));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
class ASDivider extends StatelessWidget {
|
||||
final Color color;
|
||||
final double height;
|
||||
final double indent;
|
||||
final double endIndent;
|
||||
ASDivider({Key key, this.indent, this.endIndent})
|
||||
: color = const Color(0xFFE9E9E9),
|
||||
height = 1.w,
|
||||
super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Divider(
|
||||
color: color,
|
||||
height: height,
|
||||
thickness: height,
|
||||
indent: indent,
|
||||
endIndent: endIndent,
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
import 'package:ansu_ui/pickers/as_picker_box.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
//时间选择器内部实现
|
||||
class _ASDatePickerWidget extends StatefulWidget {
|
||||
_ASDatePickerWidget({Key key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ASDatePickerWidgetState createState() => _ASDatePickerWidgetState();
|
||||
}
|
||||
|
||||
class _ASDatePickerWidgetState extends State<_ASDatePickerWidget> {
|
||||
DateTime _dateTime;
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_dateTime = DateTime.now();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ASPickerBox(
|
||||
title: '日期',
|
||||
onPressed: () {
|
||||
Navigator.pop(context, _dateTime);
|
||||
},
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 18.w),
|
||||
child: CupertinoDatePicker(
|
||||
onDateTimeChanged: (dateTime) {
|
||||
_dateTime = dateTime;
|
||||
},
|
||||
mode: CupertinoDatePickerMode.date,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
///## 时间选择器
|
||||
///
|
||||
///``` dart
|
||||
/// ASButton(
|
||||
/// title: 'DatePicker',
|
||||
/// onPressed: () async {
|
||||
/// DateTime date = await asDatePicker(context);
|
||||
/// Get.snackbar(date.toString(), 'MESSAGE');
|
||||
/// },
|
||||
/// )
|
||||
///```
|
||||
///
|
||||
///返回一个`Future<DateTime>` 类型的时间
|
||||
///
|
||||
///内部使用Navigator实现
|
||||
///```dart
|
||||
///Navigator.pop(context,dateTime)
|
||||
///```
|
||||
Future<DateTime> asDatePicker(BuildContext context) async {
|
||||
return await showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return _ASDatePickerWidget();
|
||||
},
|
||||
);
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
import 'package:ansu_ui/divider/as_divider.dart';
|
||||
import 'package:ansu_ui/styles/as_colors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
class ASPickerBox extends StatelessWidget {
|
||||
final VoidCallback onPressed;
|
||||
final String confirmString;
|
||||
final String title;
|
||||
final Widget child;
|
||||
const ASPickerBox(
|
||||
{Key key,
|
||||
this.onPressed,
|
||||
this.confirmString = '完成',
|
||||
this.title,
|
||||
@required this.child})
|
||||
: super(key: key);
|
||||
|
||||
_buildButton({
|
||||
@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,
|
||||
)),
|
||||
),
|
||||
onPressed: onPressed,
|
||||
child: Text(title),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: kForegroundColor,
|
||||
child: SizedBox(
|
||||
height: 260.w,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 48.w,
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_buildButton(
|
||||
title: '取消',
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
}),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Text(
|
||||
title ?? '',
|
||||
style: TextStyle(
|
||||
color: kTextColor,
|
||||
fontSize: 16.sp,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildButton(title: confirmString, onPressed: onPressed),
|
||||
],
|
||||
),
|
||||
),
|
||||
ASDivider(),
|
||||
Expanded(child: child),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue