From 77e4adc2adff140a694c7853c52164510234ab4c Mon Sep 17 00:00:00 2001 From: Ryan Pandya Date: Mon, 22 May 2023 10:34:25 -0700 Subject: [PATCH] Begin making CategoriesPage and TodayPage --- ltx_flutter/lib/pages/categories_page.dart | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 ltx_flutter/lib/pages/categories_page.dart diff --git a/ltx_flutter/lib/pages/categories_page.dart b/ltx_flutter/lib/pages/categories_page.dart new file mode 100644 index 0000000..977033e --- /dev/null +++ b/ltx_flutter/lib/pages/categories_page.dart @@ -0,0 +1,71 @@ +import 'package:appwrite/appwrite.dart'; +import 'package:ltx_flutter/appwrite/appwrite.dart'; +import 'package:ltx_flutter/appwrite/categories_api.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; +import 'package:appwrite/models.dart'; +import 'package:intl/intl.dart'; + +class CategoriesPage extends StatefulWidget { + const CategoriesPage({Key? key}) : super(key: key); + + @override + _CategoriesPageState createState() => _CategoriesPageState(); +} + +class _CategoriesPageState extends State { + final api = CategoriesAPI(); + late List? categories = []; + + @override + void initState() { + super.initState(); + loadCategories(); + } + + Future loadCategories() async { + try { + final value = await api.getCategories(); + setState(() { + categories = value.documents; + }); + } catch (e) { + print(e); + } + } + + @override + Widget build(BuildContext context) { + return RefreshIndicator( + onRefresh: loadCategories, + child: Center( + child: ListView.builder( + itemCount: categories!.length + 1, + itemBuilder: (context, index) { + if (index >= categories!.length || categories!.isEmpty) { + return ListTile( + leading: Text("New Category"), + ); + } else { + Document? category = categories?[index]; + Color backgroundColor = + Color(int.parse("0x${category!.data['color']}")); + Color textColor = backgroundColor.computeLuminance() > 0.2 + ? Colors.black + : Colors.white; + return ListTile( + onLongPress: , + tileColor: backgroundColor, + textColor: textColor, + titleTextStyle: TextStyle(fontWeight: FontWeight.w600), + leading: Text(category.data['number'].toString()), + title: Text(category.data['name']), + ); + } + ; + }, + ), + ), + ); + } +}