Skip to content

Commit 0b626b2

Browse files
committed
FLUT-4313-Sample updated with null safety.
1 parent e671962 commit 0b626b2

File tree

5 files changed

+82
-182
lines changed

5 files changed

+82
-182
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
In an application, the date range picker can be displayed in a dialog window by using the `onPressed` event of the button.
44

55
## Step 1:
6-
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.
6+
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.
77

88
```xml
99
body: Column(
1010
mainAxisAlignment: MainAxisAlignment.center,
1111
crossAxisAlignment: CrossAxisAlignment.stretch,
1212
children: <Widget>[
13-
FlatButton(
13+
MaterialButton(
1414
child: Container(
1515
child: _selectedDate ==null
16-
? Text('Select a date'):Text(_selectedDate),
16+
? Text('Select a date'):Text(_selectedDate!),
1717
),
1818
onPressed: () {
1919
showDialog(
@@ -26,7 +26,7 @@ body: Column(
2626
child: Column(
2727
children: <Widget>[
2828
getDateRangePicker(),
29-
FlatButton(
29+
MaterialButton(
3030
child: Text("OK"),
3131
onPressed: () {
3232
Navigator.pop(context);
@@ -61,7 +61,7 @@ Using the `onSelectionChanged` event, you can show the selected date of the pick
6161
void selectionChanged(DateRangePickerSelectionChangedArgs args) {
6262
_selectedDate = DateFormat('dd MMMM, yyyy').format(args.value);
6363

64-
SchedulerBinding.instance.addPostFrameCallback((duration) {
64+
SchedulerBinding.instance!.addPostFrameCallback((duration) {
6565
setState(() {});
6666
});
6767
}

lib/generated_plugin_registrant.dart

Lines changed: 0 additions & 15 deletions
This file was deleted.

lib/main.dart

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import 'dart:math';
2-
31
import 'package:flutter/cupertino.dart';
42
import 'package:flutter/material.dart';
53
import 'package:flutter/scheduler.dart';
@@ -25,7 +23,7 @@ class SelectedDatePicker extends StatefulWidget {
2523
}
2624

2725
class _SelectedDatePickerState extends State<SelectedDatePicker> {
28-
String _selectedDate;
26+
String? _selectedDate;
2927

3028
@override
3129
void initState() {
@@ -34,49 +32,49 @@ class _SelectedDatePickerState extends State<SelectedDatePicker> {
3432
}
3533

3634
@override
37-
3835
Widget build(BuildContext context) {
3936
return Scaffold(
4037
body: Column(
41-
mainAxisAlignment: MainAxisAlignment.center,
42-
crossAxisAlignment: CrossAxisAlignment.stretch,
43-
children: <Widget>[
44-
FlatButton(
45-
child: Container(
46-
child: _selectedDate ==null
47-
? Text('Select a date '):Text(_selectedDate),
48-
),
49-
onPressed: () {
50-
showDialog(
51-
context: context,
52-
builder: (BuildContext context) {
53-
return AlertDialog(
54-
title: Text(''),
55-
content: Container(
56-
height: 350,
57-
child: Column(
58-
children: <Widget>[
59-
getDateRangePicker(),
60-
FlatButton(
61-
child: Text("OK"),
62-
onPressed: () {
63-
Navigator.pop(context);
64-
},
65-
)
66-
],
67-
),
68-
));
69-
});
70-
},
71-
),
72-
],
73-
));
38+
mainAxisAlignment: MainAxisAlignment.center,
39+
crossAxisAlignment: CrossAxisAlignment.stretch,
40+
children: <Widget>[
41+
MaterialButton(
42+
child: Container(
43+
child: _selectedDate == null
44+
? Text('Select a date ')
45+
: Text(_selectedDate!),
46+
),
47+
onPressed: () {
48+
showDialog(
49+
context: context,
50+
builder: (BuildContext context) {
51+
return AlertDialog(
52+
title: Text(''),
53+
content: Container(
54+
height: 350,
55+
child: Column(
56+
children: <Widget>[
57+
getDateRangePicker(),
58+
MaterialButton(
59+
child: Text("OK"),
60+
onPressed: () {
61+
Navigator.pop(context);
62+
},
63+
)
64+
],
65+
),
66+
));
67+
});
68+
},
69+
),
70+
],
71+
));
7472
}
7573

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

79-
SchedulerBinding.instance.addPostFrameCallback((duration) {
77+
SchedulerBinding.instance!.addPostFrameCallback((duration) {
8078
setState(() {});
8179
});
8280
}

0 commit comments

Comments
 (0)