0
Here’s my code, no bugs, but I was trying to implement an adjustment on the Picker date and I couldn’t get until then.
I wanted to create a Picker date that selected from week to week ie 7 days, from Sunday to Saturday. User cannot change to less than or more than 7 days, it is preset.
But I couldn’t get it right yet haha, some help?
import 'package:date_range_picker/date_range_picker.dart' as DateRangePick;
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'dart:async';
import '../constants.dart';
import '../components/chart_bar.dart';
class DetailsScreen extends StatefulWidget {
@override
_DetailsScreenState createState() => _DetailsScreenState();
}
class _DetailsScreenState extends State<DetailsScreen> {
DateTime _startDate = DateTime.now().subtract(Duration(days: 7));
DateTime _endDate = DateTime.now();
Future displayDateRangePicker(context) async {
final List<DateTime> picked = await DateRangePick.showDatePicker(
context: context,
initialFirstDate: _startDate,
initialLastDate: _endDate,
firstDate: DateTime(DateTime.now().year - 10),
lastDate: DateTime.now(),
);
if (picked != null && picked.length == 2) {
setState(() {
_startDate = picked[0];
_startDate = picked[1];
});
}
}
@override
Widget build(BuildContext context) {
_detailsScreen() {
return Scaffold(
backgroundColor: kBlackColor,
body: SafeArea(
child: Center(
child: Column(
children: <Widget>[
FlatButton(
child: Text(
'${DateFormat('d / MM / y').format(_startDate)} - ${DateFormat('d / MM / y').format(_endDate)}',
style: kWhite20RegularTextStyle,
),
onPressed: () async {
await displayDateRangePicker(context);
},
),
],
),
),
),
);
}
return _detailsScreen();
}
}