123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- import 'dart:convert';
- import 'dart:ffi';
-
- 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 'package:tower_app/Screens/Menu/Survey/detailsurvey_screen.dart';
- import 'package:tower_app/Screens/Menu/Survey/editsurvey_screen.dart';
- import 'package:tower_app/Screens/Menu/Survey/getlistsurvey_post.dart';
- import 'dart:developer' as logDev;
-
- import '../../background.dart';
-
- class ListSurveyScreen extends StatefulWidget {
- const ListSurveyScreen({Key? key}) : super(key: key);
-
- @override
- State<ListSurveyScreen> createState() => _ListSurveyScreen();
- }
-
- class _ListSurveyScreen extends State<ListSurveyScreen> {
- late List <int> id_List;
- late List <String> name_List;
- late List <String> date_List;
- late List <String> site_List;
- late List <String> state_List;
- late List <Color> stateColor;
- //late List <bool> visibleEditButton;
-
- int AllDataLength = 0;
-
- @override
- initState() {
- super.initState();
- id_List = [0];
- name_List = [""];
- date_List = [""];
- site_List = [""];
- state_List = [""];
- stateColor = [Colors.blueAccent];
- //visibleEditButton = [false];
-
- WidgetsBinding.instance.addPostFrameCallback((_) async {
- getListSurvey();
- });
- }
-
- getListSurvey() 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();
- GetListSurvey_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++){
- int id = allData[i]['id'];
- String name = allData[i]['name'].toString();
- String date = allData[i]['date'].toString();
- String site = allData[i]['site'].toString();
- String state = allData[i]['state'].toString();
-
- id_List.add(id);
- name_List.add(name);
- date_List.add(date);
- site_List.add(site);
- //state_List.add(state);
- if (state == "done"){
- stateColor.add(Colors.blueAccent);
- state_List.add("Done");
- } else if (state == "approved"){
- stateColor.add(Colors.deepOrangeAccent);
- state_List.add("Approved");
- }
- }
-
- id_List.removeAt(0);
- name_List.removeAt(0);
- date_List.removeAt(0);
- site_List.removeAt(0);
- state_List.removeAt(0);
- stateColor.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(
- 'SURVEY\t\t',
- maxLines: 1,
- style: GoogleFonts.luckiestGuy(
- fontSize: 28,
- color: Color(0xFF4858A7),
- fontStyle: FontStyle.italic,
- ),
- ),
- Image.asset(
- 'assets/icons/menu/survey_3.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.breeSerif(fontSize: 18, fontWeight: FontWeight.bold)),
- Text("Date\t:\t" + date_List[i], style: GoogleFonts.nunito(fontSize: 15)),
- Text("Site\t\t\t:\t" + site_List[i], style: GoogleFonts.nunito(fontSize: 15)),
- Container(margin: EdgeInsets.only(bottom: 5, right: 10, top:10),
- child: Align
- (alignment: Alignment.centerRight,
- child: Text(state_List[i], style: GoogleFonts.nunito(fontSize: 16, color: stateColor[i])))),
- /*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: Visibility(
- visible: visibleEditButton[i],
- child: Padding(
- padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text("hello", style: GoogleFonts.nunito(fontSize: 15)),
- ],
- ),
- )
- ),
- ),*/
- ],
- ),
- /*Align(
- alignment: Alignment.centerLeft,
- child: Visibility(
- visible: visibleEditButton[i],
- child: Padding(
- padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text("Edit", style: GoogleFonts.nunito(fontSize: 15)),
- ],
- ),
- )
- ),
- )*/
- ],
- ),
- ),
- onTap: () async {
- var prefs = await SharedPreferences.getInstance();
- await prefs.setInt('idDetail', id_List[i]);
- await prefs.setString('nameDetail', name_List[i]);
- await prefs.setString('dateDetail', date_List[i]);
- await prefs.setString('siteDetail', site_List[i]);
- setState(() {
- if (state_List[i] == "Approved"){
- Navigator.push(context, MaterialPageRoute(builder: (context) => EditSurveyScreen()));
- } else if (state_List[i] == "Done") {
- Navigator.push(context, MaterialPageRoute(builder: (context) => DetailSurveyScreen()));
- }
- });
-
- },
- ),
- );
- },
- ),
- )
- ]),
- );
- }
- }
-
-
- alertDialogFailedRetrievedData(BuildContext context) {
- Widget okButton = TextButton(
- child: Text("Refresh"),
- onPressed: () {
- Navigator.of(context, rootNavigator: true).pop();
- Navigator.pushReplacement(
- context, MaterialPageRoute(builder: (context) => ListSurveyScreen()));
- },
- );
-
- 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("POC Bakti"),
- content: Text("Failed to Retrieve Data"),
- actions: [
- noButton,
- okButton,
- ],
- );
-
- // show the dialog
- showDialog(
- context: context,
- barrierDismissible: false,
- builder: (BuildContext context) {
- return alert;
- },
- );
- }
|