Realtime updating works!
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:ltx_flutter/pages/account_page.dart';
|
||||
import 'package:ltx_flutter/pages/categories_page.dart';
|
||||
import 'package:ltx_flutter/pages/today_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../app_properties_bloc.dart';
|
||||
|
||||
class TabsPage extends StatefulWidget {
|
||||
const TabsPage({Key? key}) : super(key: key);
|
||||
@@ -25,7 +26,33 @@ class _TabsPageState extends State<TabsPage> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Flutter"),
|
||||
title: StreamBuilder<Object>(
|
||||
stream: appBloc.titleStream,
|
||||
initialData: "Flutter",
|
||||
builder: (context, snapshot) {
|
||||
return Text(snapshot.data.toString());
|
||||
}),
|
||||
actions: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 28.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Text("Edit"),
|
||||
StreamBuilder<Object>(
|
||||
stream: appBloc.editable,
|
||||
initialData: true,
|
||||
builder: (context, snapshot) {
|
||||
return Switch(
|
||||
value: bool.parse(snapshot.data.toString()),
|
||||
onChanged: (value) {
|
||||
// print(value);
|
||||
},
|
||||
);
|
||||
}),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
body: _widgets.elementAt(_selectedIndex),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
|
||||
@@ -25,7 +25,7 @@ String hourString(int e) {
|
||||
return "${hour.toString()} $meridien";
|
||||
}
|
||||
|
||||
List<Widget> generateHours(entry) {
|
||||
List<Widget> generateHours(entry, bool edit) {
|
||||
if (entry == null) {
|
||||
return [Center(child: RefreshProgressIndicator())];
|
||||
}
|
||||
@@ -35,24 +35,34 @@ List<Widget> generateHours(entry) {
|
||||
|
||||
List reduced = [];
|
||||
int counter = 0;
|
||||
for (int val in hours) {
|
||||
if (reduced.isEmpty) {
|
||||
reduced.add({'val': val, 'num': 1, 'hour': counter});
|
||||
} else {
|
||||
if (reduced.last['val'] == val) {
|
||||
reduced.last['num']++;
|
||||
reduced.last['hour'] = counter;
|
||||
} else {
|
||||
|
||||
if (edit) {
|
||||
for (int val in hours) {
|
||||
if (reduced.isEmpty) {
|
||||
reduced.add({'val': val, 'num': 1, 'hour': counter});
|
||||
} else {
|
||||
if (reduced.last['val'] == val) {
|
||||
reduced.last['num']++;
|
||||
reduced.last['hour'] = counter;
|
||||
} else {
|
||||
reduced.add({'val': val, 'num': 1, 'hour': counter});
|
||||
}
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
} else {
|
||||
for (int val in hours) {
|
||||
reduced.add({
|
||||
'hour': counter,
|
||||
'val': val,
|
||||
'num': 1,
|
||||
});
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
print(reduced);
|
||||
|
||||
return reduced.map(
|
||||
(e) {
|
||||
double height = double.parse((e['num'] * 35).toString());
|
||||
double height = double.parse((e['num'] * 36).toString());
|
||||
return Consumer<CategoriesAPI>(
|
||||
builder: (context, categories, child) {
|
||||
Category category = categories.lookUp(e['val'].toString());
|
||||
@@ -63,10 +73,38 @@ List<Widget> generateHours(entry) {
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
style: TextStyle(color: category.foregroundColor),
|
||||
hourString(e['hour'])),
|
||||
e['num'] == 1
|
||||
? Center(
|
||||
child: Text(
|
||||
style:
|
||||
TextStyle(color: category.foregroundColor),
|
||||
hourString(e['hour'])),
|
||||
)
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(top: 10, bottom: 10),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
style: TextStyle(
|
||||
color: category.foregroundColor),
|
||||
hourString(e['hour'] - e['num'] + 1)),
|
||||
Expanded(
|
||||
child: VerticalDivider(
|
||||
indent: 10,
|
||||
endIndent: 10,
|
||||
color: category.foregroundColor,
|
||||
width: 4,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
style: TextStyle(
|
||||
color: category.foregroundColor),
|
||||
hourString(e['hour'] + 1))
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Text(
|
||||
@@ -85,6 +123,26 @@ List<Widget> generateHours(entry) {
|
||||
).toList();
|
||||
}
|
||||
|
||||
Color moodColor(mood) {
|
||||
if (mood == null) {
|
||||
return Colors.transparent;
|
||||
}
|
||||
if (mood >= 8) {
|
||||
return Colors.green;
|
||||
}
|
||||
if (mood > 5) {
|
||||
return Colors.blue;
|
||||
}
|
||||
if (mood == 5) {
|
||||
return Colors.yellow;
|
||||
}
|
||||
if (mood >= 3) {
|
||||
return Colors.amber;
|
||||
} else {
|
||||
return Colors.red;
|
||||
}
|
||||
}
|
||||
|
||||
class TodayPage extends StatefulWidget {
|
||||
const TodayPage({Key? key}) : super(key: key);
|
||||
|
||||
@@ -175,7 +233,6 @@ class _DayViewState extends State<DayView> {
|
||||
super.didChangeDependencies();
|
||||
database = context.watch<DatabaseAPI>();
|
||||
categories = context.watch<CategoriesAPI>();
|
||||
print(categories.lookUp(9));
|
||||
entries = database.entries;
|
||||
}
|
||||
|
||||
@@ -190,22 +247,6 @@ class _DayViewState extends State<DayView> {
|
||||
}
|
||||
}
|
||||
|
||||
// Document? grabEntry(DateTime date) {
|
||||
// DatabaseAPI database = context.watch<DatabaseAPI>();
|
||||
// entries = database.entries;
|
||||
// String formattedDate = formatDate(
|
||||
// dateISO: date.toIso8601String(),
|
||||
// format: "yyyy-MM-dd",
|
||||
// );
|
||||
|
||||
// try {
|
||||
// dayEntry = entries.singleWhere((element) => element.$id == formattedDate);
|
||||
// return dayEntry;
|
||||
// } catch (e) {
|
||||
// database.getOne(date: formattedDate).then((value) => dayEntry = value);
|
||||
// }
|
||||
// }
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<Document> entries = database.entries;
|
||||
@@ -292,7 +333,7 @@ class _DayViewState extends State<DayView> {
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: categories.ready
|
||||
? generateHours(dayEntry)
|
||||
? generateHours(dayEntry, true)
|
||||
: [CircularProgressIndicator()],
|
||||
),
|
||||
),
|
||||
@@ -304,7 +345,9 @@ class _DayViewState extends State<DayView> {
|
||||
SizedBox.square(
|
||||
dimension: 50,
|
||||
child: Container(
|
||||
color: Colors.amber, child: Center(child: moodWidget)),
|
||||
color: moodColor(mood),
|
||||
child: Center(child: moodWidget),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 30),
|
||||
Expanded(
|
||||
|
||||
Reference in New Issue
Block a user