Incremental changes to TodayPage...
This commit is contained in:
parent
77e4adc2ad
commit
162f2469f8
71
ltx_flutter/lib/appwrite/categories_api.dart
Normal file
71
ltx_flutter/lib/appwrite/categories_api.dart
Normal file
@ -0,0 +1,71 @@
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
import 'package:appwrite/models.dart';
|
||||
import 'package:ltx_flutter/constants/constants.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:ltx_flutter/appwrite/appwrite.dart';
|
||||
|
||||
class CategoriesAPI extends ChangeNotifier {
|
||||
Client client = Client();
|
||||
late final Account account;
|
||||
late final Databases databases;
|
||||
late final String userId;
|
||||
final AuthAPI auth = AuthAPI();
|
||||
|
||||
// Constructor
|
||||
CategoriesAPI() {
|
||||
init();
|
||||
}
|
||||
|
||||
// loadUser() async {
|
||||
// try {
|
||||
// user = await account.get();
|
||||
// notifyListeners();
|
||||
// } catch (e) {
|
||||
// print(e);
|
||||
// notifyListeners();
|
||||
// }
|
||||
// }
|
||||
|
||||
init() {
|
||||
client.setEndpoint(APPWRITE_URL).setProject(APPWRITE_PROJECT_ID);
|
||||
account = Account(client);
|
||||
databases = Databases(client);
|
||||
}
|
||||
|
||||
Future<DocumentList> getCategories() {
|
||||
print("Getting categories");
|
||||
return databases.listDocuments(
|
||||
databaseId: CATEGORIES_DB,
|
||||
collectionId: COLLECTION,
|
||||
queries: [
|
||||
Query.orderAsc("number"),
|
||||
]);
|
||||
}
|
||||
|
||||
Future<Document> addCategory({
|
||||
required String name,
|
||||
required double number,
|
||||
required String color,
|
||||
String? description,
|
||||
int? parentId,
|
||||
}) {
|
||||
return databases.createDocument(
|
||||
databaseId: CATEGORIES_DB,
|
||||
collectionId: COLLECTION,
|
||||
documentId: "category-${number.toString()}",
|
||||
data: {
|
||||
'name': name,
|
||||
'number': number,
|
||||
'color': color,
|
||||
'parent': parentId,
|
||||
'description': description,
|
||||
});
|
||||
}
|
||||
|
||||
Future<dynamic> deleteCategory({required double number}) {
|
||||
return databases.deleteDocument(
|
||||
databaseId: CATEGORIES_DB,
|
||||
collectionId: COLLECTION,
|
||||
documentId: "category-${number.toString()}");
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
const String APPWRITE_PROJECT_ID = "lifetracker";
|
||||
const String APPWRITE_DATABASE_ID = "lifetracker-db";
|
||||
const String CATEGORIES_DB = "categories";
|
||||
const String APPWRITE_URL = "https://db.ryanpandya.com/v1";
|
||||
const String COLLECTION = "ryan";
|
||||
|
||||
@ -61,7 +61,7 @@ class _TablePageState extends State<TablePage> {
|
||||
title: hourTitle,
|
||||
field: "hours[$e]",
|
||||
type: PlutoColumnType.number(),
|
||||
width: 65,
|
||||
width: 70,
|
||||
enableContextMenu: false,
|
||||
enableDropToResize: false,
|
||||
textAlign: PlutoColumnTextAlign.center,
|
||||
@ -75,23 +75,22 @@ class _TablePageState extends State<TablePage> {
|
||||
field: 'date',
|
||||
type: PlutoColumnType.text(),
|
||||
readOnly: true,
|
||||
width: 110,
|
||||
frozen: PlutoColumnFrozen.start,
|
||||
width: 70,
|
||||
enableContextMenu: false,
|
||||
enableDropToResize: false,
|
||||
textAlign: PlutoColumnTextAlign.center,
|
||||
titleTextAlign: PlutoColumnTextAlign.center,
|
||||
frozen: PlutoColumnFrozen.start,
|
||||
),
|
||||
PlutoColumn(
|
||||
title: 'DAY',
|
||||
field: 'day',
|
||||
type: PlutoColumnType.text(),
|
||||
readOnly: true,
|
||||
width: 53,
|
||||
enableContextMenu: false,
|
||||
enableDropToResize: false,
|
||||
),
|
||||
// PlutoColumn(
|
||||
// title: 'DAY',
|
||||
// field: 'day',
|
||||
// type: PlutoColumnType.text(),
|
||||
// readOnly: true,
|
||||
// width: 50,
|
||||
// frozen: PlutoColumnFrozen.start,
|
||||
// enableContextMenu: false,
|
||||
// enableDropToResize: false,
|
||||
// ),
|
||||
] +
|
||||
hourCols +
|
||||
[
|
||||
@ -117,23 +116,27 @@ class _TablePageState extends State<TablePage> {
|
||||
var cells = {
|
||||
'date': PlutoCell(
|
||||
value: formatDate(
|
||||
format: "MM/DD E",
|
||||
format: "MM/DD",
|
||||
dateISO: e.data['date'],
|
||||
),
|
||||
),
|
||||
'day': PlutoCell(
|
||||
value: formatDate(
|
||||
format: "E",
|
||||
dateISO: e.data['date'],
|
||||
),
|
||||
),
|
||||
// 'day': PlutoCell(
|
||||
// value: formatDate(
|
||||
// format: "E",
|
||||
// dateISO: e.data['date'],
|
||||
// ),
|
||||
// ),
|
||||
'mood': PlutoCell(value: e.data['mood']),
|
||||
'comments': PlutoCell(value: e.data['comments']),
|
||||
};
|
||||
var hours = <String, PlutoCell>{};
|
||||
for (int i = 0; i < 24; i++) {
|
||||
hours.putIfAbsent(
|
||||
"hours[$i]", () => PlutoCell(value: e.data['hours'][i]));
|
||||
"hours[$i]",
|
||||
() => PlutoCell(
|
||||
value: e.data['hours'][i],
|
||||
),
|
||||
);
|
||||
}
|
||||
cells.addEntries(hours.entries);
|
||||
|
||||
@ -159,8 +162,7 @@ class _TablePageState extends State<TablePage> {
|
||||
child: entries!.isEmpty
|
||||
? Center(child: const CircularProgressIndicator())
|
||||
: Scaffold(
|
||||
body: Container(
|
||||
padding: const EdgeInsets.all(0),
|
||||
body: InteractiveViewer(
|
||||
child: PlutoGrid(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
|
||||
@ -1,6 +1,9 @@
|
||||
import 'package:ltx_flutter/pages/table_page.dart';
|
||||
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 'package:provider/provider.dart';
|
||||
|
||||
class TabsPage extends StatefulWidget {
|
||||
const TabsPage({Key? key}) : super(key: key);
|
||||
@ -12,7 +15,7 @@ class TabsPage extends StatefulWidget {
|
||||
class _TabsPageState extends State<TabsPage> {
|
||||
int _selectedIndex = 0;
|
||||
|
||||
static const _widgets = [TablePage(), AccountPage()];
|
||||
static const _widgets = [TodayPage(), CategoriesPage(), AccountPage()];
|
||||
|
||||
void _onItemTapped(int index) {
|
||||
setState(() {
|
||||
@ -24,13 +27,15 @@ class _TabsPageState extends State<TabsPage> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Lifetracker"),
|
||||
title: Text("LTX Android"),
|
||||
),
|
||||
body: _widgets.elementAt(_selectedIndex),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
items: const [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.table_chart_outlined), label: "Tracker"),
|
||||
icon: Icon(Icons.today_outlined), label: "Today"),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.category_outlined), label: "Categories"),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.account_circle_outlined), label: "Account")
|
||||
],
|
||||
|
||||
57
ltx_flutter/lib/pages/today_page.dart
Normal file
57
ltx_flutter/lib/pages/today_page.dart
Normal file
@ -0,0 +1,57 @@
|
||||
import 'package:appwrite/appwrite.dart';
|
||||
import 'package:ltx_flutter/appwrite/appwrite.dart';
|
||||
import 'package:ltx_flutter/appwrite/database_api.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:appwrite/models.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class TodayPage extends StatefulWidget {
|
||||
const TodayPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_TodayPageState createState() => _TodayPageState();
|
||||
}
|
||||
|
||||
class _TodayPageState extends State<TodayPage> {
|
||||
final database = DatabaseAPI();
|
||||
late List<Document>? entries = [];
|
||||
|
||||
AuthStatus authStatus = AuthStatus.uninitialized;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final AuthAPI appwrite = context.read<AuthAPI>();
|
||||
authStatus = appwrite.status;
|
||||
loadEntries();
|
||||
}
|
||||
|
||||
loadEntries() async {
|
||||
try {
|
||||
final value = await database.getEntries(limit: 25);
|
||||
setState(() {
|
||||
entries = value.documents;
|
||||
});
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
String formatDate({String format = "", String? dateISO}) {
|
||||
final DateFormat dateFormatter = DateFormat(format);
|
||||
final date = dateISO!.isEmpty ? DateTime.now() : DateTime.parse(dateISO);
|
||||
return dateFormatter.format(date);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Text("Entries: ${entries?.length}"),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -17,6 +17,7 @@ dependencies:
|
||||
flutter_svg: ^2.0.6
|
||||
intl: ^0.18.1
|
||||
pluto_grid: ^7.0.2
|
||||
string_to_hex: ^0.2.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user