123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- import 'dart:async';
- import 'dart:developer' as developer;
-
- import 'package:connectivity_plus/connectivity_plus.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:google_fonts/google_fonts.dart';
- import 'package:lottie/lottie.dart';
-
- class MyHomePage extends StatefulWidget {
- @override
- State<MyHomePage> createState() => _MyHomePageState();
- }
-
- class _MyHomePageState extends State<MyHomePage> {
- ConnectivityResult _connectionStatus = ConnectivityResult.none;
- final Connectivity _connectivity = Connectivity();
- late StreamSubscription<ConnectivityResult> _connectivitySubscription;
-
- @override
- void initState() {
- super.initState();
- initConnectivity();
-
- _connectivitySubscription = _connectivity.onConnectivityChanged.listen(_updateConnectionStatus);
- }
-
- @override
- void dispose() {
- _connectivitySubscription.cancel();
- super.dispose();
- }
-
- // Platform messages are asynchronous, so we initialize in an async method.
- Future<void> initConnectivity() async {
- late ConnectivityResult result;
- // Platform messages may fail, so we use a try/catch PlatformException.
- try {
- result = await _connectivity.checkConnectivity();
- } on PlatformException catch (e) {
- developer.log('Couldn\'t check connectivity status', error: e);
- return;
- }
-
- // 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 Future.value(null);
- }
-
- return _updateConnectionStatus(result);
- }
-
- Future<void> _updateConnectionStatus(ConnectivityResult result) async {
- setState(() {
- _connectionStatus = result;
- });
- }
-
- @override
- Widget build(BuildContext context) {
- return Container(
- child: Column(
- children: [
- SizedBox(
- width: 250,
- height: 250,
- child: LottieBuilder.asset(
- 'assets/animation/animation_no_internet.json',
- repeat: true),
- ),
- Text(
- "No Internet Connection",
- style: GoogleFonts.josefinSans(fontSize: 18),
- ),
- Padding(
- padding: EdgeInsets.all(15),
- child: Text(
- 'You Are Not Connected to The Internet. Please check your Wifi or Mobile Data!',
- style: GoogleFonts.zillaSlab(fontSize: 16),
- ),
- ),
- ElevatedButton(
- onPressed: (){
-
- },
- child: Text("Retry",
- textAlign: TextAlign.center,
- style: TextStyle(
- color: Colors.white,
- fontSize: 17,
- fontWeight: FontWeight.w500)
- )
- )
- ],
- ),
- );
- }
- }
|