Skip to content

Commit a3f101f

Browse files
authored
Merge pull request #193 from les-crepes/156-remplacer-champ-birthday-dans-register
Add birthday field
2 parents 62f65ee + bc055d3 commit a3f101f

File tree

4 files changed

+31
-11
lines changed

4 files changed

+31
-11
lines changed

lib/screens/update_client_record.dart

+2
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,14 @@ class UpdateClientRecord extends StatelessWidget {
247247
name: "Start date",
248248
onSelected: _onSelectedStartDate,
249249
initialDate: _initialStartTime,
250+
icon: const Icon(Icons.date_range),
250251
),
251252
const SizedBox(height: 15.0),
252253
DatePicker(
253254
name: "End date",
254255
onSelected: _onSelectedEndDate,
255256
initialDate: _initialEndTime,
257+
icon: const Icon(Icons.date_range),
256258
),
257259
]),
258260
),

lib/widgets/forms/date_picker.dart

+12-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,24 @@ class DatePicker extends StatefulWidget {
66
final String _name;
77
final void Function(DateTime?)? _onSelected;
88
final DateTime? _initialDate;
9+
final Icon _icon;
10+
final DateTime? _firstDate;
11+
final DateTime? _lastDate;
912

1013
const DatePicker({
1114
required String name,
1215
void Function(DateTime?)? onSelected,
1316
DateTime? initialDate,
17+
required Icon icon,
18+
DateTime? firstDate,
19+
DateTime? lastDate,
1420
Key? key,
1521
}) : _name = name,
1622
_onSelected = onSelected,
1723
_initialDate = initialDate,
24+
_icon = icon,
25+
_firstDate = firstDate,
26+
_lastDate = lastDate,
1827
super(key: key);
1928

2029
@override
@@ -32,8 +41,8 @@ class _DatePickerState extends State<DatePicker> {
3241
DateTime? selected = await showDatePicker(
3342
context: context,
3443
initialDate: picked ?? widget._initialDate ?? DateTime.now(),
35-
firstDate: DateTime(2020, 01, 01),
36-
lastDate: DateTime(2050, 12, 31),
44+
firstDate: widget._firstDate ?? DateTime(2020, 01, 01),
45+
lastDate: widget._lastDate ?? DateTime(2050, 12, 31),
3746
);
3847
setState(() {
3948
picked = selected;
@@ -49,7 +58,7 @@ class _DatePickerState extends State<DatePicker> {
4958
: widget._initialDate != null
5059
? hourFormatter.format(widget._initialDate!)
5160
: widget._name,
52-
icon: const Icon(Icons.date_range),
61+
icon: widget._icon,
5362
enabled: false,
5463
),
5564
);

lib/widgets/register/register_second_page.dart

+13-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart';
22
import 'package:cross_file_image/cross_file_image.dart';
33
import 'package:flutter/material.dart';
44
import 'package:image_picker/image_picker.dart';
5+
import 'package:pdg_app/widgets/forms/date_picker.dart';
56
import 'package:provider/provider.dart';
67

78
import '../../provider/register_provider.dart';
@@ -21,6 +22,7 @@ class RegisterSecondPage extends StatelessWidget {
2122

2223
List<Widget> buildInputs(BuildContext context) {
2324
final registerProvider = context.watch<RegisterProvider>();
25+
2426
return [
2527
InkWell(
2628
onTap: () async {
@@ -59,10 +61,17 @@ class RegisterSecondPage extends StatelessWidget {
5961
controller: registerProvider.lastnameController,
6062
validator: validateString,
6163
),
62-
const MainTextField(
63-
name: 'Birthdate',
64-
icon: Icon(Icons.cake_outlined),
65-
keyboardType: TextInputType.datetime,
64+
DatePicker(
65+
name: "Birthday",
66+
icon: const Icon(Icons.cake_outlined),
67+
initialDate: registerProvider.birthDay,
68+
firstDate: DateTime(1920, 01, 01),
69+
lastDate: DateTime.now(),
70+
onSelected: (date) {
71+
if (date != null) {
72+
registerProvider.birthday = date;
73+
}
74+
},
6675
),
6776
Row(
6877
mainAxisAlignment: MainAxisAlignment.end,

pubspec.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ packages:
77
name: _fe_analyzer_shared
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "47.0.0"
10+
version: "46.0.0"
1111
analyzer:
1212
dependency: transitive
1313
description:
1414
name: analyzer
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "4.7.0"
17+
version: "4.6.0"
1818
args:
1919
dependency: transitive
2020
description:
@@ -729,7 +729,7 @@ packages:
729729
name: path_provider_windows
730730
url: "https://pub.dartlang.org"
731731
source: hosted
732-
version: "2.1.3"
732+
version: "2.1.2"
733733
petitparser:
734734
dependency: transitive
735735
description:
@@ -1028,7 +1028,7 @@ packages:
10281028
name: win32
10291029
url: "https://pub.dartlang.org"
10301030
source: hosted
1031-
version: "3.0.0"
1031+
version: "2.7.0"
10321032
xdg_directories:
10331033
dependency: transitive
10341034
description:

0 commit comments

Comments
 (0)