Skip to content

Commit e74ebf3

Browse files
committed
Model,DB Helper,States,Insert<Fetch
1 parent 85fc827 commit e74ebf3

24 files changed

+1222
-121
lines changed

lib/db_helper/dbHelper.dart

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import 'dart:io';
2+
import 'package:sqflite/sqflite.dart';
3+
import 'package:path/path.dart';
4+
import 'package:path_provider/path_provider.dart';
5+
import '../model/task_model.dart';
6+
class DbHelper
7+
{
8+
Database? _db;
9+
Future<Database?> get db
10+
async {
11+
if(_db!=null)
12+
{
13+
return _db;
14+
}
15+
final directory = Platform.isAndroid
16+
? await getExternalStorageDirectory()
17+
: await getApplicationSupportDirectory();
18+
String path=join(directory!.path,'db');
19+
var db=await openDatabase(path,version: 1,onCreate: (db, version) {
20+
db.execute("CREATE TABLE Tasks(key TEXT PRIMARY KEY,title TEXT,category TEXT,description TEXT,image TEXT,date TEXT,startTime TEXT,periority TEXT,show TEXT,endTime TEXT,status,TEXT)");
21+
22+
23+
},);
24+
return db;
25+
}
26+
27+
28+
29+
Future<TaskModel> insert(TaskModel model) async {
30+
var dbClient=await db;
31+
dbClient!.insert('Tasks', model.toMap()).then((value) {
32+
});
33+
return model;
34+
}
35+
Future<int> delete (String id,String table) async {
36+
var dbClient=await db;
37+
return await dbClient!.delete(
38+
table,
39+
where: 'key = ?',
40+
whereArgs: [id]);
41+
}
42+
Future<List<TaskModel>> getData() async {
43+
var dbClient = await db;
44+
final List<Map<String, Object?>> queryResult = await dbClient!.query('Tasks');
45+
return queryResult.map((e) => TaskModel.fromMap(e)).toList();
46+
}
47+
48+
49+
}

