57 lines
1.8 KiB
Dart
57 lines
1.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:todoapp/elems/todo.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);
|
|
},
|
|
),
|
|
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);
|
|
},
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |