123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- import 'dart:convert';
- import 'dart:ffi';
-
- import 'package:employee_selfservice_mobile/Screens/Menu/Canvasing/canvasingDetail_screen.dart';
- import 'package:employee_selfservice_mobile/Screens/Menu/Canvasing/getAll_post.dart';
- import 'package:employee_selfservice_mobile/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<HistoryScreen> createState() => _HistoryScreen();
- }
-
- class _HistoryScreen extends State<HistoryScreen> {
- late List <String> id_List;
- late List <String> name_List;
- late List <String> customer_List;
- late List <String> telp_List;
- late List <String> alamat_List;
- late List <String> stage_List;
-
- late List <Color> statusColor;
- late List <bool> 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<String, dynamic> 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 <dynamic> 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: <Widget>[
- 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;
- },
- );
- }
|