Fixed infinite-loading-new-entry bug.

This commit is contained in:
Ryan Pandya 2023-06-22 15:36:43 -04:00
parent 2195a5324c
commit 9824429703
2 changed files with 18 additions and 13 deletions

View File

@ -81,7 +81,7 @@ class DatabaseAPI extends ChangeNotifier {
var referenceDate = DateTime.parse("2023-01-01");
final date = DateTime.parse(dateISO);
return date.difference(referenceDate).inDays;
return date.difference(referenceDate).inDays + 1;
}
getAll() async {
@ -109,18 +109,22 @@ class DatabaseAPI extends ChangeNotifier {
}
getOne({required String date}) async {
try {
// print(date);
// print(_entries.last.$id);
return _entries.singleWhere((element) => element.$id == date);
} catch (e) {
int offset =
DateTime.parse(date).difference(DateTime.parse("2023-01-01")).inDays;
DateTime.parse(date).difference(DateTime.parse("2023-01-01")).inDays +
1;
List<Document> response = await getEntries(
limit: 1,
paginationQuery: Query.offset(offset),
);
_entries.add(response.first);
notifyListeners();
return response.first;
}
}
getEntries({int limit = 100, paginationQuery}) async {

View File

@ -209,6 +209,7 @@ class _DayViewState extends State<DayView> {
Expanded(
child: TextFormField(
decoration: InputDecoration(hintText: "Comments"),
textCapitalization: TextCapitalization.sentences,
smartQuotesType: SmartQuotesType.enabled,
enableInteractiveSelection: true,
controller: commentsController,
@ -293,7 +294,7 @@ class _HourGeneratorState extends State<HourGenerator> {
double height = double.parse((e['num'] * 36).toString());
return Consumer<CategoriesAPI>(
builder: (context, categories, child) {
Category category = categories.lookUp(e['val'].toString());
dynamic category = categories.lookUp(e['val'].toString());
return SizedBox(
height: height,
child: GestureDetector(