2024-09-02 ほぼOK
This commit is contained in:
@ -4,6 +4,8 @@ import 'package:flutter/material.dart';
|
||||
import 'package:gifunavi/model/destination.dart';
|
||||
import 'package:gifunavi/utils/database_helper.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
class HistoryPage extends StatefulWidget {
|
||||
const HistoryPage({super.key});
|
||||
@ -15,6 +17,48 @@ class HistoryPage extends StatefulWidget {
|
||||
class _HistoryPageState extends State<HistoryPage> {
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("pass_history".tr),
|
||||
),
|
||||
body: FutureBuilder<List<Destination>>(
|
||||
future: db.getDestinations(),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (snapshot.hasError) {
|
||||
return Center(child: Text('Error: ${snapshot.error}'));
|
||||
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
||||
return Center(child: Text("no_checkin_yet".tr));
|
||||
}
|
||||
|
||||
final dests = snapshot.data!;
|
||||
return ListView.builder(
|
||||
itemCount: dests.length,
|
||||
itemBuilder: (context, index) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: CustomWidget(
|
||||
title: dests[index].name ?? 'No Name',
|
||||
subtitle: "${dests[index].sub_loc_id ?? 'N/A'} : ${dests[index].name ?? 'N/A'}",
|
||||
image1Path: dests[index].checkin_image,
|
||||
image2Path: dests[index].buypoint_image,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
class _HistoryPageState_old extends State<HistoryPage> {
|
||||
DatabaseHelper db = DatabaseHelper.instance;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@ -86,8 +130,97 @@ class _HistoryPageState extends State<HistoryPage> {
|
||||
);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
class CustomWidget extends StatelessWidget {
|
||||
final String? image1Path;
|
||||
final String? image2Path;
|
||||
final String title;
|
||||
final String subtitle;
|
||||
|
||||
const CustomWidget({
|
||||
super.key,
|
||||
this.image1Path,
|
||||
this.image2Path,
|
||||
required this.title,
|
||||
required this.subtitle,
|
||||
});
|
||||
|
||||
Widget _buildImage(String? path) {
|
||||
if (path == null) return const SizedBox.shrink();
|
||||
|
||||
return FutureBuilder<String>(
|
||||
future: _getFullImagePath(path),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done && snapshot.hasData) {
|
||||
return Image.file(
|
||||
File(snapshot.data!),
|
||||
width: 50,
|
||||
height: 100,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
print('Error loading image: $error');
|
||||
return const Icon(Icons.error);
|
||||
},
|
||||
);
|
||||
} else if (snapshot.hasError) {
|
||||
print('Error loading image path: ${snapshot.error}');
|
||||
return const Icon(Icons.error);
|
||||
} else {
|
||||
return const CircularProgressIndicator();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<String> _getFullImagePath(String imagePath) async {
|
||||
final appDir = await getApplicationDocumentsDirectory();
|
||||
final fileName = path.basename(imagePath);
|
||||
final fullPath = path.join(appDir.path, fileName);
|
||||
debugPrint("Full image path: $fullPath");
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 104,
|
||||
child: Row(
|
||||
children: [
|
||||
_buildImage(image1Path),
|
||||
if (image1Path != null && image2Path != null) const SizedBox(width: 2),
|
||||
_buildImage(image2Path),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
maxLines: null,
|
||||
),
|
||||
Text(
|
||||
subtitle,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
maxLines: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
class CustomWidget_old extends StatelessWidget {
|
||||
final Image? image1;
|
||||
final Image? image2;
|
||||
final String title;
|
||||
@ -152,3 +285,4 @@ class CustomWidget extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
*/
|
||||
Reference in New Issue
Block a user