Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
In an application, the date range picker can be displayed in a dialog window by using the `onPressed` event of the button.

## Step 1:
To host a date range picker in a pop-up, you can use the 'AlertDialog' window to achieve this add the date range picker inside the alert dialog and open the dialog on the 'onpressed' event of a button. Here, a flat button is used.
To host a date range picker in a pop-up, you can use the 'AlertDialog' window to achieve this add the date range picker inside the alert dialog and open the dialog on the 'onpressed' event of a button. Here, a material button is used.

```xml
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
FlatButton(
MaterialButton(
child: Container(
child: _selectedDate ==null
? Text('Select a date'):Text(_selectedDate),
? Text('Select a date'):Text(_selectedDate!),
),
onPressed: () {
showDialog(
Expand All @@ -26,7 +26,7 @@ body: Column(
child: Column(
children: <Widget>[
getDateRangePicker(),
FlatButton(
MaterialButton(
child: Text("OK"),
onPressed: () {
Navigator.pop(context);
Expand Down Expand Up @@ -61,7 +61,7 @@ Using the `onSelectionChanged` event, you can show the selected date of the pick
void selectionChanged(DateRangePickerSelectionChangedArgs args) {
_selectedDate = DateFormat('dd MMMM, yyyy').format(args.value);

SchedulerBinding.instance.addPostFrameCallback((duration) {
SchedulerBinding.instance!.addPostFrameCallback((duration) {
setState(() {});
});
}
Expand Down
15 changes: 0 additions & 15 deletions lib/generated_plugin_registrant.dart

This file was deleted.

74 changes: 36 additions & 38 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
Expand All @@ -25,7 +23,7 @@ class SelectedDatePicker extends StatefulWidget {
}

class _SelectedDatePickerState extends State<SelectedDatePicker> {
String _selectedDate;
String? _selectedDate;

@override
void initState() {
Expand All @@ -34,49 +32,49 @@ class _SelectedDatePickerState extends State<SelectedDatePicker> {
}

@override

Widget build(BuildContext context) {
return Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
FlatButton(
child: Container(
child: _selectedDate ==null
? Text('Select a date '):Text(_selectedDate),
),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(''),
content: Container(
height: 350,
child: Column(
children: <Widget>[
getDateRangePicker(),
FlatButton(
child: Text("OK"),
onPressed: () {
Navigator.pop(context);
},
)
],
),
));
});
},
),
],
));
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
MaterialButton(
child: Container(
child: _selectedDate == null
? Text('Select a date ')
: Text(_selectedDate!),
),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(''),
content: Container(
height: 350,
child: Column(
children: <Widget>[
getDateRangePicker(),
MaterialButton(
child: Text("OK"),
onPressed: () {
Navigator.pop(context);
},
)
],
),
));
});
},
),
],
));
}

void selectionChanged(DateRangePickerSelectionChangedArgs args) {
_selectedDate = DateFormat('dd MMMM, yyyy').format(args.value);

SchedulerBinding.instance.addPostFrameCallback((duration) {
SchedulerBinding.instance!.addPostFrameCallback((duration) {
setState(() {});
});
}
Expand Down
Loading