internet_permission 2.0.2
internet_permission: ^2.0.2 copied to clipboard
A Flutter plugin that automatically adds internet permissions to all platforms (Android, iOS, macOS, Windows, Linux, Web). One command setup: dart run internet_permission:setup
import 'package:flutter/material.dart';
import 'package:internet_permission/internet_permission.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Internet Connection Checker Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
int _selectedIndex = 0;
final List<Widget> _pages = [
const HomePage(),
const SettingsPage(),
const ProfilePage(),
];
@override
Widget build(BuildContext context) {
return InternetCheckedScaffold(
appBar: AppBar(
title: const Text('Internet Checker Demo'),
centerTitle: true,
elevation: 2,
),
body: _pages[_selectedIndex],
bottomNavigationBar: BottomNavigationBar(
currentIndex: _selectedIndex,
onTap: (index) {
setState(() {
_selectedIndex = index;
});
},
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home),
label: 'Home',
),
BottomNavigationBarItem(
icon: Icon(Icons.settings),
label: 'Settings',
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
label: 'Profile',
),
],
),
// Custom internet checker settings
dialogTitle: 'No Internet Connection',
dialogMessage: 'Please check your internet connection and try again.',
retryButtonText: 'Retry',
checkInterval: const Duration(seconds: 3),
);
}
}
class HomePage extends StatelessWidget {
const HomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
padding: const EdgeInsets.all(30),
decoration: BoxDecoration(
color: Colors.green.shade50,
shape: BoxShape.circle,
),
child: Icon(
Icons.wifi,
size: 100,
color: Colors.green.shade600,
),
),
const SizedBox(height: 30),
Text(
'Internet is Connected!',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
color: Colors.green.shade700,
),
),
const SizedBox(height: 15),
Text(
'Your connection is being monitored automatically',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 16,
color: Colors.grey.shade600,
),
),
const SizedBox(height: 40),
Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.blue.shade50,
borderRadius: BorderRadius.circular(15),
border: Border.all(color: Colors.blue.shade200),
),
child: Column(
children: [
Icon(
Icons.info_outline,
color: Colors.blue.shade700,
size: 40,
),
const SizedBox(height: 15),
Text(
'Try This!',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.blue.shade900,
),
),
const SizedBox(height: 10),
Text(
'Turn off your WiFi or mobile data to see the automatic dialog appear!',
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 14,
color: Colors.grey.shade700,
),
),
],
),
),
],
),
),
);
}
}
class SettingsPage extends StatelessWidget {
const SettingsPage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ListView(
padding: const EdgeInsets.all(16),
children: [
const SizedBox(height: 20),
Text(
'Settings',
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 20),
_buildSettingsTile(
icon: Icons.notifications,
title: 'Notifications',
subtitle: 'Manage notification settings',
onTap: () {},
),
_buildSettingsTile(
icon: Icons.language,
title: 'Language',
subtitle: 'Change app language',
onTap: () {},
),
_buildSettingsTile(
icon: Icons.dark_mode,
title: 'Dark Mode',
subtitle: 'Toggle dark theme',
onTap: () {},
),
_buildSettingsTile(
icon: Icons.security,
title: 'Privacy',
subtitle: 'Privacy settings',
onTap: () {},
),
],
);
}
Widget _buildSettingsTile({
required IconData icon,
required String title,
required String subtitle,
required VoidCallback onTap,
}) {
return Card(
margin: const EdgeInsets.only(bottom: 12),
child: ListTile(
leading: Icon(icon),
title: Text(title),
subtitle: Text(subtitle),
trailing: const Icon(Icons.arrow_forward_ios, size: 16),
onTap: onTap,
),
);
}
}
class ProfilePage extends StatelessWidget {
const ProfilePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircleAvatar(
radius: 60,
backgroundColor: Colors.blue.shade100,
child: Icon(
Icons.person,
size: 80,
color: Colors.blue.shade700,
),
),
const SizedBox(height: 20),
Text(
'John Doe',
style: Theme.of(context).textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Text(
'john.doe@example.com',
style: TextStyle(
fontSize: 16,
color: Colors.grey.shade600,
),
),
const SizedBox(height: 30),
ElevatedButton.icon(
onPressed: () {},
icon: const Icon(Icons.edit),
label: const Text('Edit Profile'),
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 15),
),
),
],
),
);
}
}