You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

77 lines
2.2 KiB

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))),
startRangeSelectionColor: Color(0xFF30415B),
endRangeSelectionColor: Color(0xFF30415B),
todayHighlightColor: Color(0xFF30415B),
),
)
],
));
}
}