wurong
2 years ago
8 changed files with 209 additions and 110 deletions
@ -0,0 +1,74 @@
|
||||
import 'package:flutter/cupertino.dart'; |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:intl/intl.dart'; |
||||
import 'package:syncfusion_flutter_datepicker/datepicker.dart'; |
||||
|
||||
import '../../view_widget/my_appbar.dart'; |
||||
|
||||
class CustomPage extends StatefulWidget { |
||||
|
||||
@override |
||||
State<StatefulWidget> createState() { |
||||
return _CustomPage(); |
||||
} |
||||
} |
||||
|
||||
class _CustomPage extends State<CustomPage>{ |
||||
String customDate = ''; |
||||
String endCustomDate = ''; |
||||
|
||||
void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) { |
||||
setState(() { |
||||
if (args.value is PickerDateRange) { |
||||
customDate = |
||||
DateFormat('yyyy年MM月dd日').format(args.value.startDate).toString() + |
||||
' 至 ' + |
||||
DateFormat('yyyy年MM月dd日') |
||||
.format(args.value.endDate ?? args.value.startDate) |
||||
.toString(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
@override |
||||
Widget build(BuildContext context) { |
||||
return Scaffold( |
||||
appBar: MyAppBar( |
||||
title: "时间选择", |
||||
titleColor: Colors.black, |
||||
leadingColor: Colors.black, |
||||
background: Colors.white, |
||||
actions: [ |
||||
TextButton( |
||||
onPressed: () { |
||||
Navigator.pop(context, customDate,); |
||||
}, |
||||
child: Text( |
||||
"确定", |
||||
style: TextStyle( |
||||
color: Colors.black, |
||||
fontSize: 16, |
||||
), |
||||
), |
||||
), |
||||
], |
||||
), |
||||
body: Stack( |
||||
children: <Widget>[ |
||||
Positioned( |
||||
left: 0, |
||||
top: 0, |
||||
right: 0, |
||||
bottom: 0, |
||||
child: SfDateRangePicker( |
||||
onSelectionChanged: _onSelectionChanged, |
||||
selectionMode: DateRangePickerSelectionMode.range, |
||||
initialSelectedRange: PickerDateRange( |
||||
DateTime.now().subtract(const Duration(days: 4)), |
||||
DateTime.now().add(const Duration(days: 3))), |
||||
), |
||||
) |
||||
], |
||||
)); |
||||
} |
||||
} |
Loading…
Reference in new issue