import 'dart:convert';
import 'dart:io';
import 'dart:io' as Io;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_absolute_path/flutter_absolute_path.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:image_picker/image_picker.dart';
import 'package:modal_progress_hud/modal_progress_hud.dart';
import 'package:multi_image_picker/multi_image_picker.dart';
import 'package:shinewash_employee/api/api.dart';
import 'package:shinewash_employee/screens/employee_profile.dart';

const darkBlue = Color(0xFF265E9E);
const extraDarkBlue = Color(0xFF91B4D8);
const ratingStar = Color(0xFFFECD03);

class EditProfile extends StatefulWidget {
  @override
  _EditProfileState createState() => _EditProfileState();
}

class _EditProfileState extends State<EditProfile>
    with SingleTickerProviderStateMixin {
  final _formKey = GlobalKey<FormState>();
  TextEditingController emplyeeName = TextEditingController();
  TextEditingController emplyeeAbout = TextEditingController();
  TextEditingController emplyeeExperience = TextEditingController();
  FocusNode oldpass = FocusNode();
  FocusNode newpass = FocusNode();
  FocusNode conpass = FocusNode();
  String _name = '';
  String _about = '';
  String _phone = '';
  String _email = '';
  int _experience;
  TextEditingController _oldPassword = TextEditingController();
  TextEditingController _newPassword = TextEditingController();
  TextEditingController _confirmPassword = TextEditingController();
  String startdropdownValue = '';
  String enddropdownValue = '';
  bool changeImageIndication = false;

  File _image;
  var image;
  var image64;
  var imageData;
  bool showSnipper = false;
  TabController _tabController;
  List<Asset> images = List<Asset>();
  List files = [];
  List<Asset> resultList;
  String _error = 'No Error Dectected';
  String _completeImage = '';
  List<String> timeSlot = [];

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 3, vsync: this);
    _tabController.addListener(_handleTabSelection);
    _getProfile();
    getTimeSlotData();
  }

  Future<void> changePassword(data) async {
    setState(() {
      showSnipper = true;
    });
    var res =
        await CallApi().postDataWithToken(data, 'employee_change_password');
    var body = json.decode(res.body);
    try {
      if (body['success'] == true) {
        var theData = body['data'];
        // print('the data is $theData');
        // print('the success is ${body['success']}');
        setState(() {
          Navigator.pushReplacement(
              context,
              MaterialPageRoute(
                builder: (context) => EditProfile(),
              ));
          showSnipper = false;
        });
      } else {
        showDialog(
          builder: (context) => AlertDialog(
            title: Text('Update Error'),
            content: Text(body['data']),
            actions: <Widget>[
              FlatButton(
                onPressed: () async {
                  Navigator.pop(context);
                  setState(() {
                    showSnipper = false;
                  });
                },
                child: Text('OK'),
              )
            ],
          ),
          context: context,
        );
      }
    } catch (e) {
      showDialog(
        builder: (context) => AlertDialog(
          title: Text('Update Error'),
          content: Text(e.toString()),
          actions: <Widget>[
            FlatButton(
              onPressed: () async {
                Navigator.pop(context);
                setState(() {
                  showSnipper = false;
                });
              },
              child: Text('OK'),
            )
          ],
        ),
        context: context,
      );
    }
  }

  Future<void> _getProfile() async {
    setState(() {
      showSnipper = true;
    });
    var res = await CallApi().getWithToken('employee');
    var body = json.decode(res.body);
    var theData = body['data'];
    // print('thedata is = $theData');
    setState(() {
      _completeImage = theData['completeImage'];
      _name = theData['name'];
      _email = theData['email'];
      _about = theData['description'];
      _phone = theData['phone'];
      startdropdownValue = theData['start_time'];
      enddropdownValue = theData['end_time'];
      _experience = theData['experience'];
      if (_experience == null) {
        _experience = 0;
      }
    });
    // print('the skill is $_about');
    setState(() {
      showSnipper = false;
    });
  }

  Future<void> getTimeSlotData() async {
    setState(() {
      showSnipper = true;
    });
    var res = await CallApi().getWithToken('timeslots');
    var body = json.decode(res.body);
    var theData = body['data'];

    for (int i = 0; i < theData.length; i++) {
      timeSlot.add(theData[i]['time']);
    }
    setState(() {
      // startdropdownValue = timeSlot[0];
      // enddropdownValue = timeSlot[1];
      showSnipper = false;
    });
    // print('timeslot is $timeSlot');
  }

  Future<void> setEmplyoeeData(data) async {
    setState(() {
      showSnipper = true;
    });
    var res = await CallApi().postDataWithToken(data, 'update_employee');
    var body = json.decode(res.body);
    // print('body is $body');
    try {
      if (body['success'] == true) {
        var theData = body['data'];
        // print(theData);
        // print('success is ${body['success']}');
        setState(() {
          showSnipper = false;
          Navigator.pushReplacement(
              context, MaterialPageRoute(builder: (context) => EditProfile()));
        });
      } else {
        showDialog(
          builder: (context) => AlertDialog(
            title: Text('Update Error'),
            content: Text(body['message']),
            actions: <Widget>[
              FlatButton(
                onPressed: () async {
                  Navigator.pop(context);
                  setState(() {
                    showSnipper = false;
                  });
                },
                child: Text('OK'),
              )
            ],
          ),
          context: context,
        );
      }
    } catch (e) {
      showDialog(
        builder: (context) => AlertDialog(
          title: Text('Update Error'),
          content: Text(e.toString()),
          actions: <Widget>[
            FlatButton(
              onPressed: () async {
                Navigator.pop(context);
                setState(() {
                  showSnipper = false;
                });
              },
              child: Text('OK'),
            )
          ],
        ),
        context: context,
      );
    }
  }

  Future<void> updateImage() async {
    setState(() {
      showSnipper = true;
    });
    var res =
        await CallApi().postDataWithToken(imageData, 'update_employee_image');
    var body = json.decode(res.body);
    if (body['success'] == true) {
      Navigator.pushReplacement(
          context,
          MaterialPageRoute(
            builder: (context) => EditProfile(),
          ));
    } else {
      showDialog(
        builder: (context) => AlertDialog(
          title: Text('Image error'),
          content: Text(body['data'].toString()),
          actions: <Widget>[
            FlatButton(
              onPressed: () async {
                Navigator.pop(context);
                setState(() {
                  showSnipper = false;
                });
              },
              child: Text('OK'),
            )
          ],
        ),
        context: context,
      );
    }
  }

  _imgFromCamera() async {
    image = await ImagePicker.pickImage(
        source: ImageSource.camera, imageQuality: 50);
    final bytes = Io.File(image.path).readAsBytesSync();
    String img64 = base64Encode(bytes);
    image64 = img64;
    setState(() {
      _image = image;
      imageData = {"image": "$image64"};
    });
  }

  _imgFromGallery() async {
    File image = await ImagePicker.pickImage(
        source: ImageSource.gallery, imageQuality: 50);
    final bytes = Io.File(image.path).readAsBytesSync();
    String img64 = base64Encode(bytes);
    image64 = img64;
    setState(() {
      _image = image;
      imageData = {"image": "$image64"};
    });
  }

  void _showPicker(context) {
    showModalBottomSheet(
        context: context,
        builder: (BuildContext bc) {
          return SafeArea(
            child: Container(
              child: new Wrap(
                children: <Widget>[
                  new ListTile(
                      leading: new Icon(Icons.photo_library),
                      title: new Text('Photo Library'),
                      onTap: () {
                        _imgFromGallery();
                        Navigator.of(context).pop();
                      }),
                  new ListTile(
                    leading: new Icon(Icons.photo_camera),
                    title: new Text('Camera'),
                    onTap: () {
                      _imgFromCamera();
                      Navigator.of(context).pop();
                    },
                  ),
                ],
              ),
            ),
          );
        });
  }

  void _handleTabSelection() {
    setState(() {});
  }

  getImageFileFromAsset(String path) async {
    final file = File(path);
    return file;
  }

  submit() async {
    for (int i = 0; i < images.length; i++) {
      var path2 =
          await FlutterAbsolutePath.getAbsolutePath(images[i].identifier);
      var file = await getImageFileFromAsset(path2);
      var base64Image = base64Encode(file.readAsBytesSync());
      files.add(base64Image);
      // Navigator.push(
      //     context,
      //     MaterialPageRoute(
      //       builder: (context) => showContent(
      //         files: files,
      //       ),
      //     ));
      // showDialog(
      //     context: context,
      //     child: AlertDialog(
      //       title: Text('image'),
      //       content: Text('$files'),
      //       actions: [
      //         FlatButton(
      //             onPressed: () => Navigator.pop(context), child: Text('data'))
      //       ],
      //     ));
      // print('files is $files');
      // var arrayIs = files;
      // var convertIs = json.encode(files);
      var data = {
        "image": json.encode(base64Image),
      };
      // print(data);
      try {
        var res = await CallApi().postDataWithToken(data, 'add_portfolio');
        // var response = await http.post(data, 'url')
        var body = jsonDecode(res.body);
        // print('the image response is $body');
        // print('the image response of success ${body['success']}');
        if (body['success'] == "true") {
          print('posted successfully!');
        } else {
          Fluttertoast.showToast(
              msg: body['msg'],
              toastLength: Toast.LENGTH_SHORT,
              gravity: ToastGravity.CENTER,
              timeInSecForIosWeb: 1,
              backgroundColor: Colors.red,
              textColor: Colors.white,
              fontSize: 16.0);
          // _showToast(context, );
        }
      } catch (e) {
        return print(e.toString());
      }
    }
  }

  Future<void> loadAssets() async {
    // List<Asset> resultList = List<Asset>();
    String error = 'No Error Dectected';

    try {
      resultList = await MultiImagePicker.pickImages(
        maxImages: 15,
        enableCamera: true,
        selectedAssets: images,
        cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
        materialOptions: MaterialOptions(
          actionBarColor: "#6B48FF",
          actionBarTitle: "Shinewash App",
          allViewTitle: "All Photos",
          useDetailsView: false,
          selectCircleStrokeColor: "#000000",
        ),
      );
    } on Exception catch (e) {
      error = e.toString();
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      images = resultList;
      _error = error;
    });
  }

  Widget buildGridView() {
    if (images != null) {
      return GridView.count(
        crossAxisCount: 3,
        children: List.generate(images.length, (index) {
          Asset asset = images[index];
          // print('emplyeee images is ');
          return Padding(
            padding: const EdgeInsets.all(8.0),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(10.0),
              child: Stack(
                children: [
                  AssetThumb(
                    asset: asset,
                    width: 300,
                    height: 300,
                  ),
                  // Positioned(
                  //   right: 5,
                  //   top: 5,
                  //   child: IconButton(
                  //       padding: EdgeInsets.zero,
                  //       alignment: Alignment.topRight,
                  //       icon: Icon(
                  //         Icons.remove_circle,
                  //         color: Colors.red,
                  //       ),
                  //       onPressed: () {
                  //         // print('remove');
                  //       }),
                  // ),
                ],
              ),
            ),
          );
        }),
      );
    } else
      return Center(
          child: Container(
        child: Text('No Images'),
      ));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: PreferredSize(
          preferredSize:
              Size.fromHeight(MediaQuery.of(context).size.height / 2.9), //3.5
          child: ModalProgressHUD(
            inAsyncCall: showSnipper,
            child: SafeArea(
              child: AppBar(
                leading: IconButton(
                  icon: Icon(Icons.chevron_left),
                  iconSize: 25.0,
                  onPressed: () {
                    Navigator.pop(context);
                  },
                ),
                bottom: PreferredSize(
                  preferredSize: Size(MediaQuery.of(context).size.width, 70.0),
                  child: Container(
                    decoration: BoxDecoration(
                        // color: Colors.transparent,
                        color: Color(0xFFE9F0F7),
                        borderRadius: BorderRadius.vertical(
                            bottom: Radius.circular(0.0))),
                    child: TabBar(
                      unselectedLabelColor: Color(0xFF265E9E),
                      labelColor: Theme.of(context).primaryColor,
                      labelStyle: TextStyle(
                        color: Theme.of(context).primaryColor,
                        fontSize: 18,
                        fontFamily: 'FivoSansMedium',
                      ),
                      unselectedLabelStyle: TextStyle(
                        color: Color(0xFF91B4D8),
                        fontSize: 18,
                        fontFamily: 'FivoSansMedium',
                      ),
                      indicatorColor: Colors.white,
                      tabs: [
                        Tab(
                          child: Text(
                            'Profile',
                          ),
                        ),
                        Tab(
                          child: Text(
                            'Password',
                          ),
                        ),
                        Tab(
                          child: Text(
                            'Portfolio',
                          ),
                        ),
                      ],
                      controller: _tabController,
                    ),
                  ),
                ),
                flexibleSpace: Container(
                  decoration: BoxDecoration(
                    color: Theme.of(context).primaryColor,
                    borderRadius:
                        BorderRadius.vertical(bottom: Radius.circular(50.0)),
                  ),
                  child: Center(
                    child: Column(
                      children: [
                        SizedBox(height: 30.0),
                        Stack(
                          children: [
                            Container(
                              decoration: BoxDecoration(
                                shape: BoxShape.circle,
                                color: Colors.white,
                                border: Border.all(
                                  color: Colors.white,
                                  width: 3.0,
                                ),
                              ),
                              child: CircleAvatar(
                                radius: 50,
                                child: _image != null
                                    ? ClipRRect(
                                        borderRadius: BorderRadius.circular(50),
                                        child: Image.file(
                                          _image,
                                          width: 100,
                                          height: 100,
                                          fit: BoxFit.fill,
                                        ),
                                      )
                                    : ClipRRect(
                                        borderRadius: BorderRadius.circular(50),
                                        child: Image.network(
                                          _completeImage,
                                          width: 100,
                                          height: 100,
                                          fit: BoxFit.fill,
                                        ),
                                      ),
                              ),
                            ),
                            Positioned(
                              bottom: 1.0,
                              right: 1.0,
                              child: Container(
                                height: 35.0,
                                width: 35.0,
                                decoration: BoxDecoration(
                                  color: Colors.white,
                                  shape: BoxShape.circle,
                                ),
                                child: IconButton(
                                  onPressed: () {
                                    changeImageIndication = true;
                                    _showPicker(context);
                                  },
                                  padding: EdgeInsets.zero,
                                  icon: Icon(
                                    Icons.camera_alt,
                                    color: darkBlue,
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                ),
                elevation: 0.0,
              ),
            ),
          ),
        ),
        body: ModalProgressHUD(
          inAsyncCall: showSnipper,
          child: TabBarView(
            children: [
              //first tab
              SingleChildScrollView(
                child: Column(
                  children: [
                    Container(
                      margin: EdgeInsets.all(15.0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                'Name',
                                style: TextStyle(
                                  color: extraDarkBlue,
                                  fontSize: 14,
                                  fontFamily: 'FivoSansRegular',
                                ),
                              ),
                              TextFormField(
                                // controller: emplyeeName,
                                controller: TextEditingController()
                                  ..text = _name,
                                onFieldSubmitted: (value) {
                                  setState(() {
                                    _name = value;
                                  });
                                },
                                // initialValue: _name,
                                maxLines: 1,
                                enableSuggestions: false,
                                keyboardType: TextInputType.visiblePassword,
                                decoration: InputDecoration(
                                  hintText: 'Ruth Stanley',
                                  hintStyle: TextStyle(
                                    color: darkBlue,
                                    fontSize: 18,
                                    fontFamily: 'FivoSansMedium',
                                    letterSpacing: 0.2,
                                  ),
                                ),
                                style: TextStyle(
                                  color: darkBlue,
                                  fontSize: 18,
                                  fontFamily: 'FivoSansMedium',
                                  letterSpacing: 0.2,
                                ),
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 15.0,
                          ),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                'About',
                                style: TextStyle(
                                  color: extraDarkBlue,
                                  fontSize: 14,
                                  fontFamily: 'FivoSansRegular',
                                ),
                              ),
                              TextFormField(
                                controller: TextEditingController()
                                  ..text = _about,
                                onFieldSubmitted: (value) {
                                  setState(() {
                                    _about = value;
                                  });
                                },
                                // controller: emplyeeAbout,
                                // initialValue: _about,
                                maxLines: 5,
                                enableSuggestions: false,
                                keyboardType: TextInputType.visiblePassword,
                                decoration: InputDecoration(
                                  hintText: 'Write Something about yourself',
                                  hintStyle: TextStyle(
                                    color: darkBlue,
                                    fontSize: 18,
                                    fontFamily: 'FivoSansMedium',
                                    letterSpacing: 0.2,
                                  ),
                                ),
                                style: TextStyle(
                                  color: darkBlue,
                                  fontSize: 18,
                                  fontFamily: 'FivoSansMedium',
                                  letterSpacing: 0.2,
                                ),
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 15.0,
                          ),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                'Experience',
                                style: TextStyle(
                                  color: extraDarkBlue,
                                  fontSize: 14,
                                  fontFamily: 'FivoSansRegular',
                                ),
                              ),
                              TextFormField(
                                controller: TextEditingController()
                                  ..text = _experience.toString(),
                                onFieldSubmitted: (value) {
                                  setState(() {
                                    _experience = int.parse(value);
                                  });
                                },
                                // controller: emplyeeExperience,
                                // initialValue: _experience.toString(),
                                onChanged: (value) {
                                  int a = int.parse(value);
                                  setState(() {
                                    _experience = a;
                                  });
                                },
                                maxLines: 1,
                                enableSuggestions: false,
                                keyboardType: TextInputType.visiblePassword,
                                decoration: InputDecoration(
                                  hintText: '0',
                                  hintStyle: TextStyle(
                                    color: darkBlue,
                                    fontSize: 18,
                                    fontFamily: 'FivoSansMedium',
                                    letterSpacing: 0.2,
                                  ),
                                ),
                                style: TextStyle(
                                  color: darkBlue,
                                  fontSize: 18,
                                  fontFamily: 'FivoSansMedium',
                                  letterSpacing: 0.2,
                                ),
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 20.0,
                          ),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                'Phone',
                                style: TextStyle(
                                  color: extraDarkBlue,
                                  fontSize: 14,
                                  fontFamily: 'FivoSansRegular',
                                ),
                              ),
                              TextField(
                                controller: TextEditingController()
                                  ..text = _phone,
                                readOnly: true,
                                decoration: InputDecoration(
                                  suffixIcon: Container(
                                    margin: EdgeInsets.all(10.0),
                                    height: 22,
                                    width: 61,
                                    decoration: BoxDecoration(
                                      color: Colors.green,
                                      borderRadius: BorderRadius.all(
                                          Radius.circular(30.0)),
                                    ),
                                    child: Center(
                                      child: Text(
                                        'Verified',
                                        style: TextStyle(
                                          color: Colors.white,
                                          fontSize: 12,
                                          fontFamily: 'Rubik',
                                          letterSpacing: 0.3,
                                        ),
                                      ),
                                    ),
                                  ),
                                  hintText: '+1 903 698 8574',
                                  hintStyle: TextStyle(
                                    color: darkBlue,
                                    fontSize: 18,
                                    fontFamily: 'FivoSansMedium',
                                    letterSpacing: 0.2,
                                  ),
                                ),
                                style: TextStyle(
                                  color: darkBlue,
                                  fontSize: 18,
                                  fontFamily: 'FivoSansMedium',
                                  letterSpacing: 0.2,
                                ),
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 15.0,
                          ),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                'Email',
                                style: TextStyle(
                                  color: extraDarkBlue,
                                  fontSize: 14,
                                  fontFamily: 'FivoSansRegular',
                                ),
                              ),
                              TextField(
                                controller: TextEditingController()
                                  ..text = _email,
                                maxLines: 1,
                                readOnly: true,
                                enableSuggestions: false,
                                keyboardType: TextInputType.visiblePassword,
                                decoration: InputDecoration(
                                  suffixIcon: Container(
                                    margin: EdgeInsets.all(10.0),
                                    height: 22,
                                    width: 61,
                                    decoration: BoxDecoration(
                                      color: Colors.green,
                                      borderRadius: BorderRadius.all(
                                          Radius.circular(30.0)),
                                    ),
                                    child: Center(
                                      child: Text(
                                        'Verified',
                                        style: TextStyle(
                                          color: Colors.white,
                                          fontSize: 12,
                                          fontFamily: 'Rubik',
                                          letterSpacing: 0.3,
                                        ),
                                      ),
                                    ),
                                  ),
                                  hintText: 'ruthstanley@gmail.com',
                                  hintStyle: TextStyle(
                                    color: darkBlue,
                                    fontSize: 18,
                                    fontFamily: 'FivoSansMedium',
                                    letterSpacing: 0.2,
                                  ),
                                ),
                                style: TextStyle(
                                  color: darkBlue,
                                  fontSize: 18,
                                  fontFamily: 'FivoSansMedium',
                                  letterSpacing: 0.2,
                                ),
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 20.0,
                          ),
                          Row(
                            children: [
                              Text(
                                'Start Time',
                                style: TextStyle(
                                  color: darkBlue,
                                  fontSize: 14,
                                  fontFamily: 'FivoSansRegular',
                                ),
                              ),
                              SizedBox(
                                width: 10.0,
                              ),
                              DropdownButton<String>(
                                style: TextStyle(
                                  color: darkBlue,
                                  fontSize: 18,
                                  fontFamily: 'FivoSansMedium',
                                ),
                                elevation: 0,
                                isExpanded: false,
                                underline: Container(
                                  color: Colors.transparent,
                                ),
                                value: startdropdownValue,
                                onChanged: (String newValue) {
                                  setState(() {
                                    startdropdownValue = newValue;
                                  });
                                },
                                items: timeSlot.map<DropdownMenuItem<String>>(
                                    (String value) {
                                  return DropdownMenuItem<String>(
                                    value: value,
                                    child: Text(value),
                                  );
                                }).toList(),
                              ),
                            ],
                          ),
                          Row(
                            children: [
                              Text(
                                'End Time',
                                style: TextStyle(
                                  color: darkBlue,
                                  fontSize: 14,
                                  fontFamily: 'FivoSansRegular',
                                ),
                              ),
                              SizedBox(
                                width: 10.0,
                              ),
                              DropdownButton<String>(
                                style: TextStyle(
                                  color: darkBlue,
                                  fontSize: 18,
                                  fontFamily: 'FivoSansMedium',
                                ),
                                elevation: 0,
                                isExpanded: false,
                                underline: Container(
                                  color: Colors.transparent,
                                ),
                                value: enddropdownValue,
                                onChanged: (String newValue) {
                                  setState(() {
                                    enddropdownValue = newValue;
                                  });
                                },
                                items: timeSlot.map<DropdownMenuItem<String>>(
                                    (String value) {
                                  return DropdownMenuItem<String>(
                                    value: value,
                                    child: Text(value),
                                  );
                                }).toList(),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
                    SizedBox(
                      height: 20.0,
                    ),
                    Container(
                        height: 50,
                        width: MediaQuery.of(context).size.width,
                        child: RaisedButton(
                          onPressed: () {
                            // print('Save');
                            // print('experience is $_experience');
                            if (_experience != null && _experience >= 0) {
                              // var a = 12:30 AM;
                              var body = {
                                'name': _name.toString(),
                                'start_time': startdropdownValue.toString(),
                                'end_time': enddropdownValue.toString(),
                                'experience': _experience.toInt(),
                                'description': _about.toString(),
                              };
                              // print('thebody is $body');
                              setEmplyoeeData(body);
                            }
                            if (changeImageIndication) {
                              updateImage();
                              changeImageIndication = false;
                            }
                          },
                          color: Theme.of(context).primaryColor,
                          child: Text(
                            'SAVE',
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 18.0,
                              fontFamily: 'FivoSansMedium',
                            ),
                          ),
                        )),
                  ],
                ),
              ),
              //second tab
              SingleChildScrollView(
                child: Form(
                  key: _formKey,
                  child: Column(
                    children: [
                      Container(
                        margin: EdgeInsets.all(15.0),
                        alignment: Alignment.center,
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            SizedBox(
                              height: 10,
                            ),
                            Text(
                              'Change Password',
                              style: TextStyle(
                                color: darkBlue,
                                fontSize: 18.0,
                                fontFamily: 'FivoSansMedium',
                              ),
                            ),
                            SizedBox(
                              height: 20,
                            ),
                            Text(
                              'Current Password',
                              style: TextStyle(
                                color: extraDarkBlue,
                                fontSize: 14,
                                fontFamily: 'FivoSansRegular',
                              ),
                            ),
                            TextFormField(
                              controller: _oldPassword,
                              validator: (value) {
                                if (value.isEmpty) {
                                  return "Please Enter Password";
                                } else if (value.length < 6) {
                                  return "Password must be atleast 6 characters long";
                                } else {
                                  return null;
                                }
                              },
                              focusNode: oldpass,
                              onFieldSubmitted: (a) {
                                oldpass.unfocus();
                                FocusScope.of(context).requestFocus(newpass);
                              },
                              obscureText: true,
                              decoration: InputDecoration(
                                hintText: '*******',
                                hintStyle: TextStyle(
                                  color: darkBlue,
                                  fontSize: 18,
                                  fontFamily: 'FivoSansMedium',
                                  letterSpacing: 0.2,
                                ),
                              ),
                              style: TextStyle(
                                color: darkBlue,
                                fontSize: 18,
                                fontFamily: 'FivoSansMedium',
                                letterSpacing: 0.2,
                              ),
                            ),
                            SizedBox(height: 20.0),
                            Text(
                              'New Password',
                              style: TextStyle(
                                color: extraDarkBlue,
                                fontSize: 14,
                                fontFamily: 'FivoSansRegular',
                              ),
                            ),
                            TextFormField(
                              controller: _newPassword,
                              validator: (value) {
                                if (value.isEmpty) {
                                  return "Please Enter Password";
                                } else if (value.length < 6) {
                                  return "Password must be atleast 6 characters long";
                                } else {
                                  return null;
                                }
                              },
                              focusNode: newpass,
                              onFieldSubmitted: (a) {
                                newpass.unfocus();
                                FocusScope.of(context).requestFocus(conpass);
                              },
                              obscureText: true,
                              decoration: InputDecoration(
                                hintText: '*******',
                                hintStyle: TextStyle(
                                  color: darkBlue,
                                  fontSize: 18,
                                  fontFamily: 'FivoSansMedium',
                                  letterSpacing: 0.2,
                                ),
                              ),
                              style: TextStyle(
                                color: darkBlue,
                                fontSize: 18,
                                fontFamily: 'FivoSansMedium',
                                letterSpacing: 0.2,
                              ),
                            ),
                            SizedBox(height: 20.0),
                            Text(
                              'Confirm Password',
                              style: TextStyle(
                                color: extraDarkBlue,
                                fontSize: 14,
                                fontFamily: 'FivoSansRegular',
                              ),
                            ),
                            TextFormField(
                              controller: _confirmPassword,
                              validator: (value) {
                                if (value.isEmpty) {
                                  return "Please Enter Password";
                                } else if (value != _newPassword.text) {
                                  return "Password must be same as above";
                                } else {
                                  return null;
                                }
                              },
                              focusNode: conpass,
                              onFieldSubmitted: (a) {
                                conpass.unfocus();
                              },
                              obscureText: true,
                              decoration: InputDecoration(
                                hintText: '*******',
                                hintStyle: TextStyle(
                                  color: darkBlue,
                                  fontSize: 18,
                                  fontFamily: 'FivoSansMedium',
                                  letterSpacing: 0.2,
                                ),
                              ),
                              style: TextStyle(
                                color: darkBlue,
                                fontSize: 18,
                                fontFamily: 'FivoSansMedium',
                                letterSpacing: 0.2,
                              ),
                            ),
                            SizedBox(height: 40.0),
                          ],
                        ),
                      ),
                      SizedBox(
                        height: 20.0,
                      ),
                      Container(
                          height: 50,
                          width: MediaQuery.of(context).size.width,
                          child: RaisedButton(
                            onPressed: () {
                              // print('Save');
                              if (changeImageIndication) {
                                updateImage();
                                changeImageIndication = false;
                              }
                              if (_formKey.currentState.validate()) {
                                var body = {
                                  'old_password': _oldPassword.text,
                                  'password': _newPassword.text,
                                  'password_confirmation':
                                      _confirmPassword.text,
                                };
                                changePassword(body);
                              }
                            },
                            color: Theme.of(context).primaryColor,
                            child: Text(
                              'SAVE',
                              style: TextStyle(
                                color: Colors.white,
                                fontSize: 18.0,
                                fontFamily: 'FivoSansMedium',
                              ),
                            ),
                          )),
                    ],
                  ),
                ),
              ),
              //third tab
              Container(
                margin: EdgeInsets.all(15.0),
                child: Column(
                  children: <Widget>[
                    // Center(child: Text('Error: $_error')),
                    Expanded(
                      child: buildGridView(),
                    ),
                    SizedBox(
                      height: 10.0,
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        RaisedButton(
                          onPressed: () {
                            submit();
                            Navigator.pushReplacement(
                                context,
                                MaterialPageRoute(
                                  builder: (context) => EmployeeProfile(),
                                ));
                            // if (changeImageIndication) {
                            //   updateImage();
                            //   changeImageIndication = false;
                            // }
                          },
                          color: Theme.of(context).primaryColor,
                          child: Text(
                            'SAVE',
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 18.0,
                              fontFamily: 'FivoSansMedium',
                            ),
                          ),
                        ),
                        Container(
                            height: 45.0,
                            width: 45.0,
                            decoration: BoxDecoration(
                                color: Theme.of(context).primaryColor,
                                shape: BoxShape.circle),
                            child: IconButton(
                                icon: Icon(
                                  Icons.add,
                                  color: Colors.white,
                                ),
                                onPressed: loadAssets)),
                        // RaisedButton(
                        //   color: Theme.of(context).primaryColor,
                        //   child: Text(
                        //     "Pick images",
                        //     style: TextStyle(
                        //       color: Colors.white,
                        //       fontSize: 18,
                        //       fontFamily: 'FivoSansMedium',
                        //       // fontWeight: FontWeight.w600,
                        //     ),
                        //   ),
                        //   onPressed: loadAssets,
                        // ),
                      ],
                    ),
                  ],
                ),
              ),
            ],
            controller: _tabController,
          ),
        ));
  }
}

class showContent extends StatelessWidget {
  final files;

  const showContent({Key key, this.files}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView(
        children: [
          TextField(
            controller: TextEditingController()..text = files.toString(),
            maxLines: 20,
          ),
        ],
      ),
    );
  }
}
