TIFNGANJUK_E41212218/classifragise/lib/pages/result_page.dart

164 lines
6.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'dart:io';
class ResultPage extends StatelessWidget {
final File image;
final String date;
final String? prediction;
const ResultPage({
super.key,
required this.image,
required this.date,
required this.prediction,
});
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
backgroundColor: const Color(0xFF891A2D),
title: Text(
"Hasil Prediksi",
style: GoogleFonts.poppins(color: Colors.white),
),
centerTitle: true,
iconTheme: const IconThemeData(color: Colors.white),
),
body: SafeArea(
child: SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Image.file(
image,
width: double.infinity,
height: 250,
fit: BoxFit.cover,
),
),
const SizedBox(height: 15),
Table(
border: TableBorder.all(color: Colors.black26),
columnWidths: const {
0: FlexColumnWidth(1),
1: FlexColumnWidth(2),
},
children: [
TableRow(children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Tanggal",
style: GoogleFonts.poppins(
fontWeight: FontWeight.bold)),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(date),
),
]),
TableRow(children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Hasil Prediksi",
style: GoogleFonts.poppins(
fontWeight: FontWeight.bold)),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Text(prediction ??
"Error: Tidak dapat memproses gambar"),
),
]),
],
),
const SizedBox(height: 10),
Align(
alignment: Alignment.centerLeft,
child: Text(
"Penjelasan Hasil",
style: GoogleFonts.poppins(
fontSize: 16,
fontWeight: FontWeight.bold,
color: const Color(0xFF891A2D),
),
),
),
const SizedBox(height: 5),
if (prediction == "Segar ✅")
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.green[50],
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.green, width: 1),
),
child: Text(
"Strawberry segar adalah buah stroberi yang masih dalam kondisi baik, belum layu atau busuk, serta memiliki rasa yang manis dan sedikit asam. Untuk menjaga kesegarannya, stroberi sebaiknya disimpan di kulkas dalam wadah terbuka atau dilapisi kertas agar tidak cepat lembap dan membusuk.",
textAlign: TextAlign.left,
style: GoogleFonts.poppins(
fontSize: 14, color: Colors.black54),
),
),
if (prediction == "Tidak Segar ❌")
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.red[50],
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.red, width: 1),
),
child: Text(
"Strawberry busuk adalah stroberi yang sudah mengalami pembusukan akibat faktor seperti kelembapan tinggi, suhu penyimpanan yang tidak tepat, atau terlalu lama disimpan. Jika menemukan stroberi dalam kondisi seperti ini, sebaiknya segera dibuang agar tidak menyebar ke stroberi lainnya. Untuk mencegah pembusukan, stroberi sebaiknya disimpan di kulkas dalam wadah terbuka dengan kertas penyerap kelembapan.",
textAlign: TextAlign.left,
style: GoogleFonts.poppins(
fontSize: 14, color: Colors.black54),
),
),
if (prediction == null || prediction!.isEmpty)
Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.grey, width: 1),
),
child: Text(
"Tidak dapat menentukan hasil prediksi. Silakan coba lagi dengan gambar lain.",
textAlign: TextAlign.center,
style: GoogleFonts.poppins(
fontSize: 14, color: Colors.black54),
),
),
const SizedBox(height: 20),
ElevatedButton(
onPressed: () => Navigator.pop(context),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF891A2D),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(15),
),
padding: const EdgeInsets.symmetric(
vertical: 15, horizontal: 30),
),
child: Text(
"Selesai",
style:
GoogleFonts.poppins(fontSize: 16, color: Colors.white),
),
),
],
),
),
),
),
);
}
}