Begin making CategoriesPage and TodayPage

This commit is contained in:
Ryan Pandya 2023-05-22 10:34:25 -07:00
parent be43a1d6e9
commit 77e4adc2ad

View File

@ -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<CategoriesPage> {
final api = CategoriesAPI();
late List<Document>? 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']),
);
}
;
},
),
),
);
}
}