ddd

asdsad
mail@pastecode.io avatar
unknown
dart
2 years ago
6.4 kB
5
Indexable
Never
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:netfleet_servis_kaptan/constants/app_configurations.dart';
import 'package:netfleet_servis_kaptan/rest/entity/gateway.dart';
import 'package:netfleet_servis_kaptan/rest/service/crud_service.dart';
import 'package:netfleet_servis_kaptan/rest/service/gateway_service.dart';
import 'package:netfleet_servis_kaptan/screen/StudentsSchemaPage.dart';
import 'package:netfleet_servis_kaptan/screen/VehicleTaskPage.dart';
import 'package:netfleet_servis_kaptan/utility/Colors.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';

import 'UserConfigPage.dart';


class DashboardPageView extends StatefulWidget {
  @override
  _DashboardPageViewState createState() => _DashboardPageViewState();
}

class _DashboardPageViewState extends State<DashboardPageView> {
  PageController pageController;
  int currentPageIndex = 0;

  @override
  void initState() {
    super.initState();
    pageController = PageController(initialPage: currentPageIndex);
    WidgetsBinding.instance.addPostFrameCallback((_) async {
      getAppVersionProvider();
      selectedModGetInstance();
    });
  }

  Future<void> getAppVersionProvider() async {
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    if(sharedPreferences.containsKey("serverId")){
      try {
        Gateway responseGateway = await GatewayService.requestForGatewayReturn(sharedPreferences.getString("serverId"));
        setupTransportationStatus.value = responseGateway.setupStatus;
        if(Platform.isAndroid){
          if(responseGateway.androidVersion.compareTo(AppConfigurations.appVersionControl)!=0){
            _showDialog("${responseGateway.androidUrl}");
          }
        }else if(Platform.isIOS){
          if(responseGateway.iosVersion.compareTo(AppConfigurations.appVersionControl)!=0){
            _showDialog(responseGateway.iosUrl);
          }
        }
      } catch (e) {

      }
    }
  }

  Future<void> selectedModGetInstance() async{
    SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
    if(sharedPreferences.containsKey("mod")){
      int statusMod = sharedPreferences.getInt("mod");
      setState(() {
        modeSelectedNow.value = statusMod;
      });
    }else{
      sharedPreferences.setInt("mod", 0);
      setState(() {
        modeSelectedNow.value = 0;
      });
    }

    print('---- ${modeSelectedNow.value}');
  }


  void _showDialog(String storeUrl) {
    print('STORE URLL $storeUrl');
    showDialog(
      context: context,
      builder: (BuildContext context) {
        // return object of type Dialog
        return AlertDialog(
          title: new Text("Uygulamayı güncelle"),
          content: new Text("Herhangi bir hata ile karşılaşmamak için lütfen uygulamayı güncelleyiniz. \n\nSizi mağazaya yönlendireceğiz"),
          actions: <Widget>[
            // usually buttons at the bottom of the dialog
            new FlatButton(
              child: new Text("Güncellemek için tıkla"),
              onPressed: () async{
                Navigator.of(context).pop();
                if (await canLaunch("$storeUrl")) {
                  await launch("$storeUrl");
                }
              },
            ),
          ],
        );
      },
    );
  }

  Future<bool> _onBackPressed() {
    return showDialog(
      context: context,
      builder: (context) => new AlertDialog(
        title: new Text('Uygulamadan Çık'),
        content:
        new Text('Uygulamadan tamamen çıkış mı yapmak istiyorsun?'),
        actions: <Widget>[
          new GestureDetector(
            onTap: () => Navigator.of(context).pop(true),
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text("Evet"),
            ),
          ),
          SizedBox(height: 16),
          new GestureDetector(
            onTap: () => Navigator.of(context).pop(false),
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text("Hayır"),
            ),
          ),
        ],
      ),
    ) ??
        false;
  }



  @override
  Widget build(BuildContext context) {
    final pages = [
      VehicleTaskPage(),
      StudentsSchemaPage(),
      UserConfigPage(),
    ];

    return WillPopScope(
      onWillPop:  _onBackPressed,
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: AppColors.mainColor,
          title: Text(
            getAppBarTitle(currentPageIndex),
            style: GoogleFonts.montserrat(
              color: Colors.white,
              fontWeight: FontWeight.w500,
            ),
          ),
          centerTitle: true,
          automaticallyImplyLeading: false,
        ),
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: currentPageIndex,
          items: navBarItems,
          backgroundColor: AppColors.mainColor,
          type: BottomNavigationBarType.fixed,
          selectedItemColor: Colors.white,
          unselectedItemColor: Colors.white.withOpacity(.4),
          onTap: (value) {
            setState(() {
              currentPageIndex = value;
            });
          },
        ),
        body: PageView.builder(
          controller: pageController,
          physics: NeverScrollableScrollPhysics(),
          itemBuilder: (context, index) => pages[currentPageIndex],
        ),
      ),
    );
  }

  List<BottomNavigationBarItem> navBarItems = [
    BottomNavigationBarItem(icon: Icon(FontAwesomeIcons.thList), label: 'Görevler'),
    BottomNavigationBarItem(icon: Icon(Icons.school), label: 'Öğrenciler'),
    BottomNavigationBarItem(icon: Icon(Icons.settings), label: 'Ayarlar'),
  ];

  String getAppBarTitle(int index) {
    switch (index) {
      case 0:
        return 'Yerlem Reis Görev';
        break;
      case 1:
        return 'Öğrencilerim';
        break;
      case 2:
        return 'Ayarlarım';
        break;
      default:
        return '';
    }
  }
}