Files
rog_app/lib/widgets/list_widget.dart

83 lines
3.7 KiB
Dart
Raw Normal View History

2022-04-17 11:45:21 +05:30
import 'package:flutter/material.dart';
import 'package:geojson/geojson.dart';
import 'package:get/get.dart';
2022-09-22 20:36:56 +05:30
import 'package:rogapp/model/destination.dart';
import 'package:rogapp/pages/destination/destination_controller.dart';
2022-05-12 02:17:08 +05:30
import 'package:rogapp/pages/index/index_controller.dart';
2023-02-02 15:43:35 +05:30
import 'package:rogapp/utils/const.dart';
2022-06-27 12:15:54 +05:30
import 'package:rogapp/widgets/bottom_sheet_new.dart';
2022-04-17 11:45:21 +05:30
class ListWidget extends StatelessWidget {
ListWidget({ Key? key }) : super(key: key);
final IndexController indexController = Get.find<IndexController>();
2022-09-22 20:36:56 +05:30
final DestinationController destinationController = Get.find<DestinationController>();
2022-04-17 11:45:21 +05:30
Image getImage(int index){
if(indexController.locations[0].collection[index].properties!["photos"] == null || indexController.locations[0].collection[index].properties!["photos"] == ""){
2023-09-03 23:37:41 +05:30
return const Image(image: AssetImage('assets/images/empty_image.png'));
2022-04-17 11:45:21 +05:30
}
else{
2023-09-03 23:37:41 +05:30
print("==== photo index is $index ===");
String serverUrl = ConstValues.currentServer();
2023-02-02 15:43:35 +05:30
GeoJsonFeature<dynamic> gf = indexController.locations[0].collection[index];
2023-09-03 23:37:41 +05:30
String photo = gf.properties!["photos"];
2022-06-27 12:15:54 +05:30
return Image(
2023-02-02 15:43:35 +05:30
image: NetworkImage(
2023-09-03 23:37:41 +05:30
'$serverUrl/media/compressed/$photo'
2023-02-02 15:43:35 +05:30
),
2022-06-27 12:15:54 +05:30
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
return Image.asset("assets/images/empty_image.png");
},
);
2022-04-17 11:45:21 +05:30
}
}
void changeCurrentFeature(GeoJsonFeature fs){
2023-09-03 23:37:41 +05:30
if(indexController.currentFeature.isNotEmpty){
2022-04-17 11:45:21 +05:30
indexController.currentFeature.clear();
}
indexController.currentFeature.add(fs);
}
@override
Widget build(BuildContext context) {
return Obx(() =>
2023-09-03 23:37:41 +05:30
indexController.locations.isNotEmpty ?
2022-04-17 11:45:21 +05:30
ListView.builder(
itemCount: indexController.locations[0].collection.length,
shrinkWrap: true,
itemBuilder: (_, index){
2023-09-03 23:37:41 +05:30
bool isFound = false;
2022-09-22 20:36:56 +05:30
for(Destination d in destinationController.destinations){
if(indexController.locations[0].collection[index].properties!['location_id'] == d.location_id){
2023-09-03 23:37:41 +05:30
isFound = true;
2022-09-22 20:36:56 +05:30
break;
}
}
2022-04-17 11:45:21 +05:30
return Card(
child: ListTile(
2023-09-03 23:37:41 +05:30
selected: isFound,
2022-09-22 20:36:56 +05:30
selectedTileColor: Colors.yellow.shade200,
2022-04-17 11:45:21 +05:30
onTap: (){
GeoJsonFeature gf = indexController.locations[0].collection[index];
changeCurrentFeature(gf);
showModalBottomSheet(
isScrollControlled: true,
context: context,
2022-06-27 12:15:54 +05:30
//builder: (context) => BottomSheetWidget(),
builder:((context) => BottomSheetNew())
2022-04-17 11:45:21 +05:30
);
},
leading: getImage(index),
2023-09-03 23:37:41 +05:30
title: indexController.locations[0].collection[index].properties!['location_name'] != null ? Text(indexController.locations[0].collection[index].properties!['location_name'].toString()) : const Text(""),
subtitle: indexController.locations[0].collection[index].properties!['category'] != null ? Text(indexController.locations[0].collection[index].properties!['category']) : const Text(""),
trailing: indexController.locations[0].collection[index].properties!['sub_loc_id'] != null ? Text(indexController.locations[0].collection[index].properties!['sub_loc_id']) : const Text(""),
2022-04-17 11:45:21 +05:30
),
);
},
2023-09-03 23:37:41 +05:30
) : const SizedBox(width: 0, height: 0,),
2022-04-17 11:45:21 +05:30
);
}
}