Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class _WorkingScreenState extends State<WorkingScreen> {
- int pageIndex = 0;
- String? chooseLocation;
- late Future<Response> futureData;
- late Future<Response> futureDataForAccount;
- late Future<Response> futureDataForStatus;
- Timer? timer;
- List<WorkingLocationData>? workingData;
- List<AccountData>? accountData;
- bool shouldPop = true;
- bool _flag = true;
- Response? response;
- Future<Response?> postLocationId(String? id) async {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- String? authorization = prefs.getString('authorization');
- var url = 'https://dev.api.wurk.skyver.co/api/$id/workingTimeframes';
- try {
- response = await http.post(
- Uri.parse(url),
- headers: <String, String>{
- 'authorization': authorization ?? basicAuth.toString(),
- "Content-Type": "application/json"
- },
- );
- print(id);
- print(response!.statusCode);
- } catch (er) {}
- return response;
- }
- final _formKey = GlobalKey<FormState>();
- @override
- void initState() {
- super.initState();
- futureData = fetchWorkingLocationData();
- futureDataForAccount = fetchAccountData();
- }
- @override
- Widget build(BuildContext context) {
- var width = MediaQuery.of(context).size.width;
- var height = MediaQuery.of(context).size.height;
- return Form(
- key: _formKey,
- child: WillPopScope(
- onWillPop: () async {
- return shouldPop;
- },
- child: SafeArea(
- child: Scaffold(
- body: FutureBuilder<List<Response>>(
- future: Future.wait([futureData, futureDataForAccount]),
- builder: (context, snapshot) {
- if (snapshot.hasData) {
- List<WorkingLocationData> data1 =
- parsedData(snapshot.data![0].body);
- workingData = data1;
- AccountData data3 =
- AccountData.fromJson(json.decode(snapshot.data![1].body));
- //WorkingLocationStatus statusData = WorkingLocationStatus.fromJson(json.decode(snapshot.data![2].body));
- return Column(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Container(
- width: width,
- height: 50,
- decoration: BoxDecoration(
- border: Border.all(
- color: Colors.black,
- width: 4,
- ),
- ),
- child: Center(
- child: Text(
- 'Welcome ' + data3.firstName + ' ${data3.lastName}',
- style: const TextStyle(fontSize: 18),
- ),
- ),
- ),
- const Text(
- 'Choose working location',
- style: TextStyle(fontSize: 23),
- ),
- Container(
- width: width * 0.860,
- padding: const EdgeInsets.symmetric(
- horizontal: 12, vertical: 4),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(12),
- border: Border.all(color: Colors.black, width: 4),
- ),
- child: DropdownButtonFormField<String>(
- decoration: const InputDecoration(
- enabledBorder: UnderlineInputBorder(
- borderSide: BorderSide(color: Colors.transparent),
- ),
- ),
- value: chooseLocation,
- hint: const Text('Select a location'),
- isExpanded: true,
- items: workingData!.map((some) {
- return DropdownMenuItem(
- child: Text(some.name + ' (${some.location})'),
- value: some.id,
- );
- }).toList(),
- onChanged: (String? displayedValue) {
- setState(
- () {
- chooseLocation = displayedValue!;
- },
- );
- },
- validator: (value) {
- if (value == '') {
- return 'Please select a working location';
- }
- return null;
- },
- ),
- ),
- SizedBox(height: height * 0.150),
- Column(
- children: [
- Container(
- width: width / 2.5,
- height: height / 10,
- child: ElevatedButton(
- onPressed: () async {
- final WorkingLocationData locationData =
- workingData!.firstWhere(
- (some) => some.id == chooseLocation);
- await postLocationId(locationData.id);
- setState(() {
- _flag = !_flag;
- });
- },
- child: Text(
- _flag ? 'Start Work' : 'Stop Work',
- style: const TextStyle(fontSize: 20),
- ),
- style: ElevatedButton.styleFrom(
- primary: _flag ? Colors.teal : Colors.red,
- ),
- ),
- ),
- ],
- ),
- SizedBox(
- height: height * 0.01,
- )
- ],
- );
- } else if (snapshot.hasError) {
- return Text('${snapshot.error}');
- }
- return const Center(child: CircularProgressIndicator());
- },
- ),
- bottomNavigationBar: bottomNavigationBar1(context),
- ),
- ),
- ),
- );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement