Reactive Cards in summary,

Offline Banner
This commit is contained in:
Sewmina
2022-03-08 05:18:00 +05:30
parent 455483299f
commit c7c1495b92
2 changed files with 234 additions and 223 deletions

View File

@@ -55,6 +55,7 @@ Future<void> initUserData() async {
await initCacheDatabase(); await initCacheDatabase();
await refreshUserData(); await refreshUserData();
print('Initializing UserData...'); print('Initializing UserData...');
if(Platform.isAndroid || Platform.isIOS){
Connectivity().onConnectivityChanged.listen((result) { Connectivity().onConnectivityChanged.listen((result) {
offline = (result == ConnectivityResult.none); offline = (result == ConnectivityResult.none);
if (!offline) { if (!offline) {
@@ -62,6 +63,7 @@ Future<void> initUserData() async {
refreshUserData(); refreshUserData();
} }
}); });
}
} }
Future<void> refreshUserData() async { Future<void> refreshUserData() async {
@@ -180,14 +182,14 @@ Future<List<Category>> GetCategories(bool forceOffline) async {
//Validate device_id to check updates //Validate device_id to check updates
bool catsUpdated = true; bool catsUpdated = false;
try { // 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})); // 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}));
final data = update_response.body.split(','); // final data = update_response.body.split(',');
catsUpdated = data[0] == '1'; // catsUpdated = data[0] == '1';
} catch (e) { // } catch (e) {
print(e); // print(e);
} // }
print("Need to update : ${!catsUpdated}"); print("Need to update : ${!catsUpdated}");
@@ -243,15 +245,15 @@ Future<List<TaskType>> GetTaskTypes(bool forceOffline) async {
//Check if server got updated, If not go for cache //Check if server got updated, If not go for cache
var android_id = await Settings.UUID(); var android_id = await Settings.UUID();
bool updated = true; bool updated = false;
try { // try {
//Validate device_id to check updates // //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})); // 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}));
final data = update_response.body.split(','); // final data = update_response.body.split(',');
updated = data[1] == '1'; // updated = data[1] == '1';
} catch (e) { // } catch (e) {
print(e); // print(e);
} // }
print("Need to update : ${!updated}"); print("Need to update : ${!updated}");
@@ -313,15 +315,15 @@ Future<List<Activity>> GetActivities(bool forceOffline) async {
//Check if server got updated, If not go for cache //Check if server got updated, If not go for cache
var android_id = await Settings.UUID(); var android_id = await Settings.UUID();
bool updated = true; bool updated = false;
try { // try {
//Validate device_id to check updates // //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})); // 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}));
final data = update_response.body.split(','); // final data = update_response.body.split(',');
updated = data[2] == '1'; // updated = data[2] == '1';
} catch (e) { // } catch (e) {
print(e); // print(e);
} // }
print("Need to update activities : ${!updated}"); print("Need to update activities : ${!updated}");

View File

@@ -369,210 +369,219 @@ class _MyHomePageState extends State<MyHomePage> {
Expanded(flex: 1,child: Container(),), Expanded(flex: 1,child: Container(),),
Expanded(flex: 2,child: Image(image: AssetImage('images/empty.png'))), 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),)) Expanded(flex:2,child: Text("Add your first activity to access Summary",style: TextStyle(color: Colors.grey, fontStyle: FontStyle.italic),))
]) :SingleChildScrollView( ]) :Column(
scrollDirection: Axis.vertical, mainAxisSize: MainAxisSize.max,
child: Column( children: [
children: [ if(User.offline)Expanded(flex:1,child: Container(width:1000,color: Colors.red,child: Align(alignment: Alignment.center,child: Text("Offline")))),
(false) Expanded(
? Container( flex:50,
padding: EdgeInsets.all(20), child: SingleChildScrollView(
child: Row( scrollDirection: Axis.vertical,
mainAxisAlignment: MainAxisAlignment.spaceBetween, child: Column(
mainAxisSize: MainAxisSize.max, children: [
children: [ (false)
Text("Good\nMorning!", style: TextStyle(fontSize: 23, fontStyle: FontStyle.italic)), ? Container(
Text( padding: EdgeInsets.all(20),
"12%", child: Row(
style: TextStyle(fontSize: 30), mainAxisAlignment: MainAxisAlignment.spaceBetween,
), mainAxisSize: MainAxisSize.max,
Column( children: [
children: [ Text("Good\nMorning!", style: TextStyle(fontSize: 23, fontStyle: FontStyle.italic)),
Text(DateFormat("yy - MM-dd").format(DateTime.now())), Text(
Text(DateFormat("HH:mm").format(DateTime.now()), style: TextStyle(fontSize: 40)), "12%",
], style: TextStyle(fontSize: 30),
) ),
], Column(
),
)
: Container(),
Container(
height: 300,
padding: EdgeInsets.all(10),
child: Card(
elevation: 8,
shadowColor: Colors.blueGrey,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20),
child: Column(
children: [
Row(
children: [
SizedBox(
width: 10,
),
Text("Productivity", style: TextStyle(color: Colors.green, fontWeight: FontWeight.bold)),
],
),
Divider(),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
children: [
Text("Today : "),
Text("${(productivityData.length > 0) ? productivityData[0].productivity.toStringAsFixed(1) : 'n/a'}%",
style: TextStyle(
fontSize: 20,
color: (productivityData.length > 1)
? ((productivityData[0].productivity > productivityData[1].productivity) ? Colors.lightGreenAccent : Colors.red)
: Colors.white))
],
),
Row(
children: [
Text("Yesterday : "),
Text("${(productivityData.length > 1) ? productivityData[1].productivity.toStringAsFixed(1) : 'n/a'}%", style: TextStyle(fontSize: 18))
],
),
],
),
Expanded(
child: SfCartesianChart(
// Initialize category axis
primaryXAxis: CategoryAxis(),
series: <LineSeries<ProductivityMapData, String>>[
LineSeries<ProductivityMapData, String>(
// Bind data source
dataSource: productivityData.reversed.toList(),
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),
color: Colors.green)
]),
)
],
),
)),
),
Container(
height: 370,
padding: EdgeInsets.all(10),
child: Card(
elevation: 8,
shadowColor: Colors.blueGrey,
child: Padding(
padding: EdgeInsets.all(8),
child: (!days.isEmpty)
? Column(
children: [ children: [
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(DateFormat("yy - MM-dd").format(DateTime.now())),
Padding(padding: EdgeInsets.all(20), child: Text('Daily Briefing', style: TextStyle(fontWeight: FontWeight.bold))), Text(DateFormat("HH:mm").format(DateTime.now()), style: TextStyle(fontSize: 40)),
dayPickerWidget(days, value: curDay, onChange: (_value) {
print('new val : $_value');
curDay = _value;
setState(() {
LoadStats();
});
}),
]),
Expanded(
child: SfCircularChart(legend: Legend(isVisible: true), series: <CircularSeries>[
// Render pie chart
PieSeries<CatMapData, String>(
dataSource: dailyData,
pointColorMapper: (CatMapData data, _) => data.color,
xValueMapper: (CatMapData data, _) => data.name,
yValueMapper: (CatMapData data, _) => data.time,
dataLabelMapper: (CatMapData sales, _) => MinutesToTimeString(sales.time),
dataLabelSettings: DataLabelSettings(isVisible: true, useSeriesColor: true))
]))
], ],
) )
: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.center, children: [CircularProgressIndicator()])))), ],
Container( ),
height: 450, )
padding: EdgeInsets.all(10), : Container(),
child: Card( Container(
elevation: 8, height: 300,
shadowColor: Colors.blueGrey, padding: EdgeInsets.all(10),
child: Padding( child: Card(
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 25), elevation: 8,
child: Column(children: [ shadowColor: Colors.blueGrey,
Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ child: Padding(
Text("Task Types", style: TextStyle(fontWeight: FontWeight.bold)), padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 20),
InkWell( child: Column(
onTap: () async { children: [
DateTimeRange? value = await showDateRangePicker(context: context, firstDate: firstDay ?? DateTime.now(), lastDate: lastDay ?? DateTime.now()); Row(
if (value != null) { children: [
taskTypeRange = value; SizedBox(
} width: 10,
),
Text("Productivity", style: TextStyle(color: Colors.green, fontWeight: FontWeight.bold)),
],
),
Divider(),
Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
children: [
Text("Today : "),
Text("${(productivityData.length > 0) ? productivityData[0].productivity.toStringAsFixed(1) : 'n/a'}%",
style: TextStyle(
fontSize: 20,
color: (productivityData.length > 1)
? ((productivityData[0].productivity > productivityData[1].productivity) ? Colors.lightGreenAccent : Colors.red)
: Colors.white))
],
),
Row(
children: [
Text("Yesterday : "),
Text("${(productivityData.length > 1) ? productivityData[1].productivity.toStringAsFixed(1) : 'n/a'}%", style: TextStyle(fontSize: 18))
],
),
],
),
Expanded(
child: SfCartesianChart(
// Initialize category axis
primaryXAxis: CategoryAxis(),
series: <LineSeries<ProductivityMapData, String>>[
LineSeries<ProductivityMapData, String>(
// Bind data source
dataSource: productivityData.reversed.toList(),
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),
color: Colors.green)
]),
)
],
),
)),
),
Container(
height: 370,
padding: EdgeInsets.all(10),
child: Card(
elevation: 8,
shadowColor: Colors.blueGrey,
child: Padding(
padding: EdgeInsets.all(8),
child: (!days.isEmpty)
? Column(
children: [
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Padding(padding: EdgeInsets.all(20), child: Text('Daily Briefing', style: TextStyle(fontWeight: FontWeight.bold))),
dayPickerWidget(days, value: curDay, onChange: (_value) {
print('new val : $_value');
curDay = _value;
setState(() {
LoadStats();
});
}),
]),
Expanded(
child: SfCircularChart(legend: Legend(isVisible: true), series: <CircularSeries>[
// Render pie chart
PieSeries<CatMapData, String>(
dataSource: dailyData,
pointColorMapper: (CatMapData data, _) => data.color,
xValueMapper: (CatMapData data, _) => data.name,
yValueMapper: (CatMapData data, _) => data.time,
dataLabelMapper: (CatMapData sales, _) => MinutesToTimeString(sales.time),
dataLabelSettings: DataLabelSettings(isVisible: true, useSeriesColor: true))
]))
],
)
: Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.center, children: [CircularProgressIndicator()])))),
Container(
height: (taskTypesData.length * 45).clamp(350, 1000).toDouble(),
padding: EdgeInsets.all(10),
child: Card(
elevation: 8,
shadowColor: Colors.blueGrey,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 25),
child: Column(children: [
Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Text("Task Types", style: TextStyle(fontWeight: FontWeight.bold)),
InkWell(
onTap: () async {
DateTimeRange? value = await showDateRangePicker(context: context, firstDate: firstDay ?? DateTime.now(), lastDate: lastDay ?? DateTime.now());
if (value != null) {
taskTypeRange = value;
}
LoadStats(); LoadStats();
}, },
child: Text((taskTypeRange != null) ? (DateFormat("MM/dd").format(taskTypeRange!.start) + " - " + DateFormat("MM/dd").format(taskTypeRange!.end)) : 'n/a'), child: Text((taskTypeRange != null) ? (DateFormat("MM/dd").format(taskTypeRange!.start) + " - " + DateFormat("MM/dd").format(taskTypeRange!.end)) : 'n/a'),
) )
]),
Expanded(
// maxHeight: 300,
// maxWidth: 100,
child: SfCartesianChart(primaryXAxis: CategoryAxis(),
//primaryYAxis: NumericAxis(minimum: 0, maximum: 40, interval: 10),
series: <ChartSeries<TaskTypeMapData, String>>[
BarSeries<TaskTypeMapData, String>(
dataSource: taskTypesData,
xValueMapper: (TaskTypeMapData data, _) => data.task,
yValueMapper: (TaskTypeMapData data, _) => data.time / 60,
pointColorMapper: (TaskTypeMapData data, _) => data.color,
dataLabelMapper: (TaskTypeMapData data, _) => MinutesToTimeString(data.time),
dataLabelSettings: DataLabelSettings(isVisible: true),
color: Color.fromRGBO(8, 142, 255, 1))
]), ]),
) Expanded(
])))), // maxHeight: 300,
Container( // maxWidth: 100,
height: 450, child: SfCartesianChart(primaryXAxis: CategoryAxis(),
padding: EdgeInsets.all(10), //primaryYAxis: NumericAxis(minimum: 0, maximum: 40, interval: 10),
child: Card( series: <ChartSeries<TaskTypeMapData, String>>[
elevation: 8, BarSeries<TaskTypeMapData, String>(
shadowColor: Colors.blueGrey, dataSource: taskTypesData,
child: Padding( xValueMapper: (TaskTypeMapData data, _) => data.task,
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 25), yValueMapper: (TaskTypeMapData data, _) => data.time / 60,
child: Column(children: [ pointColorMapper: (TaskTypeMapData data, _) => data.color,
Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ dataLabelMapper: (TaskTypeMapData data, _) => MinutesToTimeString(data.time),
Text("Categories", style: TextStyle(fontWeight: FontWeight.bold)), dataLabelSettings: DataLabelSettings(isVisible: true),
InkWell( color: Color.fromRGBO(8, 142, 255, 1))
onTap: () async { ]),
DateTimeRange? value = await showDateRangePicker(context: context, firstDate: firstDay ?? DateTime.now(), lastDate: lastDay ?? DateTime.now()); )
if (value != null) { ])))),
catsRange = value; Container(
} height: (catsData.length * 45).clamp(350, 1000).toDouble(),
padding: EdgeInsets.all(10),
child: Card(
elevation: 8,
shadowColor: Colors.blueGrey,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 25, vertical: 25),
child: Column(children: [
Row(mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Text("Categories", style: TextStyle(fontWeight: FontWeight.bold)),
InkWell(
onTap: () async {
DateTimeRange? value = await showDateRangePicker(context: context, firstDate: firstDay ?? DateTime.now(), lastDate: lastDay ?? DateTime.now());
if (value != null) {
catsRange = value;
}
LoadStats(); LoadStats();
}, },
child: Text((catsRange != null) ? (DateFormat("MM/dd").format(catsRange!.start) + " - " + DateFormat("MM/dd").format(catsRange!.end)) : 'n/a'), child: Text((catsRange != null) ? (DateFormat("MM/dd").format(catsRange!.start) + " - " + DateFormat("MM/dd").format(catsRange!.end)) : 'n/a'),
) )
]),
Expanded(
// maxHeight: 300,
// maxWidth: 100,
child: SfCartesianChart(primaryXAxis: CategoryAxis(),
//primaryYAxis: NumericAxis(minimum: 0, maximum: 40, interval: 10),
series: <ChartSeries<CatMapData, String>>[
BarSeries<CatMapData, String>(
dataSource: catsData,
xValueMapper: (CatMapData data, _) => data.name,
yValueMapper: (CatMapData data, _) => data.time / 60,
pointColorMapper: (CatMapData data, _) => data.color,
dataLabelMapper: (CatMapData data, _) => MinutesToTimeString(data.time),
dataLabelSettings: DataLabelSettings(isVisible: true),
color: Color.fromRGBO(8, 142, 255, 1))
]), ]),
) Expanded(
])))), // maxHeight: 300,
], // maxWidth: 100,
), child: SfCartesianChart(primaryXAxis: CategoryAxis(),
//primaryYAxis: NumericAxis(minimum: 0, maximum: 40, interval: 10),
series: <ChartSeries<CatMapData, String>>[
BarSeries<CatMapData, String>(
dataSource: catsData,
xValueMapper: (CatMapData data, _) => data.name,
yValueMapper: (CatMapData data, _) => data.time / 60,
pointColorMapper: (CatMapData data, _) => data.color,
dataLabelMapper: (CatMapData data, _) => MinutesToTimeString(data.time),
dataLabelSettings: DataLabelSettings(isVisible: true),
color: Color.fromRGBO(8, 142, 255, 1))
]),
)
])))),
],
),
),
),
],
), ),
), ),
); );