From d38e2a918ba122bbf4d2ffa657c9364d5e69928a Mon Sep 17 00:00:00 2001 From: Elham Rababah Date: Wed, 11 Mar 2020 11:40:33 +0200 Subject: [PATCH] add calender to allow chose date from and to --- .../patients/patient_search_screen.dart | 51 +++++++++++++++++-- pubspec.lock | 35 +++---------- pubspec.yaml | 2 +- 3 files changed, 54 insertions(+), 34 deletions(-) diff --git a/lib/screens/patients/patient_search_screen.dart b/lib/screens/patients/patient_search_screen.dart index 3c8fb992..112028ac 100644 --- a/lib/screens/patients/patient_search_screen.dart +++ b/lib/screens/patients/patient_search_screen.dart @@ -1,9 +1,10 @@ +import 'package:intl/intl.dart'; + import '../../models/patient_model.dart'; import 'package:doctor_app_flutter/routes.dart'; import 'package:flutter/material.dart'; import 'package:hexcolor/hexcolor.dart'; - class PatientSearch extends StatefulWidget { @override _PatientSearchState createState() => _PatientSearchState(); @@ -25,6 +26,8 @@ class _PatientSearchState extends State { ]; String _selectedType = '1'; String _selectedLocation = '1'; + TextEditingController _toDateController = new TextEditingController(); + TextEditingController _fromDateController = new TextEditingController(); final _patientSearchForm = GlobalKey(); var _patientSearchFormValues = PatientModel( @@ -51,7 +54,11 @@ class _PatientSearchState extends State { void _saveForm() { _patientSearchForm.currentState.save(); + // Navigator.pushNamed(context,routeName) + print(_patientSearchFormValues.From); + print(_patientSearchFormValues.To); + Navigator.of(context).pushNamed(PATIENTS); } @@ -326,6 +333,7 @@ class _PatientSearchState extends State { height: 10, ), TextFormField( + keyboardType: TextInputType.number, decoration: InputDecoration( hintText: 'Patiant File', hintStyle: TextStyle( @@ -365,8 +373,10 @@ class _PatientSearchState extends State { height: 10, ), TextFormField( + keyboardType: TextInputType.number, + controller: _fromDateController, decoration: InputDecoration( - hintText: 'From', + hintText: '3/11/2020', hintStyle: TextStyle( fontSize: isSmallScreen ? 14 @@ -389,6 +399,9 @@ class _PatientSearchState extends State { } return null; }, + onTap: () { + _presentDatePicker('_selectedFromDate'); + }, onSaved: (value) { _patientSearchFormValues.From = value; }, @@ -404,8 +417,10 @@ class _PatientSearchState extends State { height: 10, ), TextFormField( + keyboardType: TextInputType.number, + controller: _toDateController, decoration: InputDecoration( - hintText: 'To', + hintText: '3/11/2020', hintStyle: TextStyle( fontSize: isSmallScreen ? 14 @@ -422,6 +437,9 @@ class _PatientSearchState extends State { ) //BorderRadius.all(Radius.circular(20)); ), + onTap: () { + _presentDatePicker('_selectedToDate'); + }, validator: (value) { if (value.isEmpty) { return 'Please enter some text'; @@ -474,7 +492,7 @@ class _PatientSearchState extends State { ), width: double.infinity, child: DropdownButton( - value: _selectedType, + value: _selectedLocation, iconSize: 24, elevation: 16, selectedItemBuilder: (BuildContext context) { @@ -484,7 +502,7 @@ class _PatientSearchState extends State { }, onChanged: (String newValue) => { setState(() { - _selectedType = newValue; + _selectedLocation = newValue; }) }, items: _locations.map((item) { @@ -539,4 +557,27 @@ class _PatientSearchState extends State { }), )); } + + void _presentDatePicker(id) { + showDatePicker( + context: context, + initialDate: DateTime.now(), + firstDate: DateTime(2019), + lastDate: DateTime.now(), + ).then((pickedDate) { + if (pickedDate == null) { + return; + } + setState(() { + print(id); + var selectedDate = DateFormat.yMd().format(pickedDate); + + if (id == '_selectedFromDate') { + _fromDateController.text = selectedDate; + } else { + _toDateController.text = selectedDate; + } + }); + }); + } } diff --git a/pubspec.lock b/pubspec.lock index a754683a..c2371589 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -113,13 +113,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.3.2" - built_mirrors: - dependency: transitive - description: - name: built_mirrors - url: "https://pub.dartlang.org" - source: hosted - version: "0.11.0" built_value: dependency: transitive description: @@ -190,13 +183,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.3.3" - dson: - dependency: "direct main" - description: - name: dson - url: "https://pub.dartlang.org" - source: hosted - version: "0.16.0" fixnum: dependency: transitive description: @@ -277,6 +263,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.1.4" + intl: + dependency: "direct main" + description: + name: intl + url: "https://pub.dartlang.org" + source: hosted + version: "0.16.1" io: dependency: transitive description: @@ -417,13 +410,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.4+2" - serializable: - dependency: transitive - description: - name: serializable - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.0" shelf: dependency: transitive description: @@ -443,13 +429,6 @@ packages: description: flutter source: sdk version: "0.0.99" - source_gen: - dependency: transitive - description: - name: source_gen - url: "https://pub.dartlang.org" - source: hosted - version: "0.9.5" source_maps: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index fc385d4a..aa4df3aa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -21,7 +21,7 @@ dependencies: sdk: flutter hexcolor: ^1.0.1 flutter_device_type: ^0.2.0 - dson: ^0.16.0 + intl: ^0.16.1 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^0.1.2