58 lines
1.4 KiB
Dart
58 lines
1.4 KiB
Dart
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}"),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|