lib/main.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:flutter/material.dart';
2-
import 'package:todo/view/home/home.dart';
3-
2+
import 'package:get/get.dart';
3+
import 'package:todo/view/splash/splash_screen.dart';
44
void main() {
55
runApp(const MyApp());
66
}
@@ -9,13 +9,13 @@ class MyApp extends StatelessWidget {
99
const MyApp({super.key});
1010
@override
1111
Widget build(BuildContext context) {
12-
return MaterialApp(
12+
return GetMaterialApp(
1313
debugShowCheckedModeBanner: false,
1414
theme: ThemeData(
1515
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
1616
useMaterial3: true,
1717
),
18-
home: HomePage()
18+
home: const SplashView()
1919
);
2020
}
2121
}

lib/model/task_model.dart

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import 'dart:core';
2+
3+
class TaskModel {
4+
String? key;
5+
String? title;
6+
String? category;
7+
String? description;
8+
String? image;
9+
String? periority;
10+
String? startTime;
11+
String? endTime;
12+
String? date;
13+
String? show;
14+
String? status;
15+
16+
TaskModel(
17+
{ required this.key,
18+
required this.startTime,
19+
required this.endTime,
20+
required this.date,
21+
required this.periority,
22+
required this.description,
23+
required this.category,
24+
required this.title,
25+
required this.image,
26+
required this.show,
27+
required this.status});
28+
29+
TaskModel.fromMap(Map<String, dynamic> res) {
30+
key = res['key'];
31+
title = res['title'];
32+
category = res['category'];
33+
description = res['description'];
34+
image = res['image'];
35+
periority = res['periority'];
36+
show = res['show'];
37+
startTime = res['startTime'];
38+
endTime = res['endTime'];
39+
date = res['date'];
40+
status=res['status'];
41+
}
42+
43+
Map<String, Object?> toMap() {
44+
return {
45+
'key': key,
46+
'title': title,
47+
'category': category,
48+
'description': description,
49+
'image': image,
50+
'periority': periority,
51+
'startTime': startTime,
52+
'endTime': endTime,
53+
'date': date,
54+
'show': show,
55+
'status' : status,
56+
};
57+
}
58+
}

lib/util/utils.dart

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11

2+
import 'package:flutter/material.dart';
3+
import 'package:get/get.dart';
24
import 'package:intl/intl.dart';
5+
import 'package:todo/res/constants.dart';
36
class Utils{
47

58
static String getMonth(DateTime date){
@@ -13,11 +16,33 @@ class Utils{
1316
}
1417
return formattedDate;
1518
}
16-
1719
static String getDay(DateTime date){
1820
String formattedDate = DateFormat('EEE').format(date);
1921
return formattedDate;
2022
}
23+
static String addPrefix(String string){
24+
if(string.length==1){
25+
string='0$string';
26+
}
27+
return string;
28+
}
29+
30+
31+
32+
static void showSnackBar(String title,String message,Widget icon){
33+
Get.showSnackbar(
34+
GetSnackBar(
35+
backgroundColor: darkestBlue,
36+
title: title,
37+
isDismissible: true,
38+
duration: const Duration(milliseconds: 2000),
39+
icon: icon,
40+
message: message,
41+
snackPosition: SnackPosition.BOTTOM,
42+
padding: const EdgeInsets.symmetric(horizontal: 20,vertical: 5),
43+
)
44+
);
45+
}
2146

2247

2348
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import 'package:animated_bottom_navigation_bar/animated_bottom_navigation_bar.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:get/get.dart';
4+
5+
import '../../../view_model/controller/home_controller.dart';
6+
7+
class BottomNavBar extends StatelessWidget {
8+
BottomNavBar({super.key});
9+
final controller = Get.put(HomeController());
10+
@override
11+
Widget build(BuildContext context) {
12+
return Obx(()=>AnimatedBottomNavigationBar(
13+
elevation: 10,
14+
height: 60,
15+
inactiveColor: Colors.grey,
16+
activeColor: Colors.orange,
17+
icons: const [
18+
Icons.home_max,
19+
Icons.ac_unit,
20+
Icons.edit_note_sharp,
21+
Icons.person_outline_rounded
22+
],
23+
activeIndex: controller.barIndex.value,
24+
gapLocation: GapLocation.center,
25+
notchSmoothness: NotchSmoothness.verySmoothEdge,
26+
leftCornerRadius: 32,
27+
rightCornerRadius: 32,
28+
onTap: (index){controller.barIndex.value=index;},
29+
//other params
30+
),);
31+
}
32+
}

lib/view/home/components/date_container.dart

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
2-
31
import 'package:flutter/material.dart';
42
import 'package:get/get.dart';
5-
63
import '../../../res/constants.dart';
74
import '../../../view_model/controller/home_controller.dart';
85
import 'dates.dart';
@@ -14,7 +11,8 @@ class DateContainer extends StatelessWidget {
1411
@override
1512
Widget build(BuildContext context) {
1613
var size=MediaQuery.sizeOf(context);
17-
return Obx(() => Container(
14+
return Obx(() => AnimatedContainer(
15+
duration: const Duration(milliseconds: 200),
1816
height: 110,
1917
width: 70,
2018
margin: EdgeInsets.only(left: size.width*0.05),
@@ -44,4 +42,4 @@ class DateContainer extends StatelessWidget {
4442
child: Dates(index: index)
4543
));
4644
}
47-
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:todo/view/new_task/new_task.dart';
3+
4+
import '../../../res/constants.dart';
5+
6+
class FloatingButton extends StatelessWidget {
7+
const FloatingButton({super.key});
8+
9+
@override
10+
Widget build(BuildContext context) {
11+
return InkWell(
12+
borderRadius: BorderRadius.circular(50),
13+
onTap: () {
14+
showModalBottomSheet(
15+
elevation: 0,
16+
isScrollControlled: true,
17+
backgroundColor: Colors.white,
18+
context: context, builder: (context) {
19+
return NewTask();
20+
},);
21+
},
22+
child: Container(
23+
height: 60,
24+
width: 60,
25+
decoration: const BoxDecoration(
26+
shape: BoxShape.circle,
27+
gradient: LinearGradient(colors: [
28+
lightAccentBlue,
29+
darkAccentBlue,
30+
darkAccentBlue
31+
])
32+
),
33+
child: const Icon(Icons.add,color: Colors.white,),
34+
),
35+
);
36+
}
37+
}

0 commit comments

Comments
 (0)