fooder-app/lib/screens/main.dart

59 lines
1.4 KiB
Dart
Raw Normal View History

2023-07-29 18:10:10 +02:00
import 'package:flutter/material.dart';
2023-07-29 18:47:13 +02:00
import 'package:fooder_web/screens/based.dart';
2023-07-29 19:21:02 +02:00
import 'package:fooder_web/models/meal.dart';
import 'package:fooder_web/models/entry.dart';
import 'package:fooder_web/models/diary.dart';
import 'package:fooder_web/widgets/diary.dart';
2023-07-29 18:10:10 +02:00
2023-07-29 20:01:56 +02:00
class MainScreen extends BasedScreen {
const MainScreen({super.key, required super.apiClient});
2023-07-29 18:10:10 +02:00
@override
2023-07-29 20:01:56 +02:00
State<MainScreen> createState() => _MainScreen();
2023-07-29 18:10:10 +02:00
}
2023-07-29 20:01:56 +02:00
class _MainScreen extends State<MainScreen> {
2023-07-29 20:10:59 +02:00
Diary? diary;
2023-07-29 20:55:32 +02:00
@override
void initState () {
super.initState();
_asyncInitState().then((value) => null);
}
Future<void> _asyncInitState() async {
var diaryMap = await widget.apiClient.getDiary();
setState(() {
diary = Diary.fromJson(diaryMap);
});
}
2023-07-29 18:10:10 +02:00
@override
Widget build(BuildContext context) {
2023-07-29 20:10:59 +02:00
var content;
2023-07-29 20:55:32 +02:00
var title = "FOODER";
2023-07-29 20:10:59 +02:00
if (diary != null) {
2023-07-29 20:55:32 +02:00
content = Container(
constraints: const BoxConstraints(maxWidth: 600),
padding: const EdgeInsets.all(10),
child: DiaryWidget(diary: diary!),
);
title = "FOODER - ${diary!.date.year}-${diary!.date.month}-${diary!.date.day}";
2023-07-29 20:10:59 +02:00
} else {
content = const CircularProgressIndicator();
}
2023-07-29 18:10:10 +02:00
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
2023-07-29 20:55:32 +02:00
title: Text(title),
2023-07-29 18:10:10 +02:00
),
body: Center(
2023-07-29 20:10:59 +02:00
child: content,
2023-07-29 18:10:10 +02:00
),
);
}
}