add calender to allow chose date from and to

merge-requests/1/merge
Elham Rababah 6 years ago
parent ed2f0ebcf8
commit d38e2a918b

@ -1,9 +1,10 @@
import 'package:intl/intl.dart';
import '../../models/patient_model.dart'; import '../../models/patient_model.dart';
import 'package:doctor_app_flutter/routes.dart'; import 'package:doctor_app_flutter/routes.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart'; import 'package:hexcolor/hexcolor.dart';
class PatientSearch extends StatefulWidget { class PatientSearch extends StatefulWidget {
@override @override
_PatientSearchState createState() => _PatientSearchState(); _PatientSearchState createState() => _PatientSearchState();
@ -25,6 +26,8 @@ class _PatientSearchState extends State<PatientSearch> {
]; ];
String _selectedType = '1'; String _selectedType = '1';
String _selectedLocation = '1'; String _selectedLocation = '1';
TextEditingController _toDateController = new TextEditingController();
TextEditingController _fromDateController = new TextEditingController();
final _patientSearchForm = GlobalKey<FormState>(); final _patientSearchForm = GlobalKey<FormState>();
var _patientSearchFormValues = PatientModel( var _patientSearchFormValues = PatientModel(
@ -51,7 +54,11 @@ class _PatientSearchState extends State<PatientSearch> {
void _saveForm() { void _saveForm() {
_patientSearchForm.currentState.save(); _patientSearchForm.currentState.save();
// Navigator.pushNamed(context,routeName) // Navigator.pushNamed(context,routeName)
print(_patientSearchFormValues.From);
print(_patientSearchFormValues.To);
Navigator.of(context).pushNamed(PATIENTS); Navigator.of(context).pushNamed(PATIENTS);
} }
@ -326,6 +333,7 @@ class _PatientSearchState extends State<PatientSearch> {
height: 10, height: 10,
), ),
TextFormField( TextFormField(
keyboardType: TextInputType.number,
decoration: InputDecoration( decoration: InputDecoration(
hintText: 'Patiant File', hintText: 'Patiant File',
hintStyle: TextStyle( hintStyle: TextStyle(
@ -365,8 +373,10 @@ class _PatientSearchState extends State<PatientSearch> {
height: 10, height: 10,
), ),
TextFormField( TextFormField(
keyboardType: TextInputType.number,
controller: _fromDateController,
decoration: InputDecoration( decoration: InputDecoration(
hintText: 'From', hintText: '3/11/2020',
hintStyle: TextStyle( hintStyle: TextStyle(
fontSize: isSmallScreen fontSize: isSmallScreen
? 14 ? 14
@ -389,6 +399,9 @@ class _PatientSearchState extends State<PatientSearch> {
} }
return null; return null;
}, },
onTap: () {
_presentDatePicker('_selectedFromDate');
},
onSaved: (value) { onSaved: (value) {
_patientSearchFormValues.From = value; _patientSearchFormValues.From = value;
}, },
@ -404,8 +417,10 @@ class _PatientSearchState extends State<PatientSearch> {
height: 10, height: 10,
), ),
TextFormField( TextFormField(
keyboardType: TextInputType.number,
controller: _toDateController,
decoration: InputDecoration( decoration: InputDecoration(
hintText: 'To', hintText: '3/11/2020',
hintStyle: TextStyle( hintStyle: TextStyle(
fontSize: isSmallScreen fontSize: isSmallScreen
? 14 ? 14
@ -422,6 +437,9 @@ class _PatientSearchState extends State<PatientSearch> {
) )
//BorderRadius.all(Radius.circular(20)); //BorderRadius.all(Radius.circular(20));
), ),
onTap: () {
_presentDatePicker('_selectedToDate');
},
validator: (value) { validator: (value) {
if (value.isEmpty) { if (value.isEmpty) {
return 'Please enter some text'; return 'Please enter some text';
@ -474,7 +492,7 @@ class _PatientSearchState extends State<PatientSearch> {
), ),
width: double.infinity, width: double.infinity,
child: DropdownButton( child: DropdownButton(
value: _selectedType, value: _selectedLocation,
iconSize: 24, iconSize: 24,
elevation: 16, elevation: 16,
selectedItemBuilder: (BuildContext context) { selectedItemBuilder: (BuildContext context) {
@ -484,7 +502,7 @@ class _PatientSearchState extends State<PatientSearch> {
}, },
onChanged: (String newValue) => { onChanged: (String newValue) => {
setState(() { setState(() {
_selectedType = newValue; _selectedLocation = newValue;
}) })
}, },
items: _locations.map((item) { items: _locations.map((item) {
@ -539,4 +557,27 @@ class _PatientSearchState extends State<PatientSearch> {
}), }),
)); ));
} }
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;
}
});
});
}
} }

@ -113,13 +113,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.3.2" 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: built_value:
dependency: transitive dependency: transitive
description: description:
@ -190,13 +183,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.3.3" version: "1.3.3"
dson:
dependency: "direct main"
description:
name: dson
url: "https://pub.dartlang.org"
source: hosted
version: "0.16.0"
fixnum: fixnum:
dependency: transitive dependency: transitive
description: description:
@ -277,6 +263,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "2.1.4" version: "2.1.4"
intl:
dependency: "direct main"
description:
name: intl
url: "https://pub.dartlang.org"
source: hosted
version: "0.16.1"
io: io:
dependency: transitive dependency: transitive
description: description:
@ -417,13 +410,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.0.4+2" version: "0.0.4+2"
serializable:
dependency: transitive
description:
name: serializable
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.0"
shelf: shelf:
dependency: transitive dependency: transitive
description: description:
@ -443,13 +429,6 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.99" 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: source_maps:
dependency: transitive dependency: transitive
description: description:

@ -21,7 +21,7 @@ dependencies:
sdk: flutter sdk: flutter
hexcolor: ^1.0.1 hexcolor: ^1.0.1
flutter_device_type: ^0.2.0 flutter_device_type: ^0.2.0
dson: ^0.16.0 intl: ^0.16.1
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2 cupertino_icons: ^0.1.2

Loading…
Cancel
Save