You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
doctor_app_flutter/lib/widgets/patients/dynamic_elements.dart

127 lines
4.2 KiB
Dart

import 'package:doctor_app_flutter/models/patient_model.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:intl/intl.dart';
class DynamicElements extends StatefulWidget {
PatientModel _patientSearchFormValues;
DynamicElements(this._patientSearchFormValues);
@override
_DynamicElementsState createState() => _DynamicElementsState();
}
class _DynamicElementsState extends State<DynamicElements> {
TextEditingController _toDateController = new TextEditingController();
TextEditingController _fromDateController = new TextEditingController();
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;
}
});
});
}
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (ctx, constraints) {
var smallScreenSize = 660;
bool isSmallScreen = constraints.maxWidth <= smallScreenSize;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 10,
),
TextFormField(
keyboardType: TextInputType.number,
controller: _fromDateController,
decoration: InputDecoration(
hintText: 'From',
hintStyle: TextStyle(
fontSize:
isSmallScreen ? 14 : constraints.maxWidth * 0.024),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(30)),
borderSide: BorderSide(color: Color(0xff707070)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(30.0)),
borderSide:
BorderSide(color: Theme.of(context).primaryColor),
)
//BorderRadius.all(Radius.circular(20));
),
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
onTap: () {
_presentDatePicker('_selectedFromDate');
},
onSaved: (value) {
widget._patientSearchFormValues.From = value;
},
),
SizedBox(
height: 10,
),
TextFormField(
keyboardType: TextInputType.number,
controller: _toDateController,
decoration: InputDecoration(
hintText: 'TO',
hintStyle: TextStyle(
fontSize:
isSmallScreen ? 14 : constraints.maxWidth * 0.024),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(30)),
borderSide: BorderSide(color: Color(0xff707070)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(30.0)),
borderSide:
BorderSide(color: Theme.of(context).primaryColor),
)
//BorderRadius.all(Radius.circular(20));
),
onTap: () {
_presentDatePicker('_selectedToDate');
},
validator: (value) {
if (value.isEmpty) {
return 'Please enter some text';
}
return null;
},
onSaved: (value) {
widget._patientSearchFormValues.To = value;
},
),
],
);
},
);
}
}