import 'dart:convert'; import 'dart:ffi'; import 'package:tower_app/Screens/Menu/Canvasing/canvasingDetail_screen.dart'; import 'package:tower_app/Screens/Menu/Canvasing/getAll_post.dart'; import 'package:tower_app/Screens/Menu/History/getHistory_post.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'dart:developer' as logDev; import '../../background.dart'; class HistoryScreen extends StatefulWidget { const HistoryScreen({Key? key}) : super(key: key); @override State createState() => _HistoryScreen(); } class _HistoryScreen extends State { late List id_List; late List name_List; late List customer_List; late List telp_List; late List alamat_List; late List stage_List; late List statusColor; late List visible; int AllDataLength = 0; @override initState() { super.initState(); id_List = [""]; name_List = [""]; customer_List = [""]; telp_List = [""]; alamat_List = [""]; stage_List = [""]; visible = [false]; WidgetsBinding.instance.addPostFrameCallback((_) async { getHistoryData(); }); } getHistoryData() async { ProgressDialog loading = ProgressDialog(context); loading = ProgressDialog(context, type: ProgressDialogType.normal, isDismissible: false, showLogs: true); loading.style( message: 'Please Wait .....', borderRadius: 3, backgroundColor: Colors.white, progressWidget: CircularProgressIndicator(), elevation: 10.0, padding: EdgeInsets.all(10), insetAnimCurve: Curves.easeInOut, progress: 0.0, maxProgress: 100.0, progressTextStyle: TextStyle( color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400), messageTextStyle: TextStyle( color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600)); final SharedPreferences prefs = await SharedPreferences.getInstance(); int? user_id = prefs.getInt('user_id'); logDev.log(user_id!.toString(), name: "ID NYA BERAPA???!!!"); await loading.show(); GetHistory_Post.connectToAPI(user_id).then((valueResult) async { Map object = jsonDecode(valueResult); if (object.containsKey("result").toString() == "true") { String status = object['result']['status'].toString(); if (status.contains("failed")) { await loading.hide(); alertDialogFailedRetrievedData(context); } else if (status.contains("success")){ logDev.log(status, name: "SUCCeSS?"); List allData = object['result']['data']; await loading.hide(); setState(() { for (int i = 0; i < allData.length; i++){ String id = allData[i]['id'].toString(); String name = allData[i]['name'].toString(); String customer = allData[i]['customer'].toString(); String telp = allData[i]['telp'].toString(); String alamat = allData[i]['alamat'].toString(); String stage = allData[i]['stage'].toString(); if (customer == "false"){ customer ="-"; } if (telp == "false"){ telp = "-"; } if (alamat == "false"){ alamat = "-"; } id_List.add(id); name_List.add(name); customer_List.add(customer); telp_List.add(telp); alamat_List.add(alamat); stage_List.add(stage); visible.add(false); } id_List.removeAt(0); name_List.removeAt(0); customer_List.removeAt(0); telp_List.removeAt(0); alamat_List.removeAt(0); stage_List.removeAt(0); visible.removeAt(0); AllDataLength = allData.length; }); } } else { Fluttertoast.showToast( msg: "Server Response Error", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); } }); await loading.hide(); } @override Widget build(BuildContext context) { var size = MediaQuery.of(context).size; return Scaffold( body: Stack( children: [ Column( children: [ Stack( children: [ WavyHeader(), Container( margin: EdgeInsets.only( top: (size.height / 6) - 20), padding: EdgeInsets.fromLTRB(0, 5, 25, 5), child: Row( mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( 'CANVASING HISTORY\t\t', maxLines: 1, style: GoogleFonts.luckiestGuy( fontSize: 28, color: Color(0xFF4858A7), fontStyle: FontStyle.italic, ), ), Image.asset( 'assets/icons/menu/ic_history.png', width: 40, height: 40, ), ], ) ), ], ), ], ), Container( margin: EdgeInsets.only(top: (MediaQuery.of(context).size.height / 6) + 40, left: 5, right: 5, bottom: 10), child: ListView.builder( scrollDirection: Axis.vertical, shrinkWrap: true, itemCount: AllDataLength, itemBuilder: (context, int i) { return Container( child: InkWell( child: Card( elevation: 10, child: Column( children: [ Row( children: [ Expanded( flex: 10, child: Padding( padding: EdgeInsets.fromLTRB(10, 5, 5, 5), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ //Text(id_List[i], style: GoogleFonts.rubikBubbles(fontSize: 15)), Text(name_List[i], style: GoogleFonts.rubikBubbles(fontSize: 16)), Text(customer_List[i], style: GoogleFonts.nunito(fontSize: 15)), Text(telp_List[i], style: GoogleFonts.nunito(fontSize: 15)), Text(alamat_List[i], style: GoogleFonts.nunito(fontSize: 15)), Text("", style: GoogleFonts.nunito(fontSize: 14)), Text(stage_List[i], style: GoogleFonts.nunito(fontSize: 17, fontWeight: FontWeight.bold, color: Colors.blueAccent)), ], ), ) ), /*Expanded( flex: 2, child: Padding( padding: EdgeInsets.fromLTRB(5, 5, 5, 5), child: Text(status_List[i], textAlign: TextAlign.center, style: GoogleFonts.lilitaOne(color: statusColor[i], fontSize: 17), ), ) ),*/ ], ), /*Align( alignment: Alignment.centerLeft, child: Visibility( visible: visible[i], child: Padding( padding: EdgeInsets.fromLTRB(10, 5, 5, 5), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(telp_List[i], style: GoogleFonts.nunito(fontSize: 15)), Text(alamat_List[i], style: GoogleFonts.nunito(fontSize: 15)), ], ), ) ), )*/ ], ), ), onTap: (){ setState(() async { //visible[i] = !visible[i]; /* var prefs = await SharedPreferences.getInstance(); await prefs.setString('idDetail', id_List[i]); Navigator.push(context, MaterialPageRoute(builder: (context) => CanvasingDetail()));*/ }); }, ), ); }, ), ) ]), ); } } alertDialogFailedRetrievedData(BuildContext context) { Widget okButton = TextButton( child: Text("Refresh"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => HistoryScreen())); }, ); Widget noButton = TextButton( child: Text("Back"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pop(context); }, ); // set up the AlertDialog AlertDialog alert = AlertDialog( title: Text("Canvasing"), content: Text("Failed to Retrieve Data"), actions: [ noButton, okButton, ], ); // show the dialog showDialog( context: context, barrierDismissible: false, builder: (BuildContext context) { return alert; }, ); }