Untitled

version & connection checkers
 avatar
unknown
dart
3 years ago
6.1 kB
3
Indexable
  
  bool versionCheck = false;
  bool connectionCheck = false;

  if (Platform.isAndroid) {
    await WebServices.versionControl('6', '100').then((value) {
      if (value != null) {
        versionCheck = value;
        connectionCheck = true;
      }
    }).timeout(Duration(seconds: 5), onTimeout: () {
      connectionCheck = false;
    });
  }

---------------------------------
!connectionCheck
          ? ConnectionCheckFailed()
          : !versionCheck
              ? VersionCheckFailed()
              : 
-------------------------
connection_check_failed.dart:
--------------------------

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class ConnectionCheckFailed extends StatelessWidget {
  const ConnectionCheckFailed({Key key}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;
    return Scaffold(
      body: Container(
        color: Colors.grey[700],
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Padding(
                padding: EdgeInsets.all(width * .075),
                child: Container(
                  padding: EdgeInsets.all(width * .075),
                  decoration: BoxDecoration(
                    color: Colors.grey[200],
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black.withOpacity(0.45),
                        spreadRadius: 4,
                        blurRadius: 2,
                      ),
                    ],
                    borderRadius: BorderRadius.circular(5),
                    // border: Border.all(width: 1),
                  ),
                  child: const Text(
                    "Uygulamayı kullanabilmek için lütfen internet bağlantınızı kontrol edip uygulamayı yeniden çalıştırın.",
                    style: TextStyle(fontSize: 25),
                  ),
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Platform.isAndroid
                      ? RawMaterialButton(
                          onPressed: () {
                            SystemNavigator.pop();
                          },
                          child: const Text(
                            "Çıkış",
                            style: TextStyle(color: Colors.white),
                          ),
                          fillColor: Colors.amber[800],
                        )
                      : const SizedBox(),                
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

-------------------------
version_check_failed.dart:
--------------------------

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart';

class VersionCheckFailed extends StatelessWidget {
  const VersionCheckFailed({Key key}) : super(key: key);

  void _launchURL(String _url) async {
    if (!await launch(_url)) throw 'Could not launch $_url';
  }

  @override
  Widget build(BuildContext context) {
    double width = MediaQuery.of(context).size.width;
    return Scaffold(
      body: Container(        
        color: Colors.grey[700],
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Padding(
                padding: EdgeInsets.all(width * .075),
                child: Container(
                  padding: EdgeInsets.all(width * .075),
                  decoration: BoxDecoration(
                    color: Colors.grey[200],
                    boxShadow: [
                      BoxShadow(
                        color: Colors.black.withOpacity(0.45),
                        spreadRadius: 4,
                        blurRadius: 2,
                      ),
                    ],
                    borderRadius: BorderRadius.circular(5),
                    // border: Border.all(width: 1),
                  ),
                  child: const Text(
                    "Uygulamayı kullanabilmek için lütfen en son sürüme güncelleyin.",
                    style: TextStyle(fontSize: 25),
                  ),
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Platform.isAndroid
                      ? RawMaterialButton(
                          onPressed: () {
                            SystemNavigator.pop();
                          },
                          child: const Text(
                            "Çıkış",
                            style: TextStyle(color: Colors.white),
                          ),
                          fillColor: Colors.amber[800],
                        )
                      : const SizedBox(),
                  Padding(
                    padding: EdgeInsets.only(
                        left: Platform.isAndroid ? width * .035 : 0),
                    child: RawMaterialButton(
                      onPressed: () {
                        if (Platform.isAndroid) {
                          _launchURL(
                              "https://play.google.com/store/apps/details?id=com.pars.taksim");
                        }
                        if (Platform.isIOS) {
                          _launchURL(
                              "https://apps.apple.com/us/app/pars-taksim/id1596088641");
                        }
                      },
                      child: const Text(
                        "Güncelle",
                        style: TextStyle(color: Colors.white),
                      ),
                      fillColor: Colors.green[900],
                    ),
                  ),
                ],
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Editor is loading...