- séparation des taches faite et non,

- rapettisage de la taille des taches
This commit is contained in:
2023-10-10 20:20:27 +02:00
parent 979fcfa2a1
commit 7d391194f5
13 changed files with 141 additions and 42 deletions

View File

@@ -6,7 +6,7 @@ void main() async {
//init hive
await Hive.initFlutter();
//open the box
var box = await Hive.openBox('todoBox');
await Hive.openBox('todoBox');
runApp(const MyApp());
}
@@ -23,11 +23,12 @@ class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Todo',
title: 'Tody',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.red,
),
home: const MyHomePage(title: 'Ma liste de tache'),
home: const MyHomePage(title: 'Tody'),
);
}
}

View File

@@ -23,7 +23,6 @@ class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
// TODO: implement initState
// first time
if (_myBox.get('todos') == null) {
db.createInitialData();
@@ -74,17 +73,43 @@ class _MyHomePageState extends State<MyHomePage> {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
centerTitle: true,
),
body: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: db.todoList.length,
itemBuilder: (context, index) {
return db.todoList[index][1] == false
? ToDoTile(
taskName: db.todoList[index][0],
taskCompleted: db.todoList[index][1],
onChanged: (value) => checkBoxChanged(value, index),
deleteFunction: (context) => deleteTask(index),
)
: SizedBox.shrink();
}),
),
Text(
"Tache complété : ${db.todoList.where((element) => element[1] == true).length}"),
//task completed
Expanded(
child: ListView.builder(
itemCount: db.todoList.length,
itemBuilder: (context, index) {
return db.todoList[index][1] == true
? ToDoTile(
taskName: db.todoList[index][0],
taskCompleted: db.todoList[index][1],
onChanged: (value) => checkBoxChanged(value, index),
deleteFunction: (context) => deleteTask(index),
)
: Container();
}),
),
],
),
body: ListView.builder(
itemCount: db.todoList.length,
itemBuilder: (context, index) {
return ToDoTile(
taskName: db.todoList[index][0],
taskCompleted: db.todoList[index][1],
onChanged: (value) => checkBoxChanged(value, index),
deleteFunction: (context) => deleteTask(index),
);
}),
floatingActionButton: FloatingActionButton(
onPressed: createNewTask,
tooltip: 'Increment',

View File

@@ -2,39 +2,54 @@ import 'package:flutter/material.dart';
import 'package:todo/utils/my_button.dart';
class DialogBox extends StatelessWidget {
DialogBox(
const DialogBox(
{Key? key,
required this.controller,
required this.onSave,
required this.onCancel})
: super(key: key);
final controller;
VoidCallback onSave;
VoidCallback onCancel;
final TextEditingController controller;
final VoidCallback onSave;
final VoidCallback onCancel;
@override
Widget build(BuildContext context) {
return AlertDialog(
backgroundColor: Theme.of(context).primaryColor,
title: Text("New Task"),
content: Container(
title: const Text(
"Nouvelle tache",
style: TextStyle(color: Colors.white),
),
content: SizedBox(
height: 120,
child: Column(
children: [
TextField(
controller: controller,
decoration: InputDecoration(
border: OutlineInputBorder(), hintText: "Add new task"),
autofocus: true,
style: const TextStyle(color: Colors.white),
decoration: const InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
border: OutlineInputBorder(
gapPadding: 4, borderSide: BorderSide(color: Colors.white)),
hintText: "Ajouter une tache",
hintStyle: TextStyle(color: Colors.white),
),
),
SizedBox(
const SizedBox(
height: 40,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
MyButton(text: "Cancel", onPressed: onCancel),
MyButton(text: "Save", onPressed: onSave),
MyButton(text: "Annuler", onPressed: onCancel),
MyButton(text: "Sauvegarder", onPressed: onSave),
],
)
],

View File

@@ -1,18 +1,18 @@
import 'package:flutter/material.dart';
class MyButton extends StatelessWidget {
MyButton({Key? key, required this.text, required this.onPressed})
const MyButton({Key? key, required this.text, required this.onPressed})
: super(key: key);
final String text;
VoidCallback onPressed;
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
return MaterialButton(
onPressed: onPressed,
color: Theme.of(context).primaryColor,
child: Text(text),
child: Text(text, style: const TextStyle(color: Colors.white)),
);
}
}

View File

@@ -18,27 +18,28 @@ class ToDoTile extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.fromLTRB(25.0, 25, 25, 0),
padding: const EdgeInsets.fromLTRB(15.0, 15, 15, 0),
child: Slidable(
endActionPane: ActionPane(
motion: StretchMotion(),
motion: const StretchMotion(),
children: [
SlidableAction(
onPressed: deleteFunction,
icon: Icons.delete,
backgroundColor: const Color.fromARGB(255, 249, 137, 135),
backgroundColor: Color.fromARGB(255, 249, 137, 135),
borderRadius: BorderRadius.circular(12),
)
],
),
child: Container(
padding: EdgeInsets.all(24.0),
padding: const EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
taskName,
style: TextStyle(
color: Colors.white,
decoration: taskCompleted
? TextDecoration.lineThrough
: TextDecoration.none),
@@ -46,12 +47,19 @@ class ToDoTile extends StatelessWidget {
Checkbox(
value: taskCompleted,
onChanged: onChanged,
activeColor: Colors.redAccent,
side:
MaterialStateBorderSide.resolveWith((states) => BorderSide(
width: 2,
color: Colors.white,
)),
focusColor: Colors.white,
checkColor: Colors.white,
activeColor: taskCompleted ? Colors.grey : Colors.redAccent,
)
],
),
decoration: BoxDecoration(
color: Theme.of(context).primaryColor,
color: taskCompleted ? Colors.grey : Theme.of(context).primaryColor,
borderRadius: BorderRadius.circular(10.0),
),
),