add a time input field
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:patient_manager/main.dart';
|
import 'package:patient_manager/main.dart';
|
||||||
|
|
||||||
class MIHDateField extends StatefulWidget {
|
class MIHTimeField extends StatefulWidget {
|
||||||
final controller;
|
final controller;
|
||||||
final String LableText;
|
final String LableText;
|
||||||
final bool required;
|
final bool required;
|
||||||
|
|
||||||
const MIHDateField({
|
const MIHTimeField({
|
||||||
super.key,
|
super.key,
|
||||||
required this.controller,
|
required this.controller,
|
||||||
required this.LableText,
|
required this.LableText,
|
||||||
@@ -14,23 +14,41 @@ class MIHDateField extends StatefulWidget {
|
|||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<MIHDateField> createState() => _MIHDateFieldState();
|
State<MIHTimeField> createState() => _MIHDateFieldState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _MIHDateFieldState extends State<MIHDateField> {
|
class _MIHDateFieldState extends State<MIHTimeField> {
|
||||||
FocusNode _focus = FocusNode();
|
FocusNode _focus = FocusNode();
|
||||||
bool startup = true;
|
bool startup = true;
|
||||||
// bool makeEditable() {
|
|
||||||
Future<void> _selectDate(BuildContext context) async {
|
Future<void> _selectTime(BuildContext context) async {
|
||||||
DateTime? picked = await showDatePicker(
|
TimeOfDay? picked = await showTimePicker(
|
||||||
context: context,
|
context: context,
|
||||||
initialDate: DateTime.now(),
|
initialTime: TimeOfDay.now(),
|
||||||
firstDate: DateTime(2000),
|
builder: (context, child) {
|
||||||
lastDate: DateTime(2100),
|
return MediaQuery(
|
||||||
|
data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: true),
|
||||||
|
child: child as Widget,
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
if (picked != null) {
|
if (picked != null) {
|
||||||
|
String hours = "";
|
||||||
|
String minutes = "";
|
||||||
setState(() {
|
setState(() {
|
||||||
widget.controller.text = picked.toString().split(" ")[0];
|
if (picked.hour <= 9) {
|
||||||
|
hours = "0${picked.hour}";
|
||||||
|
} else {
|
||||||
|
hours = "${picked.hour}";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (picked.minute <= 9) {
|
||||||
|
minutes = "0${picked.minute}";
|
||||||
|
} else {
|
||||||
|
minutes = "${picked.minute}";
|
||||||
|
}
|
||||||
|
|
||||||
|
widget.controller.text = "$hours:$minutes";
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,7 +126,7 @@ class _MIHDateFieldState extends State<MIHDateField> {
|
|||||||
//labelText: widget.LableText,
|
//labelText: widget.LableText,
|
||||||
//labelStyle: const TextStyle(color: Colors.blueAccent),
|
//labelStyle: const TextStyle(color: Colors.blueAccent),
|
||||||
prefixIcon: Icon(
|
prefixIcon: Icon(
|
||||||
Icons.calendar_today,
|
Icons.access_alarm,
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
),
|
),
|
||||||
fillColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
fillColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
@@ -139,7 +157,7 @@ class _MIHDateFieldState extends State<MIHDateField> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_selectDate(context);
|
_selectTime(context);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user