Init
This commit is contained in:
185
lib/Activities.dart
Normal file
185
lib/Activities.dart
Normal file
@@ -0,0 +1,185 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'main.dart';
|
||||
import 'NewTask.dart';
|
||||
import 'Data.dart';
|
||||
import 'User.dart' as User;
|
||||
import 'package:sn_progress_dialog/sn_progress_dialog.dart';
|
||||
|
||||
|
||||
|
||||
class Activities extends StatefulWidget {
|
||||
const Activities({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ActivitiesState createState() => _ActivitiesState();
|
||||
}
|
||||
late ProgressDialog progressDialog;
|
||||
class _ActivitiesState extends State<Activities> {
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
|
||||
UpdateList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
progressDialog=ProgressDialog(context: context);
|
||||
return Scaffold(
|
||||
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: (context) => NewTask()))
|
||||
.then((value) => UpdateList());
|
||||
},
|
||||
label: Text("New Activity"),
|
||||
icon: Icon(Icons.add)),
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(children: [
|
||||
Icon(Icons.task, color: Theme.of(context).primaryColor),
|
||||
SizedBox(width: 10),
|
||||
Text('Activities')
|
||||
]),
|
||||
(selecting)?Row(children: [
|
||||
InkWell(onTap: (){
|
||||
DeleteSelectedTasks();
|
||||
}, child: Icon(Icons.delete,size: 30,)),
|
||||
SizedBox(width: 20,),
|
||||
InkWell(onTap: (){setState(() {
|
||||
selecting=false;
|
||||
});}, child: Icon(Icons.close,size: 30),)
|
||||
]) : Container(),
|
||||
],
|
||||
)),
|
||||
drawer: navDrawer(context, 3),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: PrintTasks(),
|
||||
))));
|
||||
}
|
||||
|
||||
void UpdateList() async {
|
||||
if(progressDialog != null){progressDialog.show(max:100,msg: 'Loading Task Types');}
|
||||
await User.updateTasksList();
|
||||
setState(() {});
|
||||
if(progressDialog != null){progressDialog.update(value: 100);}
|
||||
}
|
||||
|
||||
List<Widget> PrintTasks() {
|
||||
List<Widget> _tasks = [];
|
||||
print('Priting cats : ' + User.taskTypes.length.toString());
|
||||
User.taskTypes.forEach((element) {
|
||||
String name = element.name;
|
||||
if (element.cat == null) {
|
||||
print('Got some null cat : ${element.name}');
|
||||
} else {
|
||||
Color color = HexColor.fromHex(element.cat?.color ?? '#000000');
|
||||
bool productive = element.cat?.productive ?? true;
|
||||
Widget task = TaskCard(context, name, productive, color);
|
||||
_tasks.add(task);
|
||||
}
|
||||
});
|
||||
|
||||
return _tasks;
|
||||
}
|
||||
|
||||
bool selecting = false;
|
||||
Widget TaskCard(
|
||||
BuildContext context, String name, bool productive, Color color) {
|
||||
return Row(children: [
|
||||
// Container(),
|
||||
(selecting)
|
||||
? Checkbox(
|
||||
value: selectedTasks.contains(name),
|
||||
onChanged: (value) {
|
||||
print('selected $name');
|
||||
OnItemSelected(name);
|
||||
setState(() {});
|
||||
})
|
||||
: Container(),
|
||||
Expanded(
|
||||
child: Column(children: [
|
||||
Card(
|
||||
|
||||
// color: color,
|
||||
elevation:20,
|
||||
shadowColor: color,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
//Open Respective Category
|
||||
if(selecting){
|
||||
OnItemSelected(name);
|
||||
}
|
||||
setState(() {
|
||||
|
||||
});
|
||||
},
|
||||
onLongPress: () {
|
||||
print('gonna delete');
|
||||
selecting = !selecting;
|
||||
selectedTasks = [name];
|
||||
setState(() {});
|
||||
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(name,
|
||||
style: TextStyle(color: Colors.white)),
|
||||
// Icon(Icons.analytics, color: color, size: 20,),
|
||||
Icon(Icons.circle,
|
||||
color: (productive)
|
||||
? Colors.green
|
||||
: Colors.red)
|
||||
]),
|
||||
],
|
||||
)))),
|
||||
Container(
|
||||
margin: EdgeInsets.fromLTRB(15, 0, 15, 10),
|
||||
height: 2,
|
||||
color: color)
|
||||
]),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
void OnItemSelected(String name){
|
||||
if (!selectedTasks.contains(name)) {
|
||||
selectedTasks.add(name);
|
||||
} else {
|
||||
selectedTasks.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
void DeleteSelectedTasks() async{
|
||||
progressDialog.show(max: 100, msg: 'Deleteing ${selectedTasks.length} Task Types');
|
||||
selectedTasks.forEach((element) async {
|
||||
await User.UserOperations.deleteTask(element, bulk:true);
|
||||
});
|
||||
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
await User.UserOperations.executeQueries();
|
||||
selectedTasks=[];
|
||||
selecting=false;
|
||||
setState(() {
|
||||
progressDialog.update(value: 100);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<String> selectedTasks = [];
|
||||
213
lib/Categories.dart
Normal file
213
lib/Categories.dart
Normal file
@@ -0,0 +1,213 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tasktracker/NewCategory.dart';
|
||||
import 'main.dart';
|
||||
import 'NewTask.dart';
|
||||
import 'User.dart' as User;
|
||||
import 'Data.dart';
|
||||
import 'package:sn_progress_dialog/sn_progress_dialog.dart';
|
||||
class Categories extends StatefulWidget {
|
||||
const Categories({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_CategoriesState createState() => _CategoriesState();
|
||||
}
|
||||
|
||||
late ProgressDialog progressDialog;
|
||||
bool selecting=false;
|
||||
class _CategoriesState extends State<Categories> {
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
|
||||
UpdateList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
progressDialog=ProgressDialog(context: context);
|
||||
return Scaffold(
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: (context) => NewCategory()))
|
||||
.then((value) => UpdateList());
|
||||
},
|
||||
label: Text("New Category"),
|
||||
icon: Icon(Icons.add)),
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(children: [
|
||||
Icon(Icons.account_tree_outlined, color: Theme.of(context).primaryColor),
|
||||
SizedBox(width: 10),
|
||||
Text('Categories')
|
||||
]),
|
||||
(selecting)?Row(children: [
|
||||
InkWell(onTap: (){
|
||||
DeleteSelectedCats();
|
||||
}, child: Icon(Icons.delete,size: 30,)),
|
||||
SizedBox(width: 20,),
|
||||
InkWell(onTap: (){setState(() {
|
||||
selecting=false;
|
||||
});}, child: Icon(Icons.close,size: 30),)
|
||||
]) : Container(),
|
||||
],
|
||||
)),
|
||||
drawer: navDrawer(context, 4),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: PrintCats(),
|
||||
))));
|
||||
}
|
||||
|
||||
void UpdateList() async {
|
||||
await User.updateCatsList();
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
List<Widget> PrintCats() {
|
||||
List<Widget> _cats = [];
|
||||
print('Priting cats : ' + User.categories.length.toString());
|
||||
User.categories.forEach((element) {
|
||||
String name = element.name;
|
||||
Color color = HexColor.fromHex(element.color);
|
||||
bool productive = element.productive;
|
||||
Widget cat = TaskCard(context,name, productive, color);
|
||||
_cats.add(cat);
|
||||
});
|
||||
|
||||
return _cats;
|
||||
}
|
||||
void OnItemSelected(String name){
|
||||
if (!selectedTasks.contains(name)) {
|
||||
selectedTasks.add(name);
|
||||
} else {
|
||||
selectedTasks.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
void DeleteSelectedCats() async{
|
||||
progressDialog.show(max: 100, msg: 'Deleteing ${selectedTasks.length} Categories');
|
||||
selectedTasks.forEach((element) async {
|
||||
await User.UserOperations.deleteCategory(element, bulk:true);
|
||||
});
|
||||
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
await User.UserOperations.executeQueries();
|
||||
selectedTasks=[];
|
||||
selecting=false;
|
||||
setState(() {
|
||||
progressDialog.update(value: 100);
|
||||
});
|
||||
|
||||
}
|
||||
Widget TaskCard(
|
||||
BuildContext context, String name, bool productive, Color color) {
|
||||
return Row(children: [
|
||||
// Container(),
|
||||
(selecting)
|
||||
? Checkbox(
|
||||
value: selectedTasks.contains(name),
|
||||
onChanged: (value) {
|
||||
print('selected $name');
|
||||
OnItemSelected(name);
|
||||
setState(() {});
|
||||
})
|
||||
: Container(),
|
||||
Expanded(
|
||||
child: Column(children: [
|
||||
Card(
|
||||
|
||||
// color: color,
|
||||
elevation:20,
|
||||
shadowColor: color,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
//Open Respective Category
|
||||
if(selecting){
|
||||
OnItemSelected(name);
|
||||
}
|
||||
setState(() {
|
||||
|
||||
});
|
||||
},
|
||||
onLongPress: () {
|
||||
print('gonna delete');
|
||||
selecting = !selecting;
|
||||
selectedTasks = [name];
|
||||
setState(() {});
|
||||
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(name,
|
||||
style: TextStyle(color: Colors.white)),
|
||||
// Icon(Icons.analytics, color: color, size: 20,),
|
||||
Icon(Icons.circle,
|
||||
color: (productive)
|
||||
? Colors.green
|
||||
: Colors.red)
|
||||
]),
|
||||
],
|
||||
)))),
|
||||
Container(
|
||||
margin: EdgeInsets.fromLTRB(15, 0, 15, 10),
|
||||
height: 2,
|
||||
color: color)
|
||||
]),
|
||||
),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> selectedTasks = [];
|
||||
|
||||
// Widget TaskCard(String name, bool productive, Color color) {
|
||||
// return Column(
|
||||
// children: [Card(
|
||||
// // color: color,
|
||||
// elevation: 30,
|
||||
// shadowColor: color,
|
||||
// child: InkWell(
|
||||
// onTap: () {
|
||||
// //Open Respective Category
|
||||
// },
|
||||
// onLongPress: () {
|
||||
// print('gonna delete');
|
||||
// },
|
||||
// child: Container(
|
||||
// padding: EdgeInsets.all(10),
|
||||
// child: Column(
|
||||
// children: [
|
||||
// Row(
|
||||
// mainAxisSize: MainAxisSize.max,
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
// children: [
|
||||
// Text(name, style: TextStyle(color: Colors.white)),
|
||||
// // Icon(Icons.analytics, color: color, size: 20,),
|
||||
// Icon(Icons.circle,
|
||||
// color: (productive) ? Colors.green : Colors.red)
|
||||
// ]),
|
||||
// ],
|
||||
// ))
|
||||
//
|
||||
// )),
|
||||
//
|
||||
// Container(
|
||||
// margin: EdgeInsets.fromLTRB(10, 0, 10, 10),
|
||||
// height: 2,
|
||||
// color: color
|
||||
// )
|
||||
// ]);
|
||||
// }
|
||||
94
lib/Data.dart
Normal file
94
lib/Data.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
class Category{
|
||||
|
||||
Category(this.category_id, this.name, this.color, this.productive);
|
||||
|
||||
String category_id;
|
||||
String name;
|
||||
String color;
|
||||
bool productive;
|
||||
|
||||
static String colCatId = "category_id";
|
||||
static String colName = "name";
|
||||
static String colColor = "color";
|
||||
static String colProductive = "productive";
|
||||
}
|
||||
|
||||
class TaskType{
|
||||
|
||||
TaskType(this.id, this.name, this.category, [this.cat = null]);
|
||||
|
||||
String id;
|
||||
String name;
|
||||
String category;
|
||||
Category? cat;
|
||||
|
||||
static String colId = "id";
|
||||
static String colName="name";
|
||||
static String colCategory = "category_id";
|
||||
}
|
||||
|
||||
class Activity{
|
||||
|
||||
Activity(this.taskType, this.startTime, this.endTime);
|
||||
|
||||
TaskType taskType;
|
||||
DateTime startTime;
|
||||
DateTime endTime;
|
||||
|
||||
static String colType = "type";
|
||||
static String colStartTime = "s_time";
|
||||
static String colEndTime = "e_time";
|
||||
}
|
||||
|
||||
class InitialData{
|
||||
static List<TaskType> getTaskTypes(String username){
|
||||
List<TaskType> tasks =[
|
||||
TaskType(username + 'Sleep','Sleep', 'Relax'),
|
||||
TaskType(username + 'Physics','Physics', 'Study'),
|
||||
TaskType(username + 'History','History','Study'),
|
||||
TaskType(username + 'Football','Football', 'Play'),
|
||||
TaskType(username + 'At work','At work', 'Work'),
|
||||
TaskType(username + 'Chores','Chores', 'Daily Activities'),
|
||||
TaskType(username + 'Eat','Eat','Daily Activities'),
|
||||
TaskType(username + 'Hang out','Hang out', 'Social')
|
||||
];
|
||||
return tasks;
|
||||
}
|
||||
|
||||
static List<Category> getCategories(String username){
|
||||
List<Category> cats = [
|
||||
Category(username+'Relax','Relax', '#555555', false),
|
||||
Category(username+'Daily Activities','Daily Activities', '#009955',false),
|
||||
Category(username+'Study','Study', '#00FF00', true),
|
||||
Category(username+'Play','Play', '#FF0000', false),
|
||||
Category(username+'Work','Work', '#00AAFF', true),
|
||||
Category(username+'Social','Social', '#00AAAA', false)
|
||||
];
|
||||
|
||||
return cats;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class Queries{
|
||||
static String colLink= "file";
|
||||
static String colData = "data";
|
||||
}
|
||||
|
||||
|
||||
class Settings{
|
||||
|
||||
static Future<String> UUID() async{
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
if(prefs.containsKey('uuid')){
|
||||
return await Future.value(prefs.getString('uuid'));
|
||||
}else{
|
||||
var uuid = Uuid();
|
||||
String _uuid = uuid.v4();
|
||||
await prefs.setString('uuid',_uuid);
|
||||
return Future.value(_uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
199
lib/NewCategory.dart
Normal file
199
lib/NewCategory.dart
Normal file
@@ -0,0 +1,199 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:flutter_colorpicker/flutter_colorpicker.dart';
|
||||
import 'User.dart' as User;
|
||||
import 'Data.dart';
|
||||
|
||||
DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
DateFormat durationFormat = DateFormat("HH:mm:ss");
|
||||
|
||||
class NewCategory extends StatefulWidget {
|
||||
const NewCategory({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_NewCategoryState createState() => _NewCategoryState();
|
||||
}
|
||||
|
||||
class _NewCategoryState extends State<NewCategory> {
|
||||
TextEditingController nameController = TextEditingController();
|
||||
bool productive = true;
|
||||
Color pickerColor = Colors.blue;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('New Category')),
|
||||
body: Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 50, 20, 50),
|
||||
child: Column(
|
||||
children: [
|
||||
Column(children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Text('Category Name')),
|
||||
Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: TextField(
|
||||
controller: nameController,
|
||||
decoration: InputDecoration(
|
||||
hintText:
|
||||
'ex: Study, Games, Relax, etc...',
|
||||
border: OutlineInputBorder()),
|
||||
),
|
||||
),
|
||||
Divider(),
|
||||
Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Productivity',
|
||||
style: TextStyle(fontSize: 18)),
|
||||
Switch(
|
||||
value: productive,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
productive = value;
|
||||
});
|
||||
},
|
||||
)
|
||||
])),
|
||||
Divider(),
|
||||
Container(
|
||||
margin: EdgeInsets.all(10),
|
||||
child: InkWell(
|
||||
onTap: () => pickColor(context),
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Text("Category Color ",
|
||||
style: TextStyle(fontSize: 18)),
|
||||
Icon(Icons.circle,
|
||||
size: 40, color: pickerColor)
|
||||
],
|
||||
)))
|
||||
]),
|
||||
],
|
||||
))),
|
||||
Container(
|
||||
padding:
|
||||
EdgeInsets.symmetric(vertical: 10, horizontal: 20),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 5,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 10, vertical: 0),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.red,
|
||||
shape: StadiumBorder()),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
Navigator.pop(context);
|
||||
});
|
||||
},
|
||||
child: Text('Back',
|
||||
style: TextStyle(fontSize: 20))))),
|
||||
Expanded(
|
||||
flex: 6,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 10, vertical: 0),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.green,
|
||||
shape: StadiumBorder()),
|
||||
onPressed: () {
|
||||
add_action();
|
||||
},
|
||||
child: Text('Add Category',
|
||||
style: TextStyle(fontSize: 20))))),
|
||||
],
|
||||
))
|
||||
])));
|
||||
}
|
||||
|
||||
void pickColor(BuildContext context) => showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text('Pick Color for Category'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
MaterialPicker(
|
||||
pickerColor: pickerColor,
|
||||
onColorChanged: (color){
|
||||
setState(() {
|
||||
pickerColor=color;
|
||||
});
|
||||
},
|
||||
enableLabel: false,
|
||||
portraitOnly: true,
|
||||
),
|
||||
TextButton(
|
||||
child: Text('Select', style: TextStyle(fontSize: 20)),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
)
|
||||
]),
|
||||
));
|
||||
|
||||
void add_action() async{
|
||||
String catName = nameController.value.text;
|
||||
|
||||
if(catName.length< 2){
|
||||
showAlertDialog(context, 'Category needs a name', 'Please enter a name for this category');
|
||||
return;
|
||||
}
|
||||
var hex = '#${pickerColor.value.toRadixString(16)}';
|
||||
await User.UserOperations.addCategory(catName, hex, productive);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
String _printDuration(Duration duration) {
|
||||
String twoDigits(int n) => n.toString().padLeft(2, "0");
|
||||
String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60));
|
||||
String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60));
|
||||
return "${twoDigits(duration.inHours)}:$twoDigitMinutes:$twoDigitSeconds";
|
||||
}
|
||||
|
||||
showAlertDialog(BuildContext context, String title, String message) {
|
||||
|
||||
// set up the button
|
||||
Widget okButton = TextButton(
|
||||
child: Text("OK"),
|
||||
onPressed: () { Navigator.of(context).pop(); },
|
||||
);
|
||||
|
||||
// set up the AlertDialog
|
||||
AlertDialog alert = AlertDialog(
|
||||
title: Text(title),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
okButton,
|
||||
],
|
||||
);
|
||||
|
||||
// show the dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
}
|
||||
184
lib/NewTask.dart
Normal file
184
lib/NewTask.dart
Normal file
@@ -0,0 +1,184 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'User.dart' as User;
|
||||
|
||||
DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
DateFormat durationFormat = DateFormat("HH:mm:ss");
|
||||
|
||||
class NewTask extends StatefulWidget {
|
||||
const NewTask({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_NewTaskState createState() => _NewTaskState();
|
||||
}
|
||||
|
||||
List<String> getCategoryNames(){
|
||||
List<String> _cats = [];
|
||||
User.categories.forEach((element) {
|
||||
String name = element.name;
|
||||
_cats.add(name);
|
||||
});
|
||||
return _cats;
|
||||
}
|
||||
|
||||
String selectedCat = User.categories[0].name;
|
||||
class _NewTaskState extends State<NewTask> {
|
||||
TextEditingController nameController = TextEditingController();
|
||||
bool productive = true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('New Task Type')),
|
||||
body: Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 50, 20, 50),
|
||||
child: Column(
|
||||
children: [
|
||||
Column(children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Text('Task Type Name')),
|
||||
Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: TextField(
|
||||
controller: nameController,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'ex: Study Science, Play CS:GO, etc...',
|
||||
border: OutlineInputBorder()
|
||||
),
|
||||
),
|
||||
),
|
||||
Divider(),
|
||||
Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Text('Category')),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blueGrey,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.grey, width: 2)),
|
||||
child: DropdownButton<String>(
|
||||
dropdownColor: Colors.blueGrey,
|
||||
iconSize: 30,
|
||||
elevation: 10,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
value: selectedCat,
|
||||
isExpanded: true,
|
||||
items: getCategoryNames().map<DropdownMenuItem<String>>(
|
||||
(String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? _value) {
|
||||
setState(() {
|
||||
selectedCat = _value!;
|
||||
});
|
||||
})),
|
||||
Container(
|
||||
child: Divider(
|
||||
height: 30,
|
||||
)),
|
||||
]),
|
||||
],
|
||||
))),
|
||||
Container(
|
||||
padding:
|
||||
EdgeInsets.symmetric(vertical: 10, horizontal: 20),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 5,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 0),
|
||||
child: ElevatedButton(
|
||||
|
||||
style:ElevatedButton.styleFrom(
|
||||
primary: Colors.red,
|
||||
shape: StadiumBorder()
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
Navigator.pop(context);
|
||||
});
|
||||
},
|
||||
child: Text('Back',
|
||||
style: TextStyle(fontSize: 20))))),
|
||||
Expanded(
|
||||
flex: 6,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 0),
|
||||
child: ElevatedButton(
|
||||
style:ElevatedButton.styleFrom(
|
||||
primary: Colors.green,
|
||||
shape: StadiumBorder()
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
add_action();
|
||||
});
|
||||
},
|
||||
child: Text('Add Task Type',
|
||||
style: TextStyle(fontSize: 20))))),
|
||||
],
|
||||
))
|
||||
])));
|
||||
}
|
||||
|
||||
void add_action() async{
|
||||
String catName = nameController.value.text;
|
||||
print('adding Task Type : $catName, $selectedCat');
|
||||
if(catName.length< 2){
|
||||
showAlertDialog(context, 'Category needs a name', 'Please enter a name for this category');
|
||||
return;
|
||||
}
|
||||
await User.UserOperations.addTaskType(catName,selectedCat);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
String _printDuration(Duration duration) {
|
||||
String twoDigits(int n) => n.toString().padLeft(2, "0");
|
||||
String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60));
|
||||
String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60));
|
||||
return "${twoDigits(duration.inHours)}:$twoDigitMinutes:$twoDigitSeconds";
|
||||
}
|
||||
showAlertDialog(BuildContext context, String title, String message) {
|
||||
|
||||
// set up the button
|
||||
Widget okButton = TextButton(
|
||||
child: Text("OK"),
|
||||
onPressed: () { Navigator.of(context).pop(); },
|
||||
);
|
||||
|
||||
// set up the AlertDialog
|
||||
AlertDialog alert = AlertDialog(
|
||||
title: Text(title),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
okButton,
|
||||
],
|
||||
);
|
||||
|
||||
// show the dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
}
|
||||
185
lib/Tasks.dart
Normal file
185
lib/Tasks.dart
Normal file
@@ -0,0 +1,185 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'main.dart';
|
||||
import 'NewTask.dart';
|
||||
import 'Data.dart';
|
||||
import 'User.dart' as User;
|
||||
import 'package:sn_progress_dialog/sn_progress_dialog.dart';
|
||||
|
||||
|
||||
|
||||
class Tasks extends StatefulWidget {
|
||||
const Tasks({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_TasksState createState() => _TasksState();
|
||||
}
|
||||
late ProgressDialog progressDialog;
|
||||
class _TasksState extends State<Tasks> {
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
|
||||
UpdateList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
progressDialog=ProgressDialog(context: context);
|
||||
return Scaffold(
|
||||
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: (context) => NewTask()))
|
||||
.then((value) => UpdateList());
|
||||
},
|
||||
label: Text("New Task Type"),
|
||||
icon: Icon(Icons.add)),
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(children: [
|
||||
Icon(Icons.task, color: Theme.of(context).primaryColor),
|
||||
SizedBox(width: 10),
|
||||
Text('Task Types')
|
||||
]),
|
||||
(selecting)?Row(children: [
|
||||
InkWell(onTap: (){
|
||||
DeleteSelectedTasks();
|
||||
}, child: Icon(Icons.delete,size: 30,)),
|
||||
SizedBox(width: 20,),
|
||||
InkWell(onTap: (){setState(() {
|
||||
selecting=false;
|
||||
});}, child: Icon(Icons.close,size: 30),)
|
||||
]) : Container(),
|
||||
],
|
||||
)),
|
||||
drawer: navDrawer(context, 3),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: PrintTasks(),
|
||||
))));
|
||||
}
|
||||
|
||||
void UpdateList() async {
|
||||
if(progressDialog != null){progressDialog.show(max:100,msg: 'Loading Task Types');}
|
||||
await User.updateTasksList();
|
||||
setState(() {});
|
||||
if(progressDialog != null){progressDialog.update(value: 100);}
|
||||
}
|
||||
|
||||
List<Widget> PrintTasks() {
|
||||
List<Widget> _tasks = [];
|
||||
print('Priting cats : ' + User.taskTypes.length.toString());
|
||||
User.taskTypes.forEach((element) {
|
||||
String name = element.name;
|
||||
if (element.cat == null) {
|
||||
print('Got some null cat : ${element.name}');
|
||||
} else {
|
||||
Color color = HexColor.fromHex(element.cat?.color ?? '#000000');
|
||||
bool productive = element.cat?.productive ?? true;
|
||||
Widget task = TaskCard(context, name, productive, color);
|
||||
_tasks.add(task);
|
||||
}
|
||||
});
|
||||
|
||||
return _tasks;
|
||||
}
|
||||
|
||||
bool selecting = false;
|
||||
Widget TaskCard(
|
||||
BuildContext context, String name, bool productive, Color color) {
|
||||
return Row(children: [
|
||||
// Container(),
|
||||
(selecting)
|
||||
? Checkbox(
|
||||
value: selectedTasks.contains(name),
|
||||
onChanged: (value) {
|
||||
print('selected $name');
|
||||
OnItemSelected(name);
|
||||
setState(() {});
|
||||
})
|
||||
: Container(),
|
||||
Expanded(
|
||||
child: Column(children: [
|
||||
Card(
|
||||
|
||||
// color: color,
|
||||
elevation:20,
|
||||
shadowColor: color,
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
//Open Respective Category
|
||||
if(selecting){
|
||||
OnItemSelected(name);
|
||||
}
|
||||
setState(() {
|
||||
|
||||
});
|
||||
},
|
||||
onLongPress: () {
|
||||
print('gonna delete');
|
||||
selecting = !selecting;
|
||||
selectedTasks = [name];
|
||||
setState(() {});
|
||||
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(name,
|
||||
style: TextStyle(color: Colors.white)),
|
||||
// Icon(Icons.analytics, color: color, size: 20,),
|
||||
Icon(Icons.circle,
|
||||
color: (productive)
|
||||
? Colors.green
|
||||
: Colors.red)
|
||||
]),
|
||||
],
|
||||
)))),
|
||||
Container(
|
||||
margin: EdgeInsets.fromLTRB(15, 0, 15, 10),
|
||||
height: 2,
|
||||
color: color)
|
||||
]),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
void OnItemSelected(String name){
|
||||
if (!selectedTasks.contains(name)) {
|
||||
selectedTasks.add(name);
|
||||
} else {
|
||||
selectedTasks.remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
void DeleteSelectedTasks() async{
|
||||
progressDialog.show(max: 100, msg: 'Deleteing ${selectedTasks.length} Task Types');
|
||||
selectedTasks.forEach((element) async {
|
||||
await User.UserOperations.deleteTask(element, bulk:true);
|
||||
});
|
||||
|
||||
await Future.delayed(Duration(seconds: 2));
|
||||
await User.UserOperations.executeQueries();
|
||||
selectedTasks=[];
|
||||
selecting=false;
|
||||
setState(() {
|
||||
progressDialog.update(value: 100);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<String> selectedTasks = [];
|
||||
564
lib/User.dart
Normal file
564
lib/User.dart
Normal file
@@ -0,0 +1,564 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
import 'Data.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:sn_progress_dialog/sn_progress_dialog.dart';
|
||||
|
||||
late http.Response loginResponse;
|
||||
|
||||
late Database cacheDb;
|
||||
late String username;
|
||||
List<Category> categories = [];
|
||||
List<TaskType> taskTypes = [];
|
||||
List<Activity> activities=[];
|
||||
bool offline = true;
|
||||
|
||||
Future<http.Response> login(String _username, String password) async {
|
||||
username = _username;
|
||||
var device_id = await Settings.UUID();
|
||||
try {
|
||||
loginResponse = (await http.post(
|
||||
Uri.parse('http://161.97.127.136/task_tracker/login.php'),
|
||||
body: <String, String>{
|
||||
"username": _username,
|
||||
"password": password,
|
||||
"device_id": device_id ?? 'n/a'
|
||||
}));
|
||||
|
||||
if (loginResponse.body.toLowerCase().contains("success")) {
|
||||
offline = false;
|
||||
username = _username;
|
||||
}
|
||||
}catch(e){
|
||||
offline=true;
|
||||
}
|
||||
return loginResponse;
|
||||
}
|
||||
|
||||
Future<void> initUserData() async {
|
||||
await initCacheDatabase();
|
||||
await UpdateCategoriesFromServer();
|
||||
await UpdateTaskTypesFromServer();
|
||||
await GetCategories(true);
|
||||
await GetTaskTypes(true);
|
||||
print('Initializing UserData...');
|
||||
if (offline) {
|
||||
print('Going offline mode.');
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> cacheDbExist() async{
|
||||
Directory directory = await getApplicationDocumentsDirectory();
|
||||
return databaseFactory.databaseExists(directory.path + 'cache.db');
|
||||
}
|
||||
|
||||
Future<void> updateCatsList() async{
|
||||
print('Updating with localCache');
|
||||
categories = await GetCategories(true);
|
||||
print('Checking if can refresh');
|
||||
categories = await GetCategories(false);
|
||||
}
|
||||
|
||||
Future<void> updateTasksList() async{
|
||||
print('Updating with localCache');
|
||||
taskTypes = await GetTaskTypes(true);
|
||||
print('Checking if can refresh');
|
||||
taskTypes = await GetTaskTypes(false);
|
||||
}
|
||||
|
||||
|
||||
Future<void> initCacheDatabase() async {
|
||||
Directory directory = await getApplicationDocumentsDirectory();
|
||||
print('database at ' + directory.path + 'cache.db');
|
||||
cacheDb = await openDatabase(directory.path + 'cache.db', version: 1, onCreate: onCacheDatabaseCreate, onUpgrade: onCacheDatabaseUpgrade);
|
||||
|
||||
await UserOperations.executeQueries();
|
||||
}
|
||||
|
||||
void onCacheDatabaseCreate(Database db, int newVersion) async {
|
||||
String CategoriesTableSQL =
|
||||
'CREATE TABLE Categories(${Category.colCatId} VARCHAR(255) PRIMARY KEY,${Category.colName} TEXT, ${Category.colColor} TEXT, ${Category.colProductive} INTEGER)';
|
||||
// print(CategoriesTableSQL);
|
||||
await db.execute(CategoriesTableSQL);
|
||||
print("Initiated Categories Table");
|
||||
|
||||
String TaskTableSQL =
|
||||
'CREATE TABLE TaskTypes(id TEXT PRIMARY KEY, ${TaskType.colName} TEXT, ${TaskType.colCategory} TEXT, '
|
||||
'FOREIGN KEY (${TaskType.colCategory}) REFERENCES Categories(${Category.colCatId}))';
|
||||
// print(TaskTableSQL);
|
||||
await db.execute(TaskTableSQL);
|
||||
|
||||
String ActivityTableSQL =
|
||||
'CREATE TABLE Activities(id INTEGER PRIMARY KEY AUTOINCREMENT, ${Activity.colType} INT, ${Activity.colStartTime} DATETIME, ${Activity.colEndTime} DATETIME, '
|
||||
'FOREIGN KEY (${Activity.colType}) REFERENCES TaskTypes(id))';
|
||||
// print(ActivityTableSQL);
|
||||
await db.execute(ActivityTableSQL);
|
||||
|
||||
String QueriesTableSQL = 'CREATE TABLE Queries(id INTEGER PRIMARY KEY AUTOINCREMENT, ${Queries.colLink} TEXT,${Queries.colData} TEXT)';
|
||||
// print(QueriesTableSQL);
|
||||
await db.execute(QueriesTableSQL);
|
||||
|
||||
addInitialDataToCache();
|
||||
// GetCategories();
|
||||
}
|
||||
|
||||
Future<void> addInitialDataToCache() async{
|
||||
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
|
||||
//Insert Initial Entries
|
||||
for(Category element in InitialData.getCategories(username)){
|
||||
await UserOperations.addCategory(element.name, element.color, element.productive,bulk: true);
|
||||
}
|
||||
|
||||
for(TaskType element in InitialData.getTaskTypes(username)){
|
||||
await UserOperations.addTaskType(element.name, element.category, bulk: true);
|
||||
// Map<String,Object> data = {
|
||||
// TaskType.colName: element.name,
|
||||
// TaskType.colCategory: element.category
|
||||
// };
|
||||
// await cacheDb.insert('TaskTypes', data);
|
||||
}
|
||||
|
||||
UserOperations.executeQueries();
|
||||
|
||||
}
|
||||
|
||||
void onCacheDatabaseUpgrade(Database db, int oldVersion, int newVersion) async {
|
||||
//ValidateCacheDB();
|
||||
print('Upgrading CacheDB from ver.$oldVersion to ver.$newVersion');
|
||||
}
|
||||
|
||||
|
||||
Future<List<Category>> GetCategories(bool forceOffline) async{
|
||||
List<Category> _categories = [];
|
||||
if(offline || forceOffline){
|
||||
//Retreive from cacheDB
|
||||
|
||||
}else{
|
||||
//Check if server got updated, If not go for cache
|
||||
var android_id = await Settings.UUID();
|
||||
|
||||
//Validate device_id to check updates
|
||||
|
||||
bool catsUpdated = true;
|
||||
try{
|
||||
http.Response update_response = (await http.post(
|
||||
Uri.parse('http://161.97.127.136/task_tracker/check_update.php'),
|
||||
body: <String, String>{"username": username, "device_id":android_id??'n/a'}));
|
||||
final data = update_response.body.split(',');
|
||||
catsUpdated = data[0] == '1';
|
||||
}catch(e){
|
||||
print(e);
|
||||
}
|
||||
|
||||
print("Need to update : ${!catsUpdated}");
|
||||
|
||||
//Update CacheDB
|
||||
if(!catsUpdated){
|
||||
await UpdateCategoriesFromServer();
|
||||
}
|
||||
}
|
||||
|
||||
List<Map> cats = await cacheDb.query('Categories');
|
||||
print(cats.length);
|
||||
for(Map element in cats){
|
||||
String? catName = element[Category.colName].toString();
|
||||
String? catColor = element[Category.colColor].toString();
|
||||
String? catProductive = element[Category.colProductive].toString();
|
||||
if(catName==null || catColor==null || catProductive==null){
|
||||
print("Something is null!");
|
||||
print("name:{$catName}, color:{$catColor}, prod:{$Category.colProductive}");
|
||||
continue;
|
||||
}
|
||||
print("name:{$catName}, color:{$catColor}, prod:{$catProductive}");
|
||||
_categories.add(Category(username + catName, catName, catColor, ParseBool(catProductive)));
|
||||
}
|
||||
categories = _categories;
|
||||
return categories;
|
||||
}
|
||||
|
||||
Future<void> UpdateCategoriesFromServer() async{
|
||||
print("Updating Categories");
|
||||
try {
|
||||
http.Response response = (await http.post(
|
||||
Uri.parse('http://161.97.127.136/task_tracker/get_categories.php'),
|
||||
body: <String, String>{
|
||||
"username": username,
|
||||
"device_id": await Settings.UUID() ?? 'n/a'
|
||||
}));
|
||||
|
||||
print(response.body);
|
||||
List<String> data = response.body.split("<td>");
|
||||
data.forEach((value) async {
|
||||
Map<String, dynamic> cat = jsonDecode(value);
|
||||
//print(catData);
|
||||
await cacheDb.rawInsert(
|
||||
"INSERT OR REPLACE INTO Categories (${Category.colCatId},${Category
|
||||
.colName},${Category.colProductive},${Category.colColor}) "
|
||||
"VALUES ('${cat['category_id']}','${cat['name']}',${cat['productive']},'${cat['color']}') ");
|
||||
});
|
||||
}catch(e){
|
||||
offline=true;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<TaskType>> GetTaskTypes(bool forceOffline) async{
|
||||
List<TaskType> _taskTypes = [];
|
||||
if(offline || forceOffline){
|
||||
//Retreive from cacheDB
|
||||
|
||||
}else{
|
||||
//Check if server got updated, If not go for cache
|
||||
var android_id = await Settings.UUID();
|
||||
|
||||
bool updated =true;
|
||||
try{
|
||||
//Validate device_id to check updates
|
||||
http.Response update_response = (await http.post(
|
||||
Uri.parse('http://161.97.127.136/task_tracker/check_update.php'),
|
||||
body: <String, String>{"username": username, "device_id":android_id??'n/a'}));
|
||||
final data = update_response.body.split(',');
|
||||
updated = data[1] == '1';
|
||||
}catch(e){
|
||||
print(e);
|
||||
}
|
||||
|
||||
print("Need to update : ${!updated}");
|
||||
|
||||
//Update CacheDB
|
||||
if(!updated){
|
||||
await UpdateTaskTypesFromServer();
|
||||
}
|
||||
}
|
||||
|
||||
List<Map> cats = await cacheDb.query('TaskTypes');
|
||||
print(cats.length);
|
||||
for(Map element in cats){
|
||||
String? id = element[TaskType.colId].toString();
|
||||
String? name = element[TaskType.colName].toString();
|
||||
String? category = element[TaskType.colCategory].toString();
|
||||
Category? cat = await getCatFromId(category);
|
||||
if(id==null || name==null || category==null){
|
||||
print("Something is null!");
|
||||
print("name:{$name}, cat:{$category}, prod:{$id}");
|
||||
continue;
|
||||
}
|
||||
print("name:{$name}, cat:{$category}, prod:{$id}");
|
||||
_taskTypes.add(TaskType(id,name,category,cat));
|
||||
}
|
||||
taskTypes = _taskTypes;
|
||||
return taskTypes;
|
||||
}
|
||||
|
||||
Future<void> UpdateTaskTypesFromServer() async{
|
||||
print("Updating TaskTypes");
|
||||
try {
|
||||
http.Response response = (await http.post(
|
||||
Uri.parse('http://161.97.127.136/task_tracker/get_taskTypes.php'),
|
||||
body: <String, String>{
|
||||
"username": username,
|
||||
"device_id": await Settings.UUID() ?? 'n/a'
|
||||
}));
|
||||
|
||||
print(response.body);
|
||||
List<String> data = response.body.split("<td>");
|
||||
data.forEach((value) async {
|
||||
Map<String, dynamic> cat = jsonDecode(value);
|
||||
//print(catData);
|
||||
await cacheDb.rawInsert(
|
||||
"INSERT OR REPLACE INTO TaskTypes (${TaskType.colId},${TaskType
|
||||
.colName},${TaskType.colCategory}) "
|
||||
"VALUES ('${cat['id']}','${cat['name']}',${cat['category']}) ");
|
||||
});
|
||||
}catch(e){
|
||||
offline=true;
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<TaskType>> GetActivities(bool forceOffline) async{
|
||||
List<Activity> _activities = [];
|
||||
if(offline || forceOffline){
|
||||
//Retreive from cacheDB
|
||||
|
||||
}else{
|
||||
//Check if server got updated, If not go for cache
|
||||
var android_id = await Settings.UUID();
|
||||
|
||||
bool updated =true;
|
||||
try{
|
||||
//Validate device_id to check updates
|
||||
http.Response update_response = (await http.post(
|
||||
Uri.parse('http://161.97.127.136/task_tracker/check_update.php'),
|
||||
body: <String, String>{"username": username, "device_id":android_id??'n/a'}));
|
||||
final data = update_response.body.split(',');
|
||||
updated = data[2] == '1';
|
||||
}catch(e){
|
||||
print(e);
|
||||
}
|
||||
|
||||
print("Need to update activities : ${!updated}");
|
||||
|
||||
//Update CacheDB
|
||||
if(!updated){
|
||||
await UpdateActivitiesFromServer();
|
||||
}
|
||||
}
|
||||
|
||||
List<Map> cats = await cacheDb.query('Activities');
|
||||
print(cats.length);
|
||||
for(Map element in cats){
|
||||
String? type = element[Activity.colType].toString();
|
||||
String? startTime = element[Activity.colStartTime].toString();
|
||||
String? endTime = element[Activity.colStartTime].toString();
|
||||
TaskType? taskType = await getTaskFromId(type);
|
||||
if(type==null || startTime==null || endTime==null || taskType==null){
|
||||
print("Something is null!");
|
||||
print("TaskType:{$type}, Start Time:{$startTime}, endTime:{$endTime}");
|
||||
continue;
|
||||
}
|
||||
print("TaskType:{$type}, Start Time:{$startTime}, endTime:{$endTime}");
|
||||
_activities.add(Activity(taskType, DateTime.parse(startTime), DateTime.parse(endTime)));
|
||||
}
|
||||
activities = _activities;
|
||||
return taskTypes;
|
||||
}
|
||||
|
||||
Future<void> UpdateActivitiesFromServer() async{
|
||||
print("Updating TaskTypes");
|
||||
try {
|
||||
http.Response response = (await http.post(
|
||||
Uri.parse('http://161.97.127.136/task_tracker/get_activities.php'),
|
||||
body: <String, String>{
|
||||
"username": username,
|
||||
"device_id": await Settings.UUID() ?? 'n/a'
|
||||
}));
|
||||
|
||||
print(response.body);
|
||||
List<String> data = response.body.split("<td>");
|
||||
data.forEach((value) async {
|
||||
Map<String, dynamic> cat = jsonDecode(value);
|
||||
//print(catData);
|
||||
await cacheDb.rawInsert(
|
||||
"INSERT OR REPLACE INTO Activities (${Activity.colType}, ${Activity.colStartTime}, ${Activity.colEndTime}) "
|
||||
"VALUES ('${cat['type']}', '${cat['sTime']}','${cat['eTime']}') ");
|
||||
});
|
||||
}catch(e){
|
||||
offline=true;
|
||||
}
|
||||
}
|
||||
|
||||
Future<TaskType?> getTaskFromId(String taskId) async{
|
||||
// await GetTaskTypes(false);
|
||||
TaskType? cat = null;
|
||||
taskTypes.forEach((element) async{
|
||||
if(element.id == taskId){
|
||||
cat= element;
|
||||
|
||||
cat?.cat = await getCatFromId((cat?.category ?? ''));
|
||||
}
|
||||
});
|
||||
|
||||
return cat;
|
||||
}
|
||||
|
||||
Future<Category?> getCatFromId(String catId) async{
|
||||
// await GetTaskTypes(false);
|
||||
Category? cat = null;
|
||||
categories.forEach((element) {
|
||||
if(element.category_id == catId){
|
||||
cat= element;
|
||||
}
|
||||
});
|
||||
|
||||
return cat;
|
||||
}
|
||||
|
||||
|
||||
//Helpers
|
||||
class Helpers {
|
||||
Future<String?> _getId() async {
|
||||
var deviceInfo = DeviceInfoPlugin();
|
||||
if (Platform.isIOS) { // import 'dart:io'
|
||||
var iosDeviceInfo = await deviceInfo.iosInfo;
|
||||
return iosDeviceInfo.identifierForVendor; // unique ID on iOS
|
||||
} else {
|
||||
var androidDeviceInfo = await deviceInfo.androidInfo;
|
||||
return androidDeviceInfo.androidId; // unique ID on Android
|
||||
}
|
||||
}
|
||||
}
|
||||
bool ParseBool(obj){
|
||||
return obj.toString().toLowerCase()=="true" || obj.toString()=="1";
|
||||
}
|
||||
|
||||
|
||||
class UserOperations{
|
||||
static Future<void> addCategory(String name, String color, bool productive, {bool bulk = false}) async{
|
||||
Map<String,String> queryBody= <String,String>{
|
||||
'username': username,
|
||||
'device_id': await Settings.UUID() ?? 'n/a',
|
||||
'name' : name,
|
||||
'color':color,
|
||||
'productive': productive ? '1':'0'
|
||||
};
|
||||
//Add Query
|
||||
Map<String,Object> query = {
|
||||
Queries.colLink: 'add_category',
|
||||
Queries.colData: jsonEncode(queryBody)
|
||||
};
|
||||
|
||||
print("adding new query ${query[Queries.colLink]} : ${jsonEncode(queryBody)}");
|
||||
|
||||
await cacheDb.insert('Queries', query);
|
||||
|
||||
//update Cache
|
||||
Map<String,Object> data = {
|
||||
Category.colCatId: username+name,
|
||||
Category.colName: name,
|
||||
Category.colColor: color,
|
||||
Category.colProductive: productive
|
||||
};
|
||||
await cacheDb.insert('Categories', data);
|
||||
|
||||
await GetCategories(true);
|
||||
if(!bulk){
|
||||
//Add to server and refresh Cache
|
||||
await executeQueries();
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> addTaskType(String name, String category, {bool bulk = false}) async{
|
||||
Map<String,String> queryBody= <String,String>{
|
||||
'id':username+name,
|
||||
'username': username,
|
||||
'device_id': await Settings.UUID() ?? 'n/a',
|
||||
'name' : name,
|
||||
'category': username + category
|
||||
};
|
||||
//Add Query
|
||||
Map<String,Object> query = {
|
||||
Queries.colLink: 'add_taskType',
|
||||
Queries.colData: jsonEncode(queryBody)
|
||||
};
|
||||
|
||||
print("adding new query ${query[Queries.colLink]} : ${jsonEncode(queryBody)}");
|
||||
|
||||
await cacheDb.insert('Queries', query);
|
||||
|
||||
//update Cache
|
||||
Map<String,Object> data = {
|
||||
TaskType.colId: username+name,
|
||||
Category.colName: name,
|
||||
Category.colCatId: username + category
|
||||
};
|
||||
await cacheDb.insert('TaskTypes', data);
|
||||
await GetTaskTypes(true);
|
||||
if(!bulk){
|
||||
//Add to server and refresh Cache
|
||||
await executeQueries();
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> deleteTask(String name,{bulk=false}) async{
|
||||
Map<String,String> queryBody= <String,String>{
|
||||
'id':username+name,
|
||||
'username': username,
|
||||
'device_id': await Settings.UUID() ?? 'n/a',
|
||||
};
|
||||
//Add Query
|
||||
Map<String,Object> query = {
|
||||
Queries.colLink: 'delete_taskType',
|
||||
Queries.colData: jsonEncode(queryBody)
|
||||
};
|
||||
|
||||
print("adding new query ${query[Queries.colLink]} : ${jsonEncode(queryBody)}");
|
||||
|
||||
await cacheDb.insert('Queries', query);
|
||||
|
||||
//update Cache
|
||||
Map<String,Object> data = {
|
||||
TaskType.colId: username+name,
|
||||
Category.colName: name,
|
||||
};
|
||||
await cacheDb.rawDelete("DELETE FROM TaskTypes WHERE id='${username+name}'");
|
||||
await GetTaskTypes(true);
|
||||
//Add to server and refresh Cache
|
||||
|
||||
if(!bulk) {
|
||||
await executeQueries();
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> deleteCategory(String name,{bulk=false}) async{
|
||||
Map<String,String> queryBody= <String,String>{
|
||||
'id':username+name,
|
||||
'username': username,
|
||||
'device_id': await Settings.UUID() ?? 'n/a',
|
||||
};
|
||||
//Add Query
|
||||
Map<String,Object> query = {
|
||||
Queries.colLink: 'delete_category',
|
||||
Queries.colData: jsonEncode(queryBody)
|
||||
};
|
||||
|
||||
print("adding new query ${query[Queries.colLink]} : ${jsonEncode(queryBody)}");
|
||||
|
||||
await cacheDb.insert('Queries', query);
|
||||
|
||||
//update Cache
|
||||
Map<String,Object> data = {
|
||||
TaskType.colId: username+name,
|
||||
Category.colName: name,
|
||||
};
|
||||
await cacheDb.rawDelete("DELETE FROM Categories WHERE ${Category.colCatId}='${username+name}'");
|
||||
await GetCategories(true);
|
||||
//Add to server and refresh Cache
|
||||
|
||||
if(!bulk) {
|
||||
await executeQueries();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Future<void> executeQueries() async{
|
||||
if(offline){
|
||||
print("Cannot executre queries, Offline!");
|
||||
return;
|
||||
}
|
||||
|
||||
List<Map<String,Object?>> queries = await cacheDb.query('Queries');
|
||||
|
||||
for(Map<String,Object?> element in queries){
|
||||
int id = int.parse(element['id'].toString());
|
||||
String? file = element[Queries.colLink].toString();
|
||||
String? data = element[Queries.colData].toString();
|
||||
if(file==null || data==null){
|
||||
print("Null query, Ignoring...");
|
||||
continue;
|
||||
}
|
||||
print("Query[\n file:$file, \ndata:$data]");
|
||||
|
||||
//Execute the http here
|
||||
Map<String, dynamic> body = jsonDecode(data);
|
||||
try {
|
||||
http.Response queryResponse = (await http.post(
|
||||
Uri.parse('http://161.97.127.136/task_tracker/$file.php'),
|
||||
body: body));
|
||||
print("Query executed : Results{${queryResponse.body}");
|
||||
if (queryResponse.body.toLowerCase().contains("success")) {
|
||||
await cacheDb.rawDelete('DELETE FROM Queries WHERE id=$id');
|
||||
}
|
||||
offline=false;
|
||||
}catch(e){
|
||||
offline=true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
513
lib/Welcome.dart
Normal file
513
lib/Welcome.dart
Normal file
@@ -0,0 +1,513 @@
|
||||
import 'dart:ui';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'User.dart' as Users;
|
||||
import 'package:http/http.dart' as http;
|
||||
class WelcomePage extends StatefulWidget {
|
||||
const WelcomePage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_WelcomePageState createState() => _WelcomePageState();
|
||||
}
|
||||
|
||||
class _WelcomePageState extends State<WelcomePage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
body: Container(
|
||||
color: Colors.pink,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// Container(
|
||||
// padding: EdgeInsets.all(20),
|
||||
// alignment: Alignment.centerLeft,
|
||||
// child: Text(
|
||||
// 'WELCOME',
|
||||
// style: TextStyle(fontSize: 40, fontWeight: FontWeight.bold),
|
||||
// textAlign: TextAlign.left,
|
||||
// )),
|
||||
Container(
|
||||
height: 300,
|
||||
padding: EdgeInsets.fromLTRB(0, 100, 0, 0),
|
||||
child: Expanded(
|
||||
child: Container(
|
||||
child: Image(image: AssetImage('images/Launch.png')))),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("Let's get started",
|
||||
style: TextStyle(
|
||||
fontSize: 30, fontWeight: FontWeight.bold)),
|
||||
Divider(),
|
||||
Text(
|
||||
"Task Tracker is an App where you can track your daily activities, Analyze them and plan a better tomorrow.")
|
||||
],
|
||||
)),
|
||||
Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
InkWell(
|
||||
child: Text(''),
|
||||
// onTap: () {
|
||||
// Navigator.of(context).pushReplacementNamed('/');
|
||||
// },
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(MaterialPageRoute(
|
||||
builder: (context) => const SignInPage()));
|
||||
},
|
||||
child: Text('Next', style: TextStyle(fontSize: 20)))
|
||||
],
|
||||
))
|
||||
],
|
||||
)),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
class SignInPage extends StatefulWidget {
|
||||
const SignInPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SignInPageState createState() => _SignInPageState();
|
||||
}
|
||||
|
||||
class _SignInPageState extends State<SignInPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
body: Container(
|
||||
color: Colors.deepPurpleAccent,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Container(padding: EdgeInsets.fromLTRB(0, 100, 0, 0),
|
||||
height: 400,
|
||||
child: Expanded(
|
||||
child: Container(
|
||||
child:
|
||||
Image(image: AssetImage('images/signin.png'))),
|
||||
)),
|
||||
Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("Sign in to stay connected",
|
||||
style: TextStyle(
|
||||
fontSize: 30,
|
||||
fontWeight: FontWeight.bold)),
|
||||
Divider(),
|
||||
Text(
|
||||
"Sign in and enjoy the flawless connection between all your devices. You can track your day from any device and keep it together.")
|
||||
],
|
||||
)),
|
||||
Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.red),
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const offlineLoginPage()));
|
||||
},
|
||||
child: Text('Use Offline',
|
||||
style: TextStyle(fontSize: 20))),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const onlineLoginPage()));
|
||||
},
|
||||
child: Text('Next',
|
||||
style: TextStyle(fontSize: 20)))
|
||||
],
|
||||
))
|
||||
]))));
|
||||
}
|
||||
}
|
||||
|
||||
class onlineLoginPage extends StatefulWidget {
|
||||
const onlineLoginPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_onlineLoginPageState createState() => _onlineLoginPageState();
|
||||
}
|
||||
|
||||
class _onlineLoginPageState extends State<onlineLoginPage>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
final usernameController = TextEditingController();
|
||||
final passwordController = TextEditingController();
|
||||
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(vsync: this, length: 2);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
body: Container(
|
||||
color: Colors.purpleAccent,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// Container(
|
||||
// padding: EdgeInsets.all(20),
|
||||
// alignment: Alignment.centerLeft,
|
||||
// child: Text(
|
||||
// 'Sign in online',
|
||||
// style: TextStyle(
|
||||
// fontSize: 40, fontWeight: FontWeight.bold),
|
||||
// textAlign: TextAlign.left,
|
||||
// ),
|
||||
// ),
|
||||
Container(
|
||||
child: Expanded(
|
||||
child: Container(
|
||||
child:
|
||||
Image(image: AssetImage('images/signin.png'))),
|
||||
)),
|
||||
Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Column(children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
color: Colors.purple),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
indicator: BoxDecoration(
|
||||
color: Colors.blueAccent,
|
||||
borderRadius:
|
||||
BorderRadius.circular(10)),
|
||||
tabs: [
|
||||
TabItem('Our Account'),
|
||||
TabItem('OAuth')
|
||||
],
|
||||
))),
|
||||
Divider(
|
||||
height: 30,
|
||||
),
|
||||
Container(
|
||||
height: 320,
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
BorderRadius.circular(10),
|
||||
color: Colors.purple),
|
||||
child: Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
10, 10, 10, 0),
|
||||
child: Text(
|
||||
'Username',
|
||||
style:
|
||||
TextStyle(fontSize: 16),
|
||||
)),
|
||||
Container(
|
||||
height: 70,
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Expanded(
|
||||
child: Container(
|
||||
child: TextField(
|
||||
controller: usernameController,
|
||||
autocorrect: false,
|
||||
style: TextStyle(
|
||||
color: Colors.black,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Username',
|
||||
filled: true,
|
||||
fillColor:
|
||||
Colors.white,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius:
|
||||
BorderRadius
|
||||
.circular(
|
||||
10))),
|
||||
),
|
||||
),
|
||||
)),
|
||||
Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
10, 10, 10, 0),
|
||||
child: Text(
|
||||
'Password',
|
||||
style:
|
||||
TextStyle(fontSize: 16),
|
||||
)),
|
||||
Container(
|
||||
height: 70,
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Expanded(
|
||||
child: Container(
|
||||
child: TextField(
|
||||
controller: passwordController,
|
||||
obscureText: true,
|
||||
autocorrect: false,
|
||||
enableSuggestions: false,
|
||||
style: TextStyle(
|
||||
fontWeight:
|
||||
FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Password',
|
||||
filled: true,
|
||||
fillColor:
|
||||
Colors.white,
|
||||
border: OutlineInputBorder(
|
||||
borderRadius:
|
||||
BorderRadius
|
||||
.circular(
|
||||
10))),
|
||||
),
|
||||
),
|
||||
)),
|
||||
Container(
|
||||
width: 200,
|
||||
padding: EdgeInsets.all(20),
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton
|
||||
.styleFrom(
|
||||
primary:
|
||||
Colors.green),
|
||||
onPressed: () {
|
||||
login();
|
||||
},
|
||||
child: Text(
|
||||
'Login',
|
||||
style: TextStyle(
|
||||
fontSize: 20),
|
||||
)))
|
||||
])),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
BorderRadius.circular(10),
|
||||
color: Colors.purple),
|
||||
child: Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Container(
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.green,
|
||||
),
|
||||
onPressed: (){}, child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.android),
|
||||
SizedBox(width: 20,),
|
||||
Text("Sign with Google", style: TextStyle(fontSize: 20))
|
||||
],)),
|
||||
),
|
||||
Divider(height: 50,),
|
||||
Container(
|
||||
padding: EdgeInsets.all(50),
|
||||
child:Text("New OAuth Sign in methods are on the way...")
|
||||
)
|
||||
|
||||
]))
|
||||
],
|
||||
),
|
||||
)
|
||||
])),
|
||||
Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.red),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text('Back',
|
||||
style: TextStyle(fontSize: 20))),
|
||||
SizedBox()
|
||||
],
|
||||
))
|
||||
]))));
|
||||
}
|
||||
|
||||
Widget TabItem(String text) {
|
||||
return Text(text, style: TextStyle(fontSize: 20, color: Colors.white));
|
||||
}
|
||||
|
||||
Future<void> login() async {
|
||||
if(usernameController.text.length < 3 || passwordController.text.length < 3){
|
||||
showAlertDialog(context, "Failed", "Please enter a valid username and password");
|
||||
return;
|
||||
}
|
||||
|
||||
http.Response loginResponse = await Users.login(usernameController.text, passwordController.text);
|
||||
print(loginResponse.body);
|
||||
if(loginResponse.body.toLowerCase().contains("success")){
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
prefs.setString("username", usernameController.text);
|
||||
prefs.setString("password", passwordController.text);
|
||||
Navigator.of(context).pushNamedAndRemoveUntil('/splash', (route) => false);
|
||||
}else{
|
||||
showAlertDialog(context, "Failed to login", "There was an error trying to authorize you in servers.");
|
||||
}
|
||||
}
|
||||
}
|
||||
showAlertDialog(BuildContext context, String title, String message) {
|
||||
|
||||
// set up the button
|
||||
Widget okButton = TextButton(
|
||||
child: Text("OK"),
|
||||
onPressed: () { Navigator.of(context).pop(); },
|
||||
);
|
||||
|
||||
// set up the AlertDialog
|
||||
AlertDialog alert = AlertDialog(
|
||||
title: Text(title),
|
||||
content: Text(message),
|
||||
actions: [
|
||||
okButton,
|
||||
],
|
||||
);
|
||||
|
||||
// show the dialog
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return alert;
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
class offlineLoginPage extends StatefulWidget {
|
||||
const offlineLoginPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_offlineLoginPageState createState() => _offlineLoginPageState();
|
||||
}
|
||||
|
||||
class _offlineLoginPageState extends State<offlineLoginPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
body: Container(
|
||||
color: Colors.deepOrange,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// Container(
|
||||
// padding: EdgeInsets.all(20),
|
||||
// alignment: Alignment.centerLeft,
|
||||
// child: Text(
|
||||
// 'Offline Mode',
|
||||
// style: TextStyle(fontSize: 40, fontWeight: FontWeight.bold),
|
||||
// textAlign: TextAlign.left,
|
||||
// )),
|
||||
Container(
|
||||
// padding: EdgeInsets.all(50),
|
||||
child: Expanded(
|
||||
child: Container(
|
||||
height: 400,
|
||||
child: Image(
|
||||
image: AssetImage('images/offline.png')))),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Divider(
|
||||
height: 30,
|
||||
),
|
||||
Text("Enter your name to continue",
|
||||
style: TextStyle(
|
||||
fontSize: 30,
|
||||
fontWeight: FontWeight.bold)),
|
||||
SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
hintText: 'ex: John doe',
|
||||
focusColor: Colors.white,
|
||||
border: OutlineInputBorder()),
|
||||
),
|
||||
Divider(
|
||||
height: 30,
|
||||
),
|
||||
Text(
|
||||
'Note: \nYou cannot use seemless multiple devices support with offline mode. \nYou can sign to online account anytime in settings page')
|
||||
],
|
||||
)),
|
||||
Container(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.green),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text('Sign online',
|
||||
style: TextStyle(fontSize: 20))),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
const SignInPage()));
|
||||
},
|
||||
child: Text('Continue',
|
||||
style: TextStyle(fontSize: 20)))
|
||||
],
|
||||
))
|
||||
]))));
|
||||
}
|
||||
}
|
||||
298
lib/main.dart
Normal file
298
lib/main.dart
Normal file
@@ -0,0 +1,298 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tasktracker/Categories.dart';
|
||||
import 'package:tasktracker/Welcome.dart';
|
||||
import 'package:tasktracker/splash.dart';
|
||||
import 'package:wakelock/wakelock.dart';
|
||||
import 'package:charts_flutter/flutter.dart' as charts;
|
||||
import 'NewTask.dart';
|
||||
import 'newActivity.dart';
|
||||
import 'Tasks.dart';
|
||||
import 'User.dart' as User;
|
||||
|
||||
|
||||
extension HexColor on Color {
|
||||
/// String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#".
|
||||
static Color fromHex(String hexString) {
|
||||
final buffer = StringBuffer();
|
||||
if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
|
||||
buffer.write(hexString.replaceFirst('#', ''));
|
||||
return Color(int.parse(buffer.toString(), radix: 16));
|
||||
}
|
||||
|
||||
/// Prefixes a hash sign if [leadingHashSign] is set to `true` (default is `true`).
|
||||
String toHex({bool leadingHashSign = true}) => '${leadingHashSign ? '#' : ''}'
|
||||
'${alpha.toRadixString(16).padLeft(2, '0')}'
|
||||
'${red.toRadixString(16).padLeft(2, '0')}'
|
||||
'${green.toRadixString(16).padLeft(2, '0')}'
|
||||
'${blue.toRadixString(16).padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
// To keep the screen on:
|
||||
final List<PopulationData> data = [
|
||||
PopulationData(
|
||||
name: "Rocket League",
|
||||
value: 45,
|
||||
barColor: charts.ColorUtil.fromDartColor(Colors.blue)),
|
||||
PopulationData(
|
||||
name: "CS:GO",
|
||||
value: 15,
|
||||
barColor: charts.ColorUtil.fromDartColor(Colors.yellow)),
|
||||
PopulationData(
|
||||
name: "Halo",
|
||||
value: 10,
|
||||
barColor: charts.ColorUtil.fromDartColor(Colors.grey)),
|
||||
PopulationData(
|
||||
name: "SneakyPeaky",
|
||||
value: 30,
|
||||
barColor: charts.ColorUtil.fromDartColor(Colors.red)),
|
||||
];
|
||||
|
||||
void main() {
|
||||
Wakelock.enable(); // or Wakelock.toggle(on: true);
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({Key? key}) : super(key: key);
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Flutter Demo',
|
||||
theme: ThemeData(
|
||||
accentColor: Colors.redAccent,
|
||||
brightness: Brightness.dark,
|
||||
primaryColor: Colors.amber,
|
||||
fontFamily: 'Noto-Sans'),
|
||||
//home: const MyHomePage(),
|
||||
initialRoute: '/splash',
|
||||
routes:{
|
||||
'/splash':(context)=> const SplashScreen(),
|
||||
'/welcome':(context)=> const WelcomePage(),
|
||||
'/':(context) => const MyHomePage(),
|
||||
'/Tasks':(context)=> const Tasks(),
|
||||
'/Categories':(context)=>const Categories()
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MyHomePage> createState() => _MyHomePageState();
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
List<charts.Series<PopulationData, String>> series = [
|
||||
charts.Series(
|
||||
id: "Subscribers",
|
||||
data: data,
|
||||
domainFn: (PopulationData series, _) => series.name,
|
||||
measureFn: (PopulationData series, _) => series.value,
|
||||
colorFn: (PopulationData series, _) => series.barColor)
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
|
||||
showOfflineSnack();
|
||||
}
|
||||
|
||||
void showOfflineSnack() async{
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
if(User.offline){
|
||||
const SnackBar offlineSnack = SnackBar(content: Text('Offline'),duration: Duration(seconds: 100),);
|
||||
ScaffoldMessenger.of(context).showSnackBar(offlineSnack);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
floatingActionButton: FloatingActionButton.extended(onPressed: (){
|
||||
Navigator.of(context).push(MaterialPageRoute(builder: (context)=> NewActivity()));
|
||||
},
|
||||
label: Text("New Activity"),
|
||||
icon: Icon(Icons.add)
|
||||
),
|
||||
appBar: AppBar(title: Row(children:[Icon(Icons.article_outlined, color: Theme.of(context).primaryColor),SizedBox(width: 10),Text('Summary')])),
|
||||
drawer: navDrawer(context,0),
|
||||
body: SafeArea(
|
||||
child: Container(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
height: 300,
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Card(
|
||||
elevation: 8,
|
||||
shadowColor: Colors.blueGrey,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: Column(
|
||||
children: [
|
||||
cardTitle('Daily Average'),
|
||||
Expanded(
|
||||
child: charts.BarChart(
|
||||
series,
|
||||
animate: true,
|
||||
barRendererDecorator:
|
||||
new charts.BarLabelDecorator(
|
||||
labelPosition:
|
||||
charts.BarLabelPosition.inside,
|
||||
labelPadding: 10,
|
||||
labelAnchor:
|
||||
charts.BarLabelAnchor.middle),
|
||||
))
|
||||
],
|
||||
)))),
|
||||
Container(
|
||||
height: 300,
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Card(
|
||||
elevation: 8,
|
||||
shadowColor: Colors.green,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(8),
|
||||
child: Column(
|
||||
children: [
|
||||
cardTitle('Weekly Average'),
|
||||
Expanded(
|
||||
child: charts.BarChart(
|
||||
series,
|
||||
animate: true,
|
||||
barRendererDecorator:
|
||||
new charts.BarLabelDecorator(
|
||||
labelPosition:
|
||||
charts.BarLabelPosition.inside,
|
||||
labelPadding: 10,
|
||||
labelAnchor:
|
||||
charts.BarLabelAnchor.middle),
|
||||
))
|
||||
],
|
||||
))))
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Widget cardTitle(String title) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children:[
|
||||
Padding(padding: EdgeInsets.all(20),child:Text(title,
|
||||
style: TextStyle(fontWeight: FontWeight.bold))),
|
||||
MaterialButton(onPressed: (){},child:moreButton())]);
|
||||
}
|
||||
|
||||
Widget moreButton(){
|
||||
return MaterialButton(
|
||||
onPressed: (){
|
||||
|
||||
},
|
||||
color: Colors.green,
|
||||
child:Row(
|
||||
children: [
|
||||
Text('More'),Icon(Icons.keyboard_arrow_right)
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
class PopulationData {
|
||||
String name;
|
||||
int value;
|
||||
charts.Color barColor;
|
||||
PopulationData(
|
||||
{required this.name, required this.value, required this.barColor});
|
||||
}
|
||||
|
||||
Drawer navDrawer(BuildContext context, int pageIndex){
|
||||
return Drawer(
|
||||
child: ListView(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children:[Text("Time Tracker",
|
||||
style: TextStyle(
|
||||
fontSize: 25,
|
||||
color: Theme.of(context).accentColor,
|
||||
fontWeight: FontWeight.bold)),
|
||||
Icon(Icons.more_time,size: 30,),
|
||||
])
|
||||
),
|
||||
Divider(),
|
||||
ListTile(
|
||||
selected: (pageIndex == 0),
|
||||
title: Text('Summary'),
|
||||
leading: Icon(Icons.article_outlined,color: Theme.of(context).primaryColor),
|
||||
onTap: () {
|
||||
if(pageIndex==0){return;}
|
||||
Navigator.of(context).pushReplacementNamed('/');
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
selected: (pageIndex == 1),
|
||||
title: Text('Analytics'),
|
||||
leading: Icon(Icons.analytics_outlined,color: Theme.of(context).primaryColor),
|
||||
onTap: () {
|
||||
if(pageIndex==1){return;}
|
||||
// Navigator.of(context).pushReplacementNamed('/');
|
||||
},
|
||||
),
|
||||
Divider(),
|
||||
ListTile(
|
||||
selected: (pageIndex == 2),
|
||||
title: Text('Activities'),
|
||||
leading: Icon(Icons.task,color: Theme.of(context).primaryColor),
|
||||
onTap: () {
|
||||
if(pageIndex==2){return;}
|
||||
Navigator.of(context).pushReplacementNamed('/Activities');
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
selected: (pageIndex == 3),
|
||||
title: Text('Task Types'),
|
||||
leading: Icon(Icons.task,color: Theme.of(context).primaryColor),
|
||||
onTap: () {
|
||||
if(pageIndex==3){return;}
|
||||
Navigator.of(context).pushReplacementNamed('/Tasks');
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
selected: (pageIndex == 4),
|
||||
title: Text('Categories'),
|
||||
leading: Icon(Icons.account_tree_outlined,color: Theme.of(context).primaryColor),
|
||||
onTap: () {
|
||||
if(pageIndex==4){return;}
|
||||
Navigator.of(context).pushReplacementNamed('/Categories');
|
||||
},
|
||||
),
|
||||
Divider(),
|
||||
ListTile(
|
||||
selected: (pageIndex == 5),
|
||||
title: Text('Settings'),
|
||||
leading: Icon(Icons.settings,color: Colors.blueGrey),
|
||||
onTap: () {
|
||||
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
selected: (pageIndex == 6),
|
||||
title: Text('About'),
|
||||
leading: Icon(Icons.help_outline_outlined),
|
||||
onTap: () {
|
||||
|
||||
},
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
210
lib/newActivity.dart
Normal file
210
lib/newActivity.dart
Normal file
@@ -0,0 +1,210 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'User.dart' as User;
|
||||
DateFormat dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
DateFormat durationFormat = DateFormat("HH:mm:ss");
|
||||
|
||||
class NewActivity extends StatefulWidget {
|
||||
const NewActivity({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_NewActivity createState() => _NewActivity();
|
||||
}
|
||||
|
||||
List<String> getActivitiesNames(){
|
||||
List<String> _cats = [];
|
||||
User.activities.forEach((element) {
|
||||
String name = element.taskType.name;
|
||||
_cats.add(name);
|
||||
});
|
||||
return _cats;
|
||||
}
|
||||
|
||||
class _NewActivity extends State<NewActivity> {
|
||||
String value = 'CS:GO';
|
||||
DateTime startTime = DateTime.now();
|
||||
DateTime endTime = DateTime.now().add(Duration(minutes: 30));
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('New Activity')),
|
||||
body: Container(
|
||||
height: MediaQuery.of(context).size.height,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 50, 20, 50),
|
||||
child: Column(
|
||||
children: [
|
||||
Column(children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Text('Task')),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blueGrey,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.grey, width: 2)),
|
||||
child: DropdownButton<String>(
|
||||
dropdownColor: Colors.blueGrey,
|
||||
iconSize: 30,
|
||||
elevation: 10,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
value: value,
|
||||
isExpanded: true,
|
||||
items: <String>[
|
||||
'Rocket League',
|
||||
'CS:GO',
|
||||
'HALO',
|
||||
'Unity',
|
||||
'Add new Task Type...'
|
||||
].map<DropdownMenuItem<String>>(
|
||||
(String value) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: value,
|
||||
child: Text(value),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (String? _value) {
|
||||
setState(() {
|
||||
value = _value!;
|
||||
});
|
||||
})),
|
||||
Container(
|
||||
child: Divider(
|
||||
height: 30,
|
||||
)),
|
||||
Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Text('Start Time')),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.grey, width: 2)),
|
||||
child: MaterialButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
DatePicker.showDateTimePicker(
|
||||
context,
|
||||
showTitleActions: true,
|
||||
onChanged: (date) {
|
||||
// print('change $date');
|
||||
}, onConfirm: (date) {
|
||||
setState(() {
|
||||
startTime = date;
|
||||
});
|
||||
},
|
||||
currentTime: startTime,
|
||||
locale: LocaleType.en);
|
||||
});
|
||||
},
|
||||
child: Text(
|
||||
dateFormat.format(startTime),
|
||||
style: TextStyle(
|
||||
color: Colors.blue)))),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.all(10),
|
||||
child: Text('Ended Time')),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 1),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: Colors.grey, width: 2)),
|
||||
child: MaterialButton(
|
||||
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
DatePicker.showDateTimePicker(
|
||||
context,
|
||||
showTitleActions: true,
|
||||
onChanged: (date) {
|
||||
// print('change $date');
|
||||
}, onConfirm: (date) {
|
||||
setState(() {
|
||||
endTime = date;
|
||||
});
|
||||
},
|
||||
currentTime: endTime,
|
||||
locale: LocaleType.en);
|
||||
});
|
||||
},
|
||||
child: Text(dateFormat.format(endTime),
|
||||
style: TextStyle(
|
||||
color: Colors.blue)))),
|
||||
SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
Text('Duration : ' +
|
||||
_printDuration(
|
||||
endTime.difference(startTime))),
|
||||
Divider(
|
||||
height: 30,
|
||||
),
|
||||
]),
|
||||
],
|
||||
))),
|
||||
Container(
|
||||
padding:
|
||||
EdgeInsets.symmetric(vertical: 10, horizontal: 20),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 5,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 0),
|
||||
child: ElevatedButton(
|
||||
|
||||
style:ElevatedButton.styleFrom(
|
||||
primary: Colors.red,
|
||||
shape: StadiumBorder()
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
Navigator.pop(context);
|
||||
});
|
||||
},
|
||||
child: Text('Back',
|
||||
style: TextStyle(fontSize: 20))))),
|
||||
Expanded(
|
||||
flex: 6,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 0),
|
||||
child: ElevatedButton(
|
||||
style:ElevatedButton.styleFrom(
|
||||
primary: Colors.green,
|
||||
shape: StadiumBorder()
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {});
|
||||
},
|
||||
child: Text('Add Entry',
|
||||
style: TextStyle(fontSize: 20))))),
|
||||
],
|
||||
))
|
||||
])));
|
||||
}
|
||||
}
|
||||
|
||||
String _printDuration(Duration duration) {
|
||||
String twoDigits(int n) => n.toString().padLeft(2, "0");
|
||||
String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60));
|
||||
String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60));
|
||||
return "${twoDigits(duration.inHours)}:$twoDigitMinutes:$twoDigitSeconds";
|
||||
}
|
||||
73
lib/splash.dart
Normal file
73
lib/splash.dart
Normal file
@@ -0,0 +1,73 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'User.dart' as Users;
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class SplashScreen extends StatefulWidget {
|
||||
const SplashScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_SplashScreenState createState() => _SplashScreenState();
|
||||
}
|
||||
|
||||
class _SplashScreenState extends State<SplashScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
super.initState();
|
||||
init();
|
||||
}
|
||||
|
||||
void init() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
// http.Response loginResponse = await Users.login('Test1', 'password');
|
||||
// print(loginResponse.body);
|
||||
|
||||
if (!prefs.containsKey("password") || !prefs.containsKey("username")) {
|
||||
Navigator.of(context).pushNamedAndRemoveUntil('/welcome', (route) => false);
|
||||
} else {
|
||||
try {
|
||||
http.Response loginResponse = await Users.login(
|
||||
prefs.getString("username") ?? '',
|
||||
prefs.getString("password") ?? '');
|
||||
print(loginResponse.body);
|
||||
if (loginResponse.body.toLowerCase().contains("success")) { //Login Success
|
||||
Continue();
|
||||
} else { //Login Failed
|
||||
LoginFailed();
|
||||
}
|
||||
} catch (error) { //Login Failed
|
||||
LoginFailed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LoginFailed() async{
|
||||
bool dbExist = await Users.cacheDbExist();
|
||||
if (dbExist) {
|
||||
print('cache Database exists, Lets go CACHE!');
|
||||
Continue();
|
||||
} else {
|
||||
Navigator.of(context).pushReplacementNamed('/welcome');
|
||||
}
|
||||
}
|
||||
|
||||
void Continue() async{
|
||||
await Users.initUserData();
|
||||
Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
color: Colors.purple,
|
||||
padding: EdgeInsets.all(80),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Image(image: AssetImage('images/logo.png')),
|
||||
// Text('Loading', style:TextStyle(color: Colors.grey, fontSize: 20,fontStyle: FontStyle.italic))
|
||||
]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user