Polished
This commit is contained in:
166
lib/main.dart
166
lib/main.dart
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
@@ -14,11 +16,10 @@ import 'newActivity.dart';
|
||||
import 'Tasks.dart';
|
||||
import 'Activities.dart';
|
||||
import 'User.dart' as User;
|
||||
import 'package:sn_progress_dialog/sn_progress_dialog.dart';
|
||||
import 'package:syncfusion_flutter_charts/charts.dart';
|
||||
|
||||
late ProgressDialog progressDialog;
|
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'Dialogs.dart';
|
||||
final GlobalKey<NavigatorState> navigatorKey = new GlobalKey<NavigatorState>();
|
||||
showAlertDialog(BuildContext context, String title, String message) {
|
||||
// set up the button
|
||||
Widget okButton = TextButton(
|
||||
@@ -73,27 +74,28 @@ class MyApp extends StatelessWidget {
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) => ChangeNotifierProvider(
|
||||
create: (context)=>ThemeProvider(),
|
||||
builder: (context, _){
|
||||
create: (context) => ThemeProvider(),
|
||||
builder: (context, _) {
|
||||
final themeProvider = Provider.of<ThemeProvider>(context);
|
||||
|
||||
return MaterialApp(
|
||||
title: 'Task Tracker',
|
||||
themeMode: themeProvider.themeMode,
|
||||
theme: ThemeData(accentColor: Colors.redAccent,brightness: Brightness.light, primaryColor: Colors.amber, fontFamily: 'Noto-Sans'),
|
||||
darkTheme: 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(),
|
||||
'/Activities': (context) => const Activities(),
|
||||
'/Settings':(context) => const SettingsPage()
|
||||
});
|
||||
});
|
||||
title: 'Task Tracker',
|
||||
themeMode: themeProvider.themeMode,
|
||||
theme: ThemeData(accentColor: Colors.redAccent, brightness: Brightness.light, primaryColor: Colors.amber, fontFamily: 'Noto-Sans'),
|
||||
darkTheme: ThemeData(accentColor: Colors.redAccent, brightness: Brightness.dark, primaryColor: Colors.amber, fontFamily: 'Noto-Sans'),
|
||||
navigatorKey: navigatorKey,
|
||||
//home: const SplashScreen(),
|
||||
initialRoute: '/',
|
||||
routes: {
|
||||
'/': (context) => const SplashScreen(),
|
||||
'/welcome': (context) => const WelcomePage(),
|
||||
'/home': (context) => const MyHomePage(),
|
||||
'/Tasks': (context) => const Tasks(),
|
||||
'/Categories': (context) => const Categories(),
|
||||
'/Activities': (context) => const Activities(),
|
||||
'/Settings': (context) => const SettingsPage()
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
List<String> days = [];
|
||||
@@ -135,24 +137,48 @@ class MyHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
var connectivitySub;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
// TODO: implement initState
|
||||
print("Im home!");
|
||||
init(context);
|
||||
super.initState();
|
||||
// User.refreshUserData().then((val) => LoadStats());
|
||||
// showOfflineSnack();
|
||||
print("Initializing refresh stream on main dart");
|
||||
LoadStats();
|
||||
// progressDialog = ProgressDialog(context: context);
|
||||
connectivitySub=Connectivity().onConnectivityChanged.listen((result) {
|
||||
if (this.mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
});
|
||||
|
||||
// User.progressDialog=progressDialog;
|
||||
}
|
||||
var refreshSub;
|
||||
void init(BuildContext context) async{
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
refreshSub = User.refreshStream.stream.listen((value) {
|
||||
print("Streaming refresh : $value");
|
||||
if(value){
|
||||
Dialogs.waiting("Syncing...");
|
||||
print("Opening progress dialog");
|
||||
}else{
|
||||
Dialogs.hide();
|
||||
print("Closing progress dialog");
|
||||
}
|
||||
});
|
||||
}
|
||||
@override
|
||||
void dispose() {
|
||||
// TODO: implement dispose
|
||||
super.dispose();
|
||||
connectivitySub?.cancel();
|
||||
}
|
||||
|
||||
void LoadStats() async {
|
||||
// return;
|
||||
|
||||
while (!User.userDataInitiated) {
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
}
|
||||
|
||||
DateFormat dFormat = DateFormat("MM/dd");
|
||||
Map<Category, int> catTimeMap = <Category, int>{};
|
||||
Map<Category, int> catBriefMap = <Category, int>{};
|
||||
@@ -163,7 +189,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
firstDay = null;
|
||||
lastDay = null;
|
||||
String lastDate = "";
|
||||
days=[];
|
||||
days = [];
|
||||
for (var element in User.activities) {
|
||||
if (lastDay == null) {
|
||||
lastDay = element.endTime;
|
||||
@@ -248,7 +274,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
Color barCol = HexColor.fromHex(key.color);
|
||||
dailyData.add(CatMapData(key.name, value, barCol));
|
||||
});
|
||||
dailyData.sort((a,b){
|
||||
dailyData.sort((a, b) {
|
||||
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
|
||||
});
|
||||
for (var element in days) {
|
||||
@@ -265,7 +291,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
taskTypesData.add(TaskTypeMapData(key.name, value, HexColor.fromHex(key.cat!.color)));
|
||||
});
|
||||
|
||||
taskTypesData.sort((a,b){
|
||||
taskTypesData.sort((a, b) {
|
||||
return a.time.compareTo(b.time);
|
||||
});
|
||||
|
||||
@@ -274,7 +300,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
Color barCol = HexColor.fromHex(key.color);
|
||||
catsData.add(CatMapData(key.name, value, barCol));
|
||||
});
|
||||
catsData.sort((a,b)=> a.time.compareTo(b.time));
|
||||
catsData.sort((a, b) => a.time.compareTo(b.time));
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -299,26 +325,46 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
},
|
||||
label: Text("New Activity"),
|
||||
icon: Icon(Icons.add)),
|
||||
appBar: AppBar(title: Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
appBar: AppBar(
|
||||
title: Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
Row(children: [Icon(Icons.article_outlined, color: Theme.of(context).primaryColor), SizedBox(width: 10), Text('Summary')]),
|
||||
Row(children: [
|
||||
InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
LoadStats();
|
||||
});
|
||||
},
|
||||
child: Icon(Icons.refresh, size: 30),
|
||||
)
|
||||
],)
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(children: [Icon(Icons.article_outlined, color: Theme.of(context).primaryColor), SizedBox(width: 10), Text('Summary')]),
|
||||
Row(
|
||||
children: [
|
||||
(User.offline)
|
||||
? Icon(Icons.signal_cellular_connected_no_internet_4_bar_outlined)
|
||||
: InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
LoadStats();
|
||||
});
|
||||
},
|
||||
child: Icon(Icons.refresh, size: 30),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
//Container(color: Colors.red,child: Text("Offline",style:TextStyle(fontSize: 5))),
|
||||
],
|
||||
)),
|
||||
drawer: navDrawer(context, 0),
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: (User.activities.isEmpty) ? Column(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center
|
||||
,children:[
|
||||
Expanded(flex: 1,child: Container(),),
|
||||
Expanded(flex: 2,child: Image(image: AssetImage('images/empty.png'))),
|
||||
Expanded(flex:2,child: Text("Add your first activity to access Summary",style: TextStyle(color: Colors.grey, fontStyle: FontStyle.italic),))
|
||||
]) :SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -397,11 +443,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
xValueMapper: (ProductivityMapData sales, _) => sales.day,
|
||||
yValueMapper: (ProductivityMapData sales, _) => sales.productivity,
|
||||
dataLabelMapper: (ProductivityMapData sales, _) => sales.productivity.toStringAsFixed(1) + "%",
|
||||
dataLabelSettings: DataLabelSettings(
|
||||
overflowMode: OverflowMode.hide,
|
||||
showZeroValue: false,
|
||||
isVisible: true
|
||||
),
|
||||
dataLabelSettings: DataLabelSettings(overflowMode: OverflowMode.hide, showZeroValue: false, isVisible: true),
|
||||
color: Colors.green)
|
||||
]),
|
||||
)
|
||||
@@ -602,7 +644,7 @@ Drawer navDrawer(BuildContext context, int pageIndex) {
|
||||
if (pageIndex == 0) {
|
||||
return;
|
||||
}
|
||||
Navigator.of(context).pushReplacementNamed('/');
|
||||
Navigator.of(context).pushReplacementNamed('/home');
|
||||
},
|
||||
),
|
||||
// ListTile(
|
||||
@@ -652,6 +694,18 @@ Drawer navDrawer(BuildContext context, int pageIndex) {
|
||||
},
|
||||
),
|
||||
Divider(),
|
||||
ListTile(
|
||||
selected: (pageIndex == 7),
|
||||
title: Text('TODO'),
|
||||
leading: Icon(Icons.check, color: Theme.of(context).primaryColor),
|
||||
onTap: () {
|
||||
if (pageIndex == 7) {
|
||||
return;
|
||||
}
|
||||
Navigator.of(context).pushReplacementNamed('/Todo');
|
||||
},
|
||||
),
|
||||
Divider(),
|
||||
ListTile(
|
||||
selected: (pageIndex == 5),
|
||||
title: Text('Settings'),
|
||||
@@ -667,7 +721,9 @@ Drawer navDrawer(BuildContext context, int pageIndex) {
|
||||
selected: (pageIndex == 6),
|
||||
title: Text('About'),
|
||||
leading: Icon(Icons.help_outline_outlined),
|
||||
onTap: () {},
|
||||
onTap: () {
|
||||
showAboutDialog(context: context);
|
||||
},
|
||||
),
|
||||
],
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user