import 'package:check_my_connection/notification_api.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:internet_connection_checker/internet_connection_checker.dart'; import 'package:overlay_support/overlay_support.dart'; import 'package:connectivity_plus/connectivity_plus.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin(); Future main() async { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { return OverlaySupport.global( child: MaterialApp( title: 'Flutter Demo', theme: ThemeData( primarySwatch: Colors.orange, ), home: const MyHomePage(title: 'Check Connectivity'), ), ); } } class MyHomePage extends StatefulWidget { const MyHomePage({Key? key, required this.title}) : super(key: key); final String title; @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { bool hasInternet = false; ConnectivityResult result = ConnectivityResult.none; @override void initState() { super.initState(); Connectivity().onConnectivityChanged.listen((result) { setState(() { this.result = result; }); }); InternetConnectionChecker().onStatusChange.listen((status) { final hasInternet = status == InternetConnectionStatus.connected; setState(() { this.hasInternet = hasInternet; debugPrint("int yok"); if (!hasInternet) { NotificationApi.showNotification( id: 0, title: "Int gitti!!!", body: "Kalk aƧ", payload: 'bla'); } }); }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( centerTitle: true, title: Text(widget.title), systemOverlayStyle: SystemUiOverlayStyle.dark, ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ Container( padding: EdgeInsets.only(bottom: 100), child: const Material( child: Text('Connection Status', style: TextStyle( backgroundColor: Colors.amber, fontSize: 35, fontWeight: FontWeight.bold)), )), Container( padding: EdgeInsets.only(bottom: 30.0), child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Icon((result == ConnectivityResult.wifi) ? Icons.wifi : (result == ConnectivityResult.mobile) ? Icons.phone_android : Icons.block), Text( (result == ConnectivityResult.wifi) ? ' Wifi Network Available' : (result == ConnectivityResult.mobile) ? ' Mobile Network Available' : ' No Network Available', style: const TextStyle( fontSize: 22, fontWeight: FontWeight.bold)), ], ), ), ], ), ), ); } }