Better colorway, prettier features
parent
f83dedda4a
commit
7065e69241
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,4 @@
|
|||
#Tue Oct 29 18:01:57 CET 2024
|
||||
#Wed Oct 30 19:15:57 CET 2024
|
||||
base.0=/Users/user/Documents/Programmierung/CPD/cpd_2024_todo/build/app/intermediates/dex/debug/mergeExtDexDebug/classes.dex
|
||||
base.1=/Users/user/Documents/Programmierung/CPD/cpd_2024_todo/build/app/intermediates/dex/debug/mergeLibDexDebug/0/classes.dex
|
||||
base.2=/Users/user/Documents/Programmierung/CPD/cpd_2024_todo/build/app/intermediates/dex/debug/mergeProjectDexDebug/0/classes.dex
|
||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
|||
b1dbbd5f3120f7b6042aa8334edab1c8b68a8aa6
|
||||
c90f7e0c7d3bf85952cc2520d7b349a1d904dbe1
|
Binary file not shown.
|
@ -7257,6 +7257,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
--------------------------------------------------------------------------------
|
||||
flutter_lints
|
||||
path_provider
|
||||
path_provider_android
|
||||
path_provider_foundation
|
||||
path_provider_linux
|
||||
path_provider_platform_interface
|
||||
path_provider_windows
|
||||
|
@ -33605,6 +33608,39 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
--------------------------------------------------------------------------------
|
||||
sqflite
|
||||
sqflite_android
|
||||
sqflite_common
|
||||
sqflite_darwin
|
||||
sqflite_platform_interface
|
||||
|
||||
BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2019, Alexandre Roux Tekartik
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
sqlite
|
||||
|
||||
|
@ -33662,6 +33698,30 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
synchronized
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016, Alexandre Roux Tekartik.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
--------------------------------------------------------------------------------
|
||||
term_glyph
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ class ToDoItem {
|
|||
this.status = 'Pending',
|
||||
});
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id' : id,
|
||||
'name': name,
|
||||
|
@ -22,7 +22,7 @@ class ToDoItem {
|
|||
'status': status,
|
||||
};
|
||||
}
|
||||
static ToDoItem fromMap(Map<String, dynamic> json) {
|
||||
static ToDoItem fromJson(Map<String, dynamic> json) {
|
||||
return ToDoItem(
|
||||
id: json['id'],
|
||||
name: json['name'],
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:todo/database/PathProvider.dart';
|
||||
import 'package:todo/database/SharedPref.dart';
|
||||
import '../database/Sqlite.dart';
|
||||
import 'ToDoItem.dart';
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ class PathProvider implements DatabaseInterface {
|
|||
}
|
||||
Future<File> get _localFile async {
|
||||
final path = await _localPath;
|
||||
print(path);
|
||||
File file = File('$path/dataSeq.txt');
|
||||
if (!file.existsSync()) {
|
||||
file = await file.create();
|
||||
|
@ -24,9 +25,11 @@ class PathProvider implements DatabaseInterface {
|
|||
Future<List<ToDoItem>> getToDoItems() async {
|
||||
final file = await _localFile;
|
||||
final contents = await file.readAsString();
|
||||
List<dynamic> contentJson = jsonDecode(contents);
|
||||
final contentJson = jsonDecode(contents);
|
||||
|
||||
List<ToDoItem> toDoList = contentJson.map((item) => ToDoItem.fromMap(item)).toList();
|
||||
List<dynamic> contentList = contentJson is List ? contentJson : [contentJson];
|
||||
|
||||
List<ToDoItem> toDoList = contentList.map((item) => ToDoItem.fromJson(item)).toList();
|
||||
return toDoList;
|
||||
}
|
||||
|
||||
|
@ -36,21 +39,21 @@ class PathProvider implements DatabaseInterface {
|
|||
List<ToDoItem> l = await getToDoItems();
|
||||
l.add(item);
|
||||
final file = await _localFile;
|
||||
return file.writeAsString(jsonEncode(l.map((item) => item.toMap()).toList()));
|
||||
return file.writeAsString(jsonEncode(l.map((item) => item.toJson()).toList()));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<File> updateToDoItem(ToDoItem item) async {
|
||||
final file = await _localFile;
|
||||
return file.writeAsString(item.toMap() as String);
|
||||
return file.writeAsString(jsonEncode(item.toJson()));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<File> deleteToDoItem(int id) async {
|
||||
final file = await _localFile;
|
||||
List<ToDoItem> l = await getToDoItems();
|
||||
l.remove(l.where((item) => item.id == id).first);
|
||||
return file.writeAsString(jsonEncode(l.map((item) => item.toMap()).toList()));
|
||||
l.remove(l.firstWhere((item) => item.id == id));
|
||||
return file.writeAsString(jsonEncode(l.map((item) => item.toJson()).toList()));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
import 'dart:convert';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:todo/database/DatabaseInterface.dart';
|
||||
|
||||
import '../buisness/ToDoItem.dart';
|
||||
|
||||
class SharedPref implements DatabaseInterface {
|
||||
final todoKey = "todos";
|
||||
|
||||
Future<SharedPreferences> get _prefs async {
|
||||
SharedPreferences preferences = await SharedPreferences.getInstance();
|
||||
if (preferences.getString(todoKey) == null) {
|
||||
preferences.setString(todoKey, "[]");
|
||||
}
|
||||
return preferences;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ToDoItem> insertToDoItem(ToDoItem todo) async {
|
||||
SharedPreferences preferences = await _prefs;
|
||||
final String prefContent = preferences.getString(todoKey)!;
|
||||
|
||||
final List<dynamic> fileJson = jsonDecode(prefContent);
|
||||
|
||||
List<ToDoItem> todoList =
|
||||
fileJson.map((todo) => ToDoItem.fromJson(todo)).toList();
|
||||
|
||||
todo.id = DateTime.now().millisecondsSinceEpoch;
|
||||
todoList.add(todo);
|
||||
|
||||
preferences.setString(todoKey, jsonEncode(todoList));
|
||||
|
||||
return todo;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteToDoItem(int id) async {
|
||||
SharedPreferences preferences = await _prefs;
|
||||
final String prefContent = preferences.getString(todoKey)!;
|
||||
|
||||
final List<dynamic> fileJson = jsonDecode(prefContent);
|
||||
|
||||
List<ToDoItem> todoList =
|
||||
fileJson.map((todo) => ToDoItem.fromJson(todo)).toList();
|
||||
|
||||
todoList.removeWhere((todo) => todo.id == id);
|
||||
|
||||
preferences.setString(todoKey, jsonEncode(todoList));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<ToDoItem>> getToDoItems() async {
|
||||
SharedPreferences preferences = await _prefs;
|
||||
final String prefContent = preferences.getString(todoKey)!;
|
||||
|
||||
final List<dynamic> fileJson = jsonDecode(prefContent);
|
||||
|
||||
return fileJson.map((todo) => ToDoItem.fromJson(todo)).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateToDoItem(ToDoItem todo) async {
|
||||
SharedPreferences preferences = await _prefs;
|
||||
final String prefContent = preferences.getString(todoKey)!;
|
||||
|
||||
final List<dynamic> fileJson = jsonDecode(prefContent);
|
||||
|
||||
List<ToDoItem> todoList =
|
||||
fileJson.map((todo) => ToDoItem.fromJson(todo)).toList();
|
||||
|
||||
final todoToUpdate = todoList.firstWhere((t) => t.id == todo.id);
|
||||
final todoToUpdateIndex = todoList.indexOf(todoToUpdate);
|
||||
|
||||
todoToUpdate.name = todo.name;
|
||||
todoToUpdate.description = todo.description;
|
||||
todoToUpdate.status = todo.status;
|
||||
todoToUpdate.dueDate = todo.dueDate;
|
||||
|
||||
todoList.replaceRange(todoToUpdateIndex, todoToUpdateIndex, [todoToUpdate]);
|
||||
|
||||
preferences.setString(todoKey, jsonEncode(todoList));
|
||||
}
|
||||
}
|
|
@ -45,7 +45,7 @@ class Sqlite implements DatabaseInterface {
|
|||
final db = await database;
|
||||
final id = await db.insert(
|
||||
'todo_items',
|
||||
item.toMap(),
|
||||
item.toJson(),
|
||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||
);
|
||||
item.id = id;
|
||||
|
@ -57,7 +57,7 @@ class Sqlite implements DatabaseInterface {
|
|||
final List<Map<String, dynamic>> maps = await db.query('todo_items');
|
||||
|
||||
return List.generate(maps.length, (i) {
|
||||
return ToDoItem.fromMap(maps[i]);
|
||||
return ToDoItem.fromJson(maps[i]);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ class Sqlite implements DatabaseInterface {
|
|||
final db = await database;
|
||||
await db.update(
|
||||
'todo_items',
|
||||
item.toMap(),
|
||||
item.toJson(),
|
||||
where: 'id = ?',
|
||||
whereArgs: [item.id],
|
||||
);
|
||||
|
|
|
@ -10,7 +10,7 @@ class ToDoApp extends StatelessWidget {
|
|||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
primarySwatch: Colors.orange,
|
||||
hintColor: Colors.black,
|
||||
hintColor: Colors.white,
|
||||
),
|
||||
home: ToDoListScreen(),
|
||||
);
|
||||
|
|
|
@ -7,6 +7,17 @@ class ToDoExpandableWidget extends StatelessWidget {
|
|||
final ToDoItem toDoItem;
|
||||
final int id;
|
||||
|
||||
getStatusColor(String status) {
|
||||
switch(status) {
|
||||
case 'Pending':
|
||||
return Colors.blueGrey;
|
||||
case 'In Progress':
|
||||
return Colors.lime;
|
||||
case 'Completed':
|
||||
return Colors.green;
|
||||
}
|
||||
}
|
||||
|
||||
const ToDoExpandableWidget({
|
||||
super.key,
|
||||
required this.toDoItem,
|
||||
|
@ -16,7 +27,9 @@ class ToDoExpandableWidget extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Card(
|
||||
color: Colors.orange[100],
|
||||
color: getStatusColor(toDoItem.status),
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
|
||||
child: ExpansionTile(
|
||||
title: Text(toDoItem.name, style: const TextStyle(color: Colors.black)),
|
||||
subtitle: Text('Due: ${toDoItem.dueDate.toLocal()}'),
|
||||
|
@ -26,36 +39,46 @@ class ToDoExpandableWidget extends StatelessWidget {
|
|||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Description: ${toDoItem.description}', style: const TextStyle(color: Colors.black)),
|
||||
Text(toDoItem.description, style: const TextStyle(color: Colors.black)),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ElevatedButton.icon(
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
Provider.of<ToDoProvider>(context, listen: false).deleteItem(toDoItem.id!);
|
||||
},
|
||||
icon: const Icon(Icons.delete),
|
||||
label: const Text("Delete"),
|
||||
style: ElevatedButton.styleFrom(
|
||||
foregroundColor: const Color(0xFFBB0000),
|
||||
backgroundColor: getStatusColor(toDoItem.status),
|
||||
textStyle: const TextStyle(fontSize: 15),
|
||||
iconColor: const Color(0xFFFF0000),
|
||||
iconColor: const Color(0xFFBB0000),
|
||||
),
|
||||
),
|
||||
const Text('Status: ', style: TextStyle(color: Colors.black)),
|
||||
DropdownButton<String>(
|
||||
value: toDoItem.status,
|
||||
items: ['Pending', 'In Progress', 'Completed']
|
||||
.map((status) => DropdownMenuItem(
|
||||
value: status,
|
||||
child: Text(status),
|
||||
))
|
||||
.toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
Provider.of<ToDoProvider>(context, listen: false).updateStatus(id, value);
|
||||
}
|
||||
},
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: getStatusColor(toDoItem.status),
|
||||
borderRadius: BorderRadius.circular(20.0),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: DropdownButton<String>(
|
||||
value: toDoItem.status,
|
||||
items: ['Pending', 'In Progress', 'Completed']
|
||||
.map((status) => DropdownMenuItem(
|
||||
value: status,
|
||||
child: Text(status),
|
||||
))
|
||||
.toList(),
|
||||
dropdownColor: getStatusColor(toDoItem.status),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
Provider.of<ToDoProvider>(context, listen: false).updateStatus(id, value);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
@ -10,19 +10,25 @@ class ToDoListScreen extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.grey[900],
|
||||
appBar: AppBar(
|
||||
title: Text('To-Do List'),
|
||||
backgroundColor: Colors.deepOrange[800],
|
||||
title: const Text('To-Do List'),
|
||||
titleSpacing: 150.0,
|
||||
),
|
||||
body: Consumer<ToDoProvider>(
|
||||
builder: (context, toDoProvider, child) {
|
||||
return ListView(
|
||||
children: toDoProvider.toDoList.map((todo) {
|
||||
return ToDoExpandableWidget(
|
||||
toDoItem: todo,
|
||||
id: todo.id!,
|
||||
);
|
||||
},
|
||||
).toList()
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: ListView(
|
||||
children: toDoProvider.toDoList.map((todo) {
|
||||
return ToDoExpandableWidget(
|
||||
toDoItem: todo,
|
||||
id: todo.id!,
|
||||
);
|
||||
},
|
||||
).toList()
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
|
@ -37,12 +43,12 @@ class ToDoListScreen extends StatelessWidget {
|
|||
onPressed: () => _showSortOptions(context),
|
||||
backgroundColor: Colors.orange,
|
||||
heroTag: null,
|
||||
child: Icon(Icons.sort), // Damit beide Floating Buttons keine Konflikte haben
|
||||
child: const Icon(Icons.sort), // Damit beide Floating Buttons keine Konflikte haben
|
||||
),
|
||||
// Hinzufügen-Button unten rechts
|
||||
FloatingActionButton(
|
||||
onPressed: () => _showAddToDoDialog(context),
|
||||
child: Icon(Icons.add),
|
||||
child: const Icon(Icons.add),
|
||||
backgroundColor: Colors.orange,
|
||||
heroTag: null, // Damit beide Floating Buttons keine Konflikte haben
|
||||
),
|
||||
|
@ -55,29 +61,30 @@ class ToDoListScreen extends StatelessWidget {
|
|||
// Sortier-Menü anzeigen
|
||||
void _showSortOptions(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
backgroundColor: Colors.orange,
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return Wrap(
|
||||
children: [
|
||||
ListTile(
|
||||
leading: Icon(Icons.text_fields),
|
||||
title: Text('Sort by Name'),
|
||||
leading: const Icon(Icons.text_fields),
|
||||
title: const Text('Sort by Name'),
|
||||
onTap: () {
|
||||
Provider.of<ToDoProvider>(context, listen: false).sortByName();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.date_range),
|
||||
title: Text('Sort by Due Date'),
|
||||
leading: const Icon(Icons.date_range),
|
||||
title: const Text('Sort by Due Date'),
|
||||
onTap: () {
|
||||
Provider.of<ToDoProvider>(context, listen: false).sortByDueDate();
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
leading: Icon(Icons.flag),
|
||||
title: Text('Sort by Status'),
|
||||
leading: const Icon(Icons.flag),
|
||||
title: const Text('Sort by Status'),
|
||||
onTap: () {
|
||||
Provider.of<ToDoProvider>(context, listen: false).sortByStatus();
|
||||
Navigator.pop(context);
|
||||
|
@ -99,56 +106,91 @@ class ToDoListScreen extends StatelessWidget {
|
|||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: Text('Add To-Do'),
|
||||
backgroundColor: Colors.grey[700],
|
||||
insetPadding: EdgeInsets.zero,
|
||||
title: const Text('Add To-Do'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
decoration: InputDecoration(labelText: 'Name'),
|
||||
onChanged: (value) {
|
||||
name = value;
|
||||
},
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8.0),
|
||||
child: TextField(
|
||||
decoration: const InputDecoration(labelText: 'Name', filled: true),
|
||||
onChanged: (value) {
|
||||
name = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
decoration: InputDecoration(labelText: 'Description'),
|
||||
decoration: const InputDecoration(labelText: 'Description', filled: true),
|
||||
onChanged: (value) {
|
||||
description = value;
|
||||
},
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: DateTime.now(),
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: DateTime(2101),
|
||||
);
|
||||
if (picked != null) dueDate = picked;
|
||||
},
|
||||
child: Text('Pick Due Date'),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 16.0),
|
||||
child: ElevatedButton(
|
||||
style: const ButtonStyle(
|
||||
backgroundColor: WidgetStatePropertyAll<Color>(Colors.orange),
|
||||
),
|
||||
onPressed: () async {
|
||||
DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: DateTime.now(),
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: DateTime(2101),
|
||||
);
|
||||
if (picked != null) dueDate = picked;
|
||||
},
|
||||
child: const Text('Pick Due Date'),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text('Cancel'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (name.isNotEmpty && description.isNotEmpty && dueDate != null) {
|
||||
final newToDo = ToDoItem(
|
||||
name: name,
|
||||
description: description,
|
||||
dueDate: dueDate!,
|
||||
);
|
||||
Provider.of<ToDoProvider>(context, listen: false).addToDo(newToDo);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
child: Text('Add'),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextButton(
|
||||
style: const ButtonStyle(
|
||||
backgroundColor: WidgetStatePropertyAll<Color>(Colors.red),
|
||||
),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 16,
|
||||
),
|
||||
Expanded(
|
||||
child: ElevatedButton(
|
||||
style: const ButtonStyle(
|
||||
backgroundColor: WidgetStatePropertyAll<Color>(Colors.green),
|
||||
),
|
||||
onPressed: () {
|
||||
if (name.isNotEmpty && description.isNotEmpty && dueDate != null) {
|
||||
final newToDo = ToDoItem(
|
||||
name: name,
|
||||
description: description,
|
||||
dueDate: dueDate!,
|
||||
);
|
||||
Provider.of<ToDoProvider>(context, listen: false).addToDo(newToDo);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
},
|
||||
child: const Text('Add'),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue