219 lines
8.8 KiB
Dart
219 lines
8.8 KiB
Dart
import 'dart:ffi';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:geojson/geojson.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:rogapp/model/destination.dart';
|
|
import 'package:rogapp/pages/destination/destination_controller.dart';
|
|
import 'package:rogapp/pages/index/index_controller.dart';
|
|
import 'package:rogapp/widgets/bottom_sheet_new.dart';
|
|
import 'package:rogapp/widgets/bottom_sheet_widget.dart';
|
|
import 'package:timeline_tile/timeline_tile.dart';
|
|
|
|
class DestinationWidget extends StatelessWidget {
|
|
DestinationWidget({ Key? key }) : super(key: key);
|
|
|
|
final DestinationController destinationController = Get.find<DestinationController>();
|
|
|
|
final IndexController indexController = Get.find<IndexController>();
|
|
|
|
final List<int> _items = List<int>.generate(50, (int index) => index);
|
|
|
|
Image getImage(int index){
|
|
if(destinationController.destinations[index].photos== null || destinationController.destinations[index].photos == ""){
|
|
return Image(image: AssetImage('assets/images/empty_image.png'));
|
|
}
|
|
else{
|
|
print("------- image is ${destinationController.destinations[index].photos!}------");
|
|
return Image(image: NetworkImage(
|
|
destinationController.destinations[index].photos!),
|
|
errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
|
|
return Image.asset("assets/images/empty_image.png");
|
|
},
|
|
);
|
|
}
|
|
}
|
|
|
|
bool getSelection(int index){
|
|
bool ret = false;
|
|
destinationController.destination_index_data.forEach((element) {
|
|
if(index == element["index"]){
|
|
if(element["selected"] == true){
|
|
ret = true;
|
|
return;
|
|
}
|
|
}
|
|
});
|
|
return ret;
|
|
}
|
|
|
|
void doDelete() {
|
|
destinationController.currentSelectedDestinations.forEach((element) {
|
|
destinationController.deleteDestination(element);
|
|
});
|
|
// destinationController.destination_index_data.forEach((element) {
|
|
// //print(element["index"]);
|
|
// destinationController.deleteDestination(element["index"]);
|
|
// });
|
|
// destinationController.destination_index_data.clear();
|
|
}
|
|
|
|
void moveUp() {
|
|
destinationController.destination_index_data.forEach((element) {
|
|
//print(element["index"]);
|
|
//int action_id = destinationController.destinations[element["index"]]["id"] as int;
|
|
//destinationController.makeOrder(action_id, (element["index"] as int) - 1, "up");
|
|
});
|
|
}
|
|
|
|
void moveDown() {
|
|
destinationController.destination_index_data.forEach((element) {
|
|
//print(element["index"]);
|
|
//int action_id = destinationController.destinations[element["index"]]["id"] as int;
|
|
//destinationController.makeOrder(action_id, (element["index"] as int) + 1, "up");
|
|
});
|
|
}
|
|
|
|
void interChange() {
|
|
// int first_index = -1;
|
|
// destinationController.destination_index_data.forEach((element) {
|
|
// //print(element["index"]);
|
|
// int action_id = destinationController.destinations[element["index"]]["id"] as int;
|
|
// destinationController.makeOrder(action_id, (element["index"] as int) + 1, "up");
|
|
|
|
// });
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
print("------ destination widget------ ${destinationController.destinationCount.value} ----------");
|
|
|
|
return
|
|
Obx(() =>
|
|
Stack(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(top:45.0),
|
|
child: ListView.builder(
|
|
itemCount: destinationController.destinationCount.value,
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return
|
|
TimelineTile(
|
|
alignment: TimelineAlign.manual,
|
|
lineXY: 0.2,
|
|
isFirst: index == 0 ? true : false,
|
|
indicatorStyle: IndicatorStyle(
|
|
color: index == 0 ? (Colors.red) : (Colors.grey[400])!
|
|
),
|
|
key: Key(index.toString()),
|
|
endChild: Card(
|
|
child: Container(
|
|
constraints: const BoxConstraints(
|
|
minHeight: 80,
|
|
),
|
|
child: ListTile(
|
|
onTap: () async {
|
|
{
|
|
Destination? fs = destinationController.destinations[index];
|
|
print("----fsf-----${fs}");
|
|
if(fs != null){
|
|
|
|
if(indexController.currentDestinationFeature.length > 0) {
|
|
indexController.currentDestinationFeature.clear();
|
|
}
|
|
indexController.currentDestinationFeature.add(fs);
|
|
//indexController.getAction();
|
|
|
|
showModalBottomSheet(context: context, isScrollControlled: true,
|
|
//builder:((context) => BottomSheetWidget())
|
|
builder:((context) => BottomSheetNew())
|
|
);
|
|
}
|
|
};
|
|
},
|
|
onLongPress: (){
|
|
|
|
Destination? match_element = null;
|
|
destinationController.currentSelectedDestinations.forEach((element) {
|
|
if(element.location_id == destinationController.destinations[index].location_id){
|
|
match_element = element;
|
|
return;
|
|
}
|
|
});
|
|
|
|
if(match_element != null){
|
|
destinationController.currentSelectedDestinations.remove(destinationController.destinations[index]);
|
|
}
|
|
|
|
destinationController.currentSelectedDestinations.add(destinationController.destinations[index]);
|
|
|
|
destinationController.PopulateDestinations();
|
|
|
|
},
|
|
selectedTileColor: Colors.amberAccent,
|
|
selected:destinationController.destinations[index].selected!,
|
|
leading: getImage(index),
|
|
title: Text(destinationController.destinations[index].name!),
|
|
subtitle: Text(destinationController.destinations[index].category!),
|
|
),
|
|
),
|
|
),
|
|
startChild:
|
|
destinationController.matrix["rows"][0]["elements"] != null ?
|
|
Column(
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
//Text(destinationController.matrix["rows"][0]["elements"][index]["distance"]["text"].toString()),
|
|
//Text(destinationController.matrix["rows"][0]["elements"][index]["duration"]["text"].toString())
|
|
],
|
|
):
|
|
Container()
|
|
,
|
|
);
|
|
|
|
}
|
|
),
|
|
),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.3),
|
|
spreadRadius: 5,
|
|
blurRadius: 3,
|
|
offset: Offset(0, 7), // changes position of shadow
|
|
),
|
|
],
|
|
),
|
|
height: 44.0,
|
|
width: MediaQuery.of(context).size.width,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
IconButton(
|
|
icon:Icon(Icons.cancel),
|
|
//onPressed: (){doDelete();},
|
|
onPressed: destinationController.currentSelectedDestinations.length > 0 ? doDelete : null,
|
|
),
|
|
IconButton(
|
|
icon:Icon(Icons.move_up),
|
|
onPressed: destinationController.destination_index_data.length > 0 ? moveUp : null,
|
|
),
|
|
IconButton(
|
|
icon:Icon(Icons.move_down),
|
|
onPressed: destinationController.destination_index_data.length > 0 ? moveDown : null,
|
|
),
|
|
IconButton(
|
|
icon:Icon(Icons.sync),
|
|
onPressed: destinationController.destination_index_data.length == 2 ? interChange : null,
|
|
),
|
|
],
|
|
),
|
|
)
|
|
],
|
|
)
|
|
);
|
|
}
|
|
} |