104 lines
3.3 KiB
Dart
104 lines
3.3 KiB
Dart
import 'package:ltx_flutter/appwrite/categories_api.dart';
|
|
import 'package:ltx_flutter/appwrite/database_api.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:appwrite/models.dart';
|
|
import 'package:timezone/timezone.dart' as tz;
|
|
import 'package:timezone/data/latest.dart' as tz;
|
|
import 'package:ltx_flutter/pages/today_page.dart';
|
|
import 'package:ltx_flutter/helpers.dart';
|
|
|
|
class InfinityView extends StatefulWidget {
|
|
const InfinityView({
|
|
super.key,
|
|
});
|
|
|
|
@override
|
|
State<InfinityView> createState() => _InfinityViewState();
|
|
}
|
|
|
|
class _InfinityViewState extends State<InfinityView> {
|
|
DateTime _date = DateTime.now();
|
|
|
|
late DatabaseAPI database;
|
|
late CategoriesAPI categories;
|
|
|
|
late List<Document> entries = [];
|
|
|
|
@override
|
|
void didChangeDependencies() {
|
|
super.didChangeDependencies();
|
|
database = context.watch<DatabaseAPI>();
|
|
categories = context.watch<CategoriesAPI>();
|
|
entries = database.entries;
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SingleChildScrollView(
|
|
child: Container(
|
|
height: MediaQuery.of(context).size.height,
|
|
child: GridView.builder(
|
|
gridDelegate:
|
|
SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 24),
|
|
padding: EdgeInsets.all(2),
|
|
itemBuilder: (context, index) {
|
|
int entryIndex = (-1 + (index / 24)).toInt();
|
|
if (index < 24) {
|
|
// Build the top row
|
|
return Text("");
|
|
} else if (entryIndex < entries.length) {
|
|
Document entry = entries[entryIndex];
|
|
if (index % 24 == 0) {
|
|
// First column, show date
|
|
return Text(
|
|
formatDate(
|
|
dateISO: (entry.data['date']).toString(),
|
|
format: "MM/dd"),
|
|
);
|
|
} else {
|
|
int hourIndex = (index % 24) - 1;
|
|
num? hour;
|
|
try {
|
|
hour = entry.data['hours'][hourIndex];
|
|
} catch (e) {
|
|
hour = null;
|
|
}
|
|
|
|
String tooltip;
|
|
Color fgColor;
|
|
Color bgColor;
|
|
|
|
try {
|
|
Category category = categories.lookUp(hour.toString());
|
|
tooltip = category.description!;
|
|
fgColor = category.foregroundColor;
|
|
bgColor = category.backgroundColor;
|
|
} catch (e) {
|
|
tooltip = "";
|
|
fgColor = Colors.white;
|
|
bgColor = Colors.black;
|
|
}
|
|
return SizedBox(
|
|
width: 50,
|
|
height: 50,
|
|
child: Tooltip(
|
|
message: tooltip,
|
|
child: Container(
|
|
color: bgColor,
|
|
child: Center(
|
|
child: Text(
|
|
style: TextStyle(fontSize: 10, color: fgColor),
|
|
hour.toString())),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
}),
|
|
),
|
|
);
|
|
}
|
|
}
|