Skip to content

Commit

Permalink
Merge pull request #193 from les-crepes/156-remplacer-champ-birthday-…
Browse files Browse the repository at this point in the history
…dans-register

Add birthday field
  • Loading branch information
LucaCoduriV authored Sep 6, 2022
2 parents 62f65ee + bc055d3 commit a3f101f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
2 changes: 2 additions & 0 deletions lib/screens/update_client_record.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,14 @@ class UpdateClientRecord extends StatelessWidget {
name: "Start date",
onSelected: _onSelectedStartDate,
initialDate: _initialStartTime,
icon: const Icon(Icons.date_range),
),
const SizedBox(height: 15.0),
DatePicker(
name: "End date",
onSelected: _onSelectedEndDate,
initialDate: _initialEndTime,
icon: const Icon(Icons.date_range),
),
]),
),
Expand Down
15 changes: 12 additions & 3 deletions lib/widgets/forms/date_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,24 @@ class DatePicker extends StatefulWidget {
final String _name;
final void Function(DateTime?)? _onSelected;
final DateTime? _initialDate;
final Icon _icon;
final DateTime? _firstDate;
final DateTime? _lastDate;

const DatePicker({
required String name,
void Function(DateTime?)? onSelected,
DateTime? initialDate,
required Icon icon,
DateTime? firstDate,
DateTime? lastDate,
Key? key,
}) : _name = name,
_onSelected = onSelected,
_initialDate = initialDate,
_icon = icon,
_firstDate = firstDate,
_lastDate = lastDate,
super(key: key);

@override
Expand All @@ -32,8 +41,8 @@ class _DatePickerState extends State<DatePicker> {
DateTime? selected = await showDatePicker(
context: context,
initialDate: picked ?? widget._initialDate ?? DateTime.now(),
firstDate: DateTime(2020, 01, 01),
lastDate: DateTime(2050, 12, 31),
firstDate: widget._firstDate ?? DateTime(2020, 01, 01),
lastDate: widget._lastDate ?? DateTime(2050, 12, 31),
);
setState(() {
picked = selected;
Expand All @@ -49,7 +58,7 @@ class _DatePickerState extends State<DatePicker> {
: widget._initialDate != null
? hourFormatter.format(widget._initialDate!)
: widget._name,
icon: const Icon(Icons.date_range),
icon: widget._icon,
enabled: false,
),
);
Expand Down
17 changes: 13 additions & 4 deletions lib/widgets/register/register_second_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:auto_route/auto_route.dart';
import 'package:cross_file_image/cross_file_image.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:pdg_app/widgets/forms/date_picker.dart';
import 'package:provider/provider.dart';

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

List<Widget> buildInputs(BuildContext context) {
final registerProvider = context.watch<RegisterProvider>();

return [
InkWell(
onTap: () async {
Expand Down Expand Up @@ -59,10 +61,17 @@ class RegisterSecondPage extends StatelessWidget {
controller: registerProvider.lastnameController,
validator: validateString,
),
const MainTextField(
name: 'Birthdate',
icon: Icon(Icons.cake_outlined),
keyboardType: TextInputType.datetime,
DatePicker(
name: "Birthday",
icon: const Icon(Icons.cake_outlined),
initialDate: registerProvider.birthDay,
firstDate: DateTime(1920, 01, 01),
lastDate: DateTime.now(),
onSelected: (date) {
if (date != null) {
registerProvider.birthday = date;
}
},
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
Expand Down
8 changes: 4 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ packages:
name: _fe_analyzer_shared
url: "https://pub.dartlang.org"
source: hosted
version: "47.0.0"
version: "46.0.0"
analyzer:
dependency: transitive
description:
name: analyzer
url: "https://pub.dartlang.org"
source: hosted
version: "4.7.0"
version: "4.6.0"
args:
dependency: transitive
description:
Expand Down Expand Up @@ -729,7 +729,7 @@ packages:
name: path_provider_windows
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
version: "2.1.2"
petitparser:
dependency: transitive
description:
Expand Down Expand Up @@ -1028,7 +1028,7 @@ packages:
name: win32
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.0"
version: "2.7.0"
xdg_directories:
dependency: transitive
description:
Expand Down

0 comments on commit a3f101f

Please sign in to comment.