update
This commit is contained in:
@ -12,6 +12,7 @@ class DestinationController extends GetxController {
|
|||||||
|
|
||||||
List<dynamic> destinations = <dynamic>[].obs;
|
List<dynamic> destinations = <dynamic>[].obs;
|
||||||
List<Map<String, dynamic>> destination_index_data = <Map<String, dynamic>>[].obs;
|
List<Map<String, dynamic>> destination_index_data = <Map<String, dynamic>>[].obs;
|
||||||
|
|
||||||
Map<String, dynamic> matrix = {};
|
Map<String, dynamic> matrix = {};
|
||||||
|
|
||||||
final IndexController indexController = Get.find<IndexController>();
|
final IndexController indexController = Get.find<IndexController>();
|
||||||
@ -22,6 +23,15 @@ class DestinationController extends GetxController {
|
|||||||
super.onInit();
|
super.onInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deleteDestination(int index){
|
||||||
|
int id = destinations[index]["id"];
|
||||||
|
DestinationService.deleteDestination(id).then((val){
|
||||||
|
destination_index_data.clear();
|
||||||
|
PopulateDestinations();
|
||||||
|
print("####### dest id : ${id}");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void PopulateDestinations(){
|
void PopulateDestinations(){
|
||||||
if(indexController.currentUser.isNotEmpty){
|
if(indexController.currentUser.isNotEmpty){
|
||||||
int user_id = indexController.currentUser[0]["user"]["id"] as int;
|
int user_id = indexController.currentUser[0]["user"]["id"] as int;
|
||||||
|
|||||||
@ -68,34 +68,6 @@ class _DestinationPageState extends State<DestinationPage> {
|
|||||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
||||||
appBar:AppBar(
|
appBar:AppBar(
|
||||||
title: Text("Iternery"),
|
title: Text("Iternery"),
|
||||||
actions: [
|
|
||||||
PopupMenuButton(
|
|
||||||
icon: Icon(Icons.more_vert),
|
|
||||||
itemBuilder: (BuildContext context) => <PopupMenuEntry>[
|
|
||||||
const PopupMenuItem(
|
|
||||||
child: ListTile(
|
|
||||||
leading: Icon(Icons.cut),
|
|
||||||
title: Text('Cut'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const PopupMenuItem(
|
|
||||||
child: ListTile(
|
|
||||||
leading: Icon(Icons.paste),
|
|
||||||
title: Text('Paste'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const PopupMenuItem(
|
|
||||||
child: ListTile(
|
|
||||||
leading: Icon(Icons.delete),
|
|
||||||
title: Text('Delete'),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// const PopupMenuDivider(),
|
|
||||||
// const PopupMenuItem(child: Text('Item A')),
|
|
||||||
// const PopupMenuItem(child: Text('Item B')),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
body: Obx(() =>
|
body: Obx(() =>
|
||||||
indexController.desination_mode.value == 0 ?
|
indexController.desination_mode.value == 0 ?
|
||||||
|
|||||||
@ -23,6 +23,23 @@ class DestinationService{
|
|||||||
return cats;
|
return cats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Future<Map<String, dynamic>> deleteDestination(int dest_id) async {
|
||||||
|
Map<String, dynamic> cats = {};
|
||||||
|
String url = "http://container.intranet.sumasen.net:8100/api/delete_destination/?dest_id=${dest_id}";
|
||||||
|
final http.Response response = await http.get(
|
||||||
|
Uri.parse(url),
|
||||||
|
headers: <String, String>{
|
||||||
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
cats = json.decode(utf8.decode(response.bodyBytes));
|
||||||
|
}
|
||||||
|
print("####### ---- ${cats}");
|
||||||
|
return cats;
|
||||||
|
}
|
||||||
|
|
||||||
static Future<int> updateOrder(int action_id, int order, String dir) async {
|
static Future<int> updateOrder(int action_id, int order, String dir) async {
|
||||||
int cats = 0;
|
int cats = 0;
|
||||||
String url = "http://container.intranet.sumasen.net:8100/api/updateorder/?user_action_id=${action_id}&order=${order}&dir=${dir}";
|
String url = "http://container.intranet.sumasen.net:8100/api/updateorder/?user_action_id=${action_id}&order=${order}&dir=${dir}";
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:ffi';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:rogapp/pages/destination/destination_controller.dart';
|
import 'package:rogapp/pages/destination/destination_controller.dart';
|
||||||
@ -22,25 +24,63 @@ class DestinationWidget extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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.destination_index_data.forEach((element) {
|
||||||
|
//print(element["index"]);
|
||||||
|
destinationController.deleteDestination(element["index"]);
|
||||||
|
});
|
||||||
|
// destinationController.destination_index_data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveUp() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveDown() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void interChange() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return
|
return
|
||||||
ReorderableListView.builder(
|
Obx(() =>
|
||||||
|
Stack(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top:45.0),
|
||||||
|
child: ListView.builder(
|
||||||
itemCount: destinationController.destinations.length,
|
itemCount: destinationController.destinations.length,
|
||||||
onReorder: (int oldIndex, int newIndex){
|
// onReorder: (int oldIndex, int newIndex){
|
||||||
int action_id = destinationController.destinations[oldIndex]["id"] as int;
|
// int action_id = destinationController.destinations[oldIndex]["id"] as int;
|
||||||
//print(action_id);
|
// //print(action_id);
|
||||||
if(oldIndex > newIndex){
|
// if(oldIndex > newIndex){
|
||||||
destinationController.makeOrder(context, action_id, newIndex, "up");
|
// destinationController.makeOrder(context, action_id, newIndex, "up");
|
||||||
}
|
// }
|
||||||
else if(oldIndex < newIndex){
|
// else if(oldIndex < newIndex){
|
||||||
destinationController.makeOrder(context, action_id, newIndex, "down");
|
// destinationController.makeOrder(context, action_id, newIndex, "down");
|
||||||
}
|
// }
|
||||||
|
|
||||||
},
|
// },
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return TimelineTile(
|
return
|
||||||
|
TimelineTile(
|
||||||
alignment: TimelineAlign.manual,
|
alignment: TimelineAlign.manual,
|
||||||
lineXY: 0.2,
|
lineXY: 0.2,
|
||||||
isFirst: index == 0 ? true : false,
|
isFirst: index == 0 ? true : false,
|
||||||
@ -55,23 +95,31 @@ class DestinationWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
onLongPress: (){
|
onLongPress: (){
|
||||||
print("----- selected index ${index}");
|
print("#### long press #### ${destinationController.destination_index_data.length}");
|
||||||
var el = destinationController.destination_index_data.where((element) =>
|
|
||||||
element["index"] == index
|
var match_element = null;
|
||||||
);
|
destinationController.destination_index_data.forEach((element) {
|
||||||
if(el != null){
|
if(element["index"] == index){
|
||||||
destinationController.destination_index_data.remove(el);
|
match_element = element;
|
||||||
|
print("----match----");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
print("------${el}---- index ${index}");
|
});
|
||||||
|
if(match_element != null){
|
||||||
|
destinationController.destination_index_data.remove(match_element);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//print("------${destinationController.destination_index_data}----");
|
||||||
Map<String, dynamic> indexed = {'index': index, 'selected':true};
|
Map<String, dynamic> indexed = {'index': index, 'selected':true};
|
||||||
destinationController.destination_index_data.add(indexed);
|
destinationController.destination_index_data.add(indexed);
|
||||||
},
|
},
|
||||||
|
selectedTileColor: Colors.amberAccent,
|
||||||
|
selected:getSelection(index),
|
||||||
leading: getImage(index),
|
leading: getImage(index),
|
||||||
title: Text(destinationController.destinations[index]["location"]["properties"]["location_name"]),
|
title: Text(destinationController.destinations[index]["location"]["properties"]["location_name"]),
|
||||||
subtitle: Text(destinationController.destinations[index]["location"]["properties"]["category"]),
|
subtitle: Text(destinationController.destinations[index]["location"]["properties"]["category"]),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
),
|
),
|
||||||
startChild: Column(
|
startChild: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
@ -81,7 +129,48 @@ class DestinationWidget extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
),
|
||||||
|
),
|
||||||
|
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.destination_index_data.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,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user