ModernMemoires/lib/views/entry_view/entry_page.dart

107 lines
3.3 KiB
Dart
Raw Normal View History

2023-12-25 14:10:31 +01:00
/*class EntryPage extends StatelessWidget {
2023-12-17 23:00:31 +01:00
final DateTime date;
EntryPage({Key? key, required this.date}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Date Display'),
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.white),
2023-12-18 17:51:22 +01:00
onPressed: () => context.go("/statistic"),
2023-12-17 23:00:31 +01:00
),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Selected Date:",
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
SizedBox(height: 10),
Text(
DateFormat('yyyy-MM-dd').format(date),
style: TextStyle(fontSize: 20, color: Colors.blue),
),
],
),
),
);
}
}
2023-12-25 14:10:31 +01:00
*/
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';
import '../../utils/logic/PreferencesService.dart';
class EntryPage extends StatelessWidget {
final DateTime date;
final PreferencesService prefsService = PreferencesService();
EntryPage({Key? key, required this.date}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Date Display'),
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.white),
onPressed: () => context.go("/statistic"),
),
),
body: FutureBuilder<DiaryEntry?>(
future: prefsService.getDiaryEntryByDate(date), // Fetch the diary entry
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
// Check if the diary entry exists
if (snapshot.data != null) {
DiaryEntry entry = snapshot.data!;
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
"Selected Date:",
style:
TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
),
SizedBox(height: 10),
Text(
DateFormat('yyyy-MM-dd').format(date),
style: TextStyle(fontSize: 20, color: Colors.blue),
),
SizedBox(height: 20),
Text(
"Percent Value: ${entry.percentValue}",
style: TextStyle(fontSize: 18),
),
...entry.texts.map((text) => Padding(
padding: const EdgeInsets.all(8.0),
child: Text(text),
)),
],
),
);
} else {
// Handle the case when there is no entry for the given date
return Center(
child: Text("No entry found for this date."),
);
}
} else {
// Show loading indicator while waiting for data
return Center(child: CircularProgressIndicator());
}
},
),
);
}
}