Files
rog_app/lib/widgets/destination_widget.dart

302 lines
12 KiB
Dart
Raw Normal View History

2022-05-24 20:43:41 +05:30
import 'package:flutter/material.dart';
import 'package:get/get.dart';
2022-07-09 22:51:34 +05:30
import 'package:rogapp/model/destination.dart';
2022-05-24 20:43:41 +05:30
import 'package:rogapp/pages/destination/destination_controller.dart';
import 'package:rogapp/pages/index/index_controller.dart';
2022-11-05 22:02:21 +05:30
import 'package:rogapp/utils/const.dart';
2022-09-22 20:36:56 +05:30
import 'package:rogapp/utils/database_helper.dart';
2022-06-27 12:15:54 +05:30
import 'package:rogapp/widgets/bottom_sheet_new.dart';
2022-05-24 20:43:41 +05:30
import 'package:timeline_tile/timeline_tile.dart';
class DestinationWidget extends StatelessWidget {
2023-09-06 21:36:11 +05:30
DestinationWidget({Key? key}) : super(key: key);
2022-05-24 20:43:41 +05:30
2023-09-06 21:36:11 +05:30
final DestinationController destinationController =
Get.find<DestinationController>();
2022-05-24 20:43:41 +05:30
final IndexController indexController = Get.find<IndexController>();
final List<int> _items = List<int>.generate(50, (int index) => index);
2023-09-06 21:36:11 +05:30
Image getImage(int index) {
if (destinationController.destinations[index].photos == null ||
destinationController.destinations[index].photos == "") {
2023-08-16 14:53:32 +05:30
return const Image(image: AssetImage('assets/images/empty_image.png'));
2023-09-06 21:36:11 +05:30
} else {
print(
"------- image is ${destinationController.destinations[index].photos!}------");
2022-09-29 15:32:33 +05:30
String _photo = destinationController.destinations[index].photos!;
2023-09-06 21:36:11 +05:30
if (_photo.contains('http')) {
return Image(
image:
NetworkImage(destinationController.destinations[index].photos!),
errorBuilder:
(BuildContext context, Object exception, StackTrace? stackTrace) {
return Image.asset("assets/images/empty_image.png");
},
);
} else {
String serverUrl = ConstValues.currentServer();
//print("==== photo is ${server_url + '/media/compressed/' + destinationController.destinations[index].photos!} ===");
return Image(
image: NetworkImage('$serverUrl/media/compressed/' +
destinationController.destinations[index].photos!),
errorBuilder:
(BuildContext context, Object exception, StackTrace? stackTrace) {
return Image.asset("assets/images/empty_image.png");
},
);
}
2022-05-24 20:43:41 +05:30
}
}
2022-10-30 21:43:29 +05:30
// 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;
// }
2022-05-25 21:00:10 +05:30
void doDelete() {
2023-08-16 14:53:32 +05:30
for (var element in destinationController.currentSelectedDestinations) {
2022-07-10 23:50:43 +05:30
destinationController.deleteDestination(element);
2022-10-30 21:43:29 +05:30
destinationController.resetRogaining();
2023-08-16 14:53:32 +05:30
}
2022-07-10 23:50:43 +05:30
// destinationController.destination_index_data.forEach((element) {
// //print(element["index"]);
// destinationController.deleteDestination(element["index"]);
// });
2022-05-25 21:00:10 +05:30
// destinationController.destination_index_data.clear();
}
void moveUp() {
2023-08-16 14:53:32 +05:30
Destination? d;
2023-09-06 21:36:11 +05:30
for (Destination ad in destinationController.destinations) {
if (ad.selected == true) {
2022-09-23 18:40:17 +05:30
d = ad;
break;
}
}
2023-09-06 21:36:11 +05:30
if (d != null) {
2022-09-23 18:40:17 +05:30
print("--- selected destination is ${d.list_order}");
destinationController.makeOrder(d, -1);
2022-09-22 20:36:56 +05:30
}
2022-05-25 21:00:10 +05:30
}
void moveDown() {
2023-08-16 14:53:32 +05:30
Destination? d;
2023-09-06 21:36:11 +05:30
for (Destination ad in destinationController.destinations) {
if (ad.selected == true) {
2022-09-23 18:40:17 +05:30
d = ad;
break;
}
}
2023-09-06 21:36:11 +05:30
if (d != null) {
2022-09-23 18:40:17 +05:30
print("--- selected destination is ${d.list_order}");
destinationController.makeOrder(d, 1);
}
}
2023-09-06 21:36:11 +05:30
void clearall() {
2022-09-23 18:40:17 +05:30
Get.defaultDialog(
2023-09-06 21:36:11 +05:30
title: "are_you_sure_want_to_delete_all".tr,
middleText: "all_added_destination_will_be_deleted".tr,
backgroundColor: Colors.blue.shade300,
titleStyle: const TextStyle(color: Colors.white),
middleTextStyle: const TextStyle(color: Colors.white),
textConfirm: "confirm".tr,
textCancel: "cancel".tr,
cancelTextColor: Colors.white,
confirmTextColor: Colors.blue,
buttonColor: Colors.white,
barrierDismissible: false,
radius: 10,
content: const Column(
children: [],
),
onConfirm: () {
destinationController.deleteAllDestinations();
Get.back();
Get.snackbar(
"deleted".tr, "all_destinations_are_deleted_successfully".tr);
});
2022-05-25 21:00:10 +05:30
}
void interChange() {
2022-07-09 22:51:34 +05:30
// 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");
2022-06-04 20:16:29 +05:30
2022-07-09 22:51:34 +05:30
// });
2022-05-25 21:00:10 +05:30
}
2023-08-16 14:53:32 +05:30
Future getIsLocationAvilable(int locationId) async {
2022-09-22 20:36:56 +05:30
DatabaseHelper db = DatabaseHelper.instance;
2023-08-16 14:53:32 +05:30
return await db.isAlreadyAvailable(locationId);
2022-09-22 20:36:56 +05:30
}
2022-05-24 20:43:41 +05:30
@override
Widget build(BuildContext context) {
2023-09-06 21:36:11 +05:30
print(
"------ destination widget------ ${destinationController.destinationCount.value} ----------");
2022-07-09 22:51:34 +05:30
2023-09-06 21:36:11 +05:30
return Obx(() => Stack(
2022-05-25 21:00:10 +05:30
children: [
2023-09-06 21:36:11 +05:30
Padding(
padding: const EdgeInsets.only(top: 45.0),
child: ListView.builder(
2022-06-29 18:25:19 +05:30
itemCount: destinationController.destinationCount.value,
2022-05-25 21:00:10 +05:30
itemBuilder: (BuildContext context, int index) {
2023-09-06 21:36:11 +05:30
return TimelineTile(
alignment: TimelineAlign.manual,
lineXY: 0.2,
isFirst: index == 0 ? true : false,
indicatorStyle: IndicatorStyle(
indicator: CircleAvatar(
child: Text(
destinationController.destinations[index].list_order
.toString(),
style: const TextStyle(color: Colors.white),
),
backgroundColor: Colors.red,
),
2022-09-22 20:36:56 +05:30
),
2023-09-06 21:36:11 +05:30
key: Key(index.toString()),
endChild: Card(
child: Container(
constraints: const BoxConstraints(
minHeight: 80,
),
child: ListTile(
onTap: () async {
{
Destination? fs =
destinationController.destinations[index];
2023-08-16 14:53:32 +05:30
print("----fsf-----$index");
2023-09-06 21:36:11 +05:30
if (indexController
.currentDestinationFeature.isNotEmpty) {
indexController.currentDestinationFeature
.clear();
2022-06-14 14:37:59 +05:30
}
2023-09-06 21:36:11 +05:30
indexController.currentDestinationFeature
.add(fs);
print(
"--- ndexController.currentDestinationFeature ----- ${indexController.currentDestinationFeature[0].name} ----");
2023-08-16 14:53:32 +05:30
//indexController.getAction();
2023-09-06 21:36:11 +05:30
showModalBottomSheet(
constraints: BoxConstraints.loose(
Size(Get.width, Get.height * 0.75)),
context: context,
isScrollControlled: true,
//builder:((context) => BottomSheetWidget())
2023-09-14 22:53:51 +05:30
builder: ((context) => BottomSheetNew(destination: fs,)));
2023-09-06 21:36:11 +05:30
}
},
onLongPress: () {
destinationController.toggleSelection(
destinationController.destinations[index]);
},
selectedTileColor: Colors.amberAccent,
selected: destinationController
.destinations[index].selected!,
leading: getImage(index),
title: Text(destinationController
.destinations[index].name!),
subtitle: Text(destinationController
.destinations[index].category!),
),
2022-05-25 21:00:10 +05:30
),
),
2023-09-06 21:36:11 +05:30
startChild: index > 0 &&
destinationController.matrix["routes"][0]
["legs"] !=
null
? Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Text(destinationController.matrix["routes"][0]
["legs"][index - 1]["distance"] !=
null
? destinationController.matrix["routes"][0]
["legs"][index - 1]["distance"]
["text"]
.toString()
: ''),
Text(destinationController.matrix["routes"][0]
["legs"][index - 1]["duration"] !=
null
? destinationController.matrix["routes"][0]
["legs"][index - 1]["duration"]
["text"]
.toString()
: '')
],
)
: Container(),
);
}),
2022-05-24 20:43:41 +05:30
),
2023-09-06 21:36:11 +05:30
Container(
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.3),
spreadRadius: 5,
blurRadius: 3,
offset: const Offset(0, 7), // changes position of shadow
),
],
),
height: 44.0,
width: MediaQuery.of(context).size.width,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
icon: const Icon(Icons.delete_forever),
//onPressed: (){doDelete();},
onPressed: clearall,
),
IconButton(
icon: const Icon(Icons.cancel),
//onPressed: (){doDelete();},
onPressed: destinationController
.currentSelectedDestinations.isNotEmpty
? doDelete
: null,
),
IconButton(
icon: const Icon(Icons.move_up),
onPressed: destinationController
.currentSelectedDestinations.isNotEmpty
? moveUp
: null,
),
IconButton(
icon: const Icon(Icons.move_down),
onPressed: destinationController
.currentSelectedDestinations.isNotEmpty
? moveDown
: null,
),
// IconButton(
// icon:Icon(Icons.sync),
// onPressed: destinationController.destination_index_data.length == 2 ? interChange : null,
// ),
],
),
)
2022-05-25 21:00:10 +05:30
],
2023-09-06 21:36:11 +05:30
));
2022-05-24 20:43:41 +05:30
}
2023-09-06 21:36:11 +05:30
}