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']), ); } ; }, ), ), ); } }