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 { final Map arguments; CustomPage({this.arguments}); @override State createState() { return _CustomPage(); } } class _CustomPage extends State{ String customDate = ''; String endCustomDate = ''; void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) { setState(() { if (args.value is PickerDateRange) { customDate = DateFormat('yyyy年MM月dd日 HH:mm:ss').format(args.value.startDate).toString() + ' 至 ' + DateFormat('yyyy年MM月dd日 23:59:59') .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: [ Positioned( left: 0, top: 0, right: 0, bottom: 0, child: (widget.arguments["beyondDateRange"]) == "1"?SfDateRangePicker( onSelectionChanged: _onSelectionChanged, selectionMode: DateRangePickerSelectionMode.range, initialSelectedRange: PickerDateRange( DateTime.now().subtract(const Duration(days: 4)), DateTime.now().add(const Duration(days: 3)),), startRangeSelectionColor: Color(0xFF30415B), endRangeSelectionColor: Color(0xFF30415B), todayHighlightColor: Color(0xFF30415B), ):SfDateRangePicker( onSelectionChanged: _onSelectionChanged, maxDate: DateTime.now(), selectionMode: DateRangePickerSelectionMode.range, initialSelectedRange: PickerDateRange( DateTime.now().subtract(const Duration(days: 4)), DateTime.now().add(const Duration(days: 3)),), startRangeSelectionColor: Color(0xFF30415B), endRangeSelectionColor: Color(0xFF30415B), todayHighlightColor: Color(0xFF30415B), ), ) ], )); } }