Files
rog_app/lib/pages/history/history_page.dart
2023-09-06 15:25:12 +05:30

77 lines
2.8 KiB
Dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/utils/database_helper.dart';
class HistoryPage extends StatefulWidget {
const HistoryPage({super.key});
@override
State<HistoryPage> createState() => _HistoryPageState();
}
class _HistoryPageState extends State<HistoryPage> {
DatabaseHelper db = DatabaseHelper.instance;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("History"),
),
body: SingleChildScrollView(
child: Column(
children: [
FutureBuilder(
future: db.getDestinations(),
builder: (BuildContext context,
AsyncSnapshot<List<Destination>> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
return Center(
child: Text(
'${snapshot.error} occurred',
style: TextStyle(fontSize: 18),
),
);
} else if (snapshot.hasData) {
final dests = snapshot.data;
if (dests!.length > 0) {
print("----- history -----");
return Container(
width: MediaQuery.of(context).size.width,
height: 150,
child: Expanded(
child: ListView.builder(
itemCount: dests.length,
itemBuilder: (ctx, index) {
return ListTile(
title: Text(dests[index].name ?? ""),
subtitle:
Text(dests[index].address ?? ""),
leading: dests[0].photos != null
? Container(width: 100, height: 100, child: Image.file(File(dests[0].photos!)))
: Container(),
);
}),
));
} else {
return Center(child: Text("No checkin yet"));
}
}
} else if (snapshot.connectionState ==
ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
return Container();
}),
],
),
),
);
}
}