Time
This commit is contained in:
+101
-39
@@ -1,57 +1,119 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:todoapp/elems/todo.dart';
|
||||
import 'package:todoapp/modals/datepickermodal.dart';
|
||||
import 'package:todoapp/modals/timepickermodal.dart';
|
||||
import 'package:todoapp/providers/todoprovider.dart';
|
||||
|
||||
class AddTodoModal {
|
||||
static String tempValue = "";
|
||||
|
||||
static void add(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
showDragHandle: true,
|
||||
useSafeArea: true,
|
||||
scrollControlDisabledMaxHeightRatio: 1,
|
||||
builder: (context) => Padding(
|
||||
padding: const EdgeInsets.only(left: 30, right: 30),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(labelText: "Title"),
|
||||
onChanged: (value) => tempValue = value,
|
||||
onFieldSubmitted: (value) {
|
||||
context.read<TodoProvider>().addTodo(value);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
builder: (context) => const ModalCreateTodo(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ModalCreateTodo extends StatefulWidget {
|
||||
const ModalCreateTodo({super.key});
|
||||
|
||||
@override
|
||||
State<ModalCreateTodo> createState() => _ModalCreateTodoState();
|
||||
}
|
||||
|
||||
class _ModalCreateTodoState extends State<ModalCreateTodo> {
|
||||
String tempValue = "";
|
||||
DateTime tempDateSelect = DateTime.now();
|
||||
TimeOfDay tempTimeSelect = TimeOfDay.now();
|
||||
|
||||
String formatNumber(int number) {
|
||||
if (number < 10) {
|
||||
return "0$number";
|
||||
}
|
||||
return number.toString();
|
||||
}
|
||||
|
||||
DateTime combineTime() {
|
||||
return DateTime(tempDateSelect.year, tempDateSelect.month,
|
||||
tempDateSelect.day, tempTimeSelect.hour, tempTimeSelect.minute);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 30, right: 30),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(labelText: "Title"),
|
||||
onChanged: (value) => tempValue = value,
|
||||
onFieldSubmitted: (value) {
|
||||
context.read<TodoProvider>().addTodo(value, combineTime());
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
FilledButton.tonal(
|
||||
onPressed: () async {
|
||||
tempDateSelect =
|
||||
(await DatePickerModal.add(context, tempDateSelect))!;
|
||||
setState(() {});
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(Icons.date_range),
|
||||
const SizedBox(width: 20),
|
||||
Text(
|
||||
"${tempDateSelect.year}-${formatNumber(tempDateSelect.month)}-${formatNumber(tempDateSelect.day)}")
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20,),
|
||||
SegmentedButton(
|
||||
segments: const [
|
||||
ButtonSegment(
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
FilledButton.tonal(
|
||||
onPressed: () async {
|
||||
tempTimeSelect =
|
||||
(await TimePickerModal.add(context, tempTimeSelect))!;
|
||||
setState(() {});
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(Icons.timer),
|
||||
const SizedBox(width: 20),
|
||||
Text(
|
||||
"${formatNumber(tempTimeSelect.hour)}:${formatNumber(tempTimeSelect.minute)}")
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
SegmentedButton(
|
||||
segments: const [
|
||||
ButtonSegment(
|
||||
value: "Cancel",
|
||||
label: Text("Cancel"),
|
||||
icon: Icon(Icons.cancel)
|
||||
),
|
||||
ButtonSegment(
|
||||
value: "Save",
|
||||
label: Text("Save"),
|
||||
icon: Icon(Icons.save)
|
||||
),
|
||||
],
|
||||
selected: const {"None"},
|
||||
style: ButtonStyle(iconColor: WidgetStatePropertyAll(Theme.of(context).colorScheme.primary)),
|
||||
onSelectionChanged: (p0) {
|
||||
if (p0.last == "Save") {
|
||||
context.read<TodoProvider>().addTodo(tempValue);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
icon: Icon(Icons.cancel)),
|
||||
ButtonSegment(
|
||||
value: "Save", label: Text("Save"), icon: Icon(Icons.save)),
|
||||
],
|
||||
selected: const {"None"},
|
||||
style: ButtonStyle(
|
||||
iconColor: WidgetStatePropertyAll(
|
||||
Theme.of(context).colorScheme.primary)),
|
||||
onSelectionChanged: (p0) {
|
||||
if (p0.last == "Save") {
|
||||
context.read<TodoProvider>().addTodo(tempValue, combineTime());
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class DatePickerModal {
|
||||
static Future<DateTime?> add(BuildContext context, DateTime initial) async {
|
||||
DateTime? selected = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: initial,
|
||||
firstDate: DateTime.now(),
|
||||
lastDate: DateTime(DateTime.now().year+10, 12, 31),
|
||||
);
|
||||
return selected;
|
||||
}
|
||||
}
|
||||
+127
-50
@@ -1,65 +1,142 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:todoapp/elems/todo.dart';
|
||||
import 'package:todoapp/modals/datepickermodal.dart';
|
||||
import 'package:todoapp/modals/timepickermodal.dart';
|
||||
import 'package:todoapp/providers/todoprovider.dart';
|
||||
|
||||
class EditTodoModal {
|
||||
static String tempValue = "";
|
||||
|
||||
static void add(BuildContext context, String title) {
|
||||
static void add(BuildContext context, String title, DateTime dueTime) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
showDragHandle: true,
|
||||
useSafeArea: true,
|
||||
scrollControlDisabledMaxHeightRatio: 1,
|
||||
builder: (context) => Padding(
|
||||
padding: const EdgeInsets.only(left: 30, right: 30),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
initialValue: title,
|
||||
decoration: const InputDecoration(labelText: "Title"),
|
||||
onChanged: (value) => tempValue = value,
|
||||
onFieldSubmitted: (value) {
|
||||
context.read<TodoProvider>().updateTodo(title, value);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20,),
|
||||
SegmentedButton(
|
||||
segments: const [
|
||||
ButtonSegment(
|
||||
value: "Delete",
|
||||
label: Text("Delete"),
|
||||
icon: Icon(Icons.delete)
|
||||
),
|
||||
ButtonSegment(
|
||||
value: "Cancel",
|
||||
label: Text("Cancel"),
|
||||
icon: Icon(Icons.cancel)
|
||||
),
|
||||
ButtonSegment(
|
||||
value: "Save",
|
||||
label: Text("Save"),
|
||||
icon: Icon(Icons.save)
|
||||
),
|
||||
builder: (context) => ModalEditTodo(
|
||||
oldValue: title,
|
||||
initDate: DateTime(dueTime.year, dueTime.month, dueTime.day),
|
||||
initTime: TimeOfDay(hour: dueTime.hour, minute: dueTime.minute)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ModalEditTodo extends StatefulWidget {
|
||||
const ModalEditTodo(
|
||||
{super.key,
|
||||
required this.oldValue,
|
||||
required this.initDate,
|
||||
required this.initTime});
|
||||
|
||||
final String oldValue;
|
||||
final DateTime initDate;
|
||||
final TimeOfDay initTime;
|
||||
|
||||
@override
|
||||
State<ModalEditTodo> createState() => _ModalEditTodoState();
|
||||
}
|
||||
|
||||
class _ModalEditTodoState extends State<ModalEditTodo> {
|
||||
String tempValue = "";
|
||||
TimeOfDay tempTimeSelect = TimeOfDay.now();
|
||||
DateTime tempDateSelect = DateTime.now();
|
||||
|
||||
String formatNumber(int number) {
|
||||
if (number < 10) {
|
||||
return "0$number";
|
||||
}
|
||||
return number.toString();
|
||||
}
|
||||
|
||||
DateTime combineTime() {
|
||||
return DateTime(tempDateSelect.year, tempDateSelect.month,
|
||||
tempDateSelect.day, tempTimeSelect.hour, tempTimeSelect.minute);
|
||||
}
|
||||
|
||||
bool firstBuild = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (firstBuild) {
|
||||
tempValue = widget.oldValue;
|
||||
tempDateSelect = widget.initDate;
|
||||
tempTimeSelect = widget.initTime;
|
||||
firstBuild = false;
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(left: 30, right: 30),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextFormField(
|
||||
autofocus: true,
|
||||
initialValue: widget.oldValue,
|
||||
decoration: const InputDecoration(labelText: "Title"),
|
||||
onChanged: (value) => tempValue = value,
|
||||
onFieldSubmitted: (value) {
|
||||
context.read<TodoProvider>().updateTodo(widget.oldValue, value, combineTime());
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
FilledButton.tonal(
|
||||
onPressed: () async {
|
||||
tempDateSelect =
|
||||
(await DatePickerModal.add(context, tempDateSelect))!;
|
||||
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||
print(tempDateSelect);
|
||||
setState(() {});
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(Icons.date_range),
|
||||
const SizedBox(width: 20),
|
||||
Text(
|
||||
"${tempDateSelect.year}-${formatNumber(tempDateSelect.month)}-${formatNumber(tempDateSelect.day)}")
|
||||
],
|
||||
selected: const {"None"},
|
||||
style: ButtonStyle(iconColor: WidgetStatePropertyAll(Theme.of(context).colorScheme.primary)),
|
||||
onSelectionChanged: (p0) {
|
||||
if (p0.last == "Save") {
|
||||
context.read<TodoProvider>().updateTodo(title, tempValue);
|
||||
} else if (p0.last == "Delete") {
|
||||
context.read<TodoProvider>().removeTodo(title);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
FilledButton.tonal(
|
||||
onPressed: () async {
|
||||
tempTimeSelect =
|
||||
(await TimePickerModal.add(context, tempTimeSelect))!;
|
||||
setState(() {});
|
||||
},
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
const Icon(Icons.timer),
|
||||
const SizedBox(width: 20),
|
||||
Text(
|
||||
"${formatNumber(tempTimeSelect.hour)}:${formatNumber(tempTimeSelect.minute)}")
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
SegmentedButton(
|
||||
segments: const [
|
||||
ButtonSegment(
|
||||
value: "Cancel",
|
||||
label: Text("Cancel"),
|
||||
icon: Icon(Icons.cancel)),
|
||||
ButtonSegment(
|
||||
value: "Save", label: Text("Save"), icon: Icon(Icons.save)),
|
||||
],
|
||||
selected: const {"None"},
|
||||
style: ButtonStyle(
|
||||
iconColor: WidgetStatePropertyAll(
|
||||
Theme.of(context).colorScheme.primary)),
|
||||
onSelectionChanged: (p0) {
|
||||
if (p0.last == "Save") {
|
||||
context.read<TodoProvider>().updateTodo(widget.oldValue, tempValue, combineTime());
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class TimePickerModal {
|
||||
static Future<TimeOfDay?> add(BuildContext context, TimeOfDay initial) async {
|
||||
TimeOfDay? timeSelect = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: initial,
|
||||
);
|
||||
|
||||
return timeSelect;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user