s_network_connection_checker

Creator: coderz1093

Last updated:

0 purchases

s_network_connection_checker Image
s_network_connection_checker Images

Languages

Categories

Add to Cart

Description:

s network connection checker

SNetwork Connection Checker #
Screenshots #




























Configs #
[failedPingCount] -> a failed ping up to this parameter is considered a lost connection
[reTryDuration] -> throws a ping during this duration
[pingTimeout] -> If there is no response to the ping in this time, it is considered unsuccessful
[urls] -> links to ping, As default, the first element of the list is taken
SNetworkConnectionChecker.instance.selectedIp.setState(SIpModel("Google 1", "8.8.8.8", 53));

SNetworkConnectionChecker.instance.setConfig(
failedPingCount: 2,
pingTimeout: const Duration(seconds: 2),
reTryDuration: const Duration(seconds: 3),
urls: [
SIpModel("Google 1", "8.8.8.8", 53),
SIpModel("Google 2", "8.8.4.4", 53),
],
);
copied to clipboard
Usage #
Check if you have internet connection #
var hasConnection = await SNetworkConnectionChecker.instance.hasConnection();

print("Has connection $hasConnection");
runApp(const FullScreenWarningWithOpacity());

copied to clipboard
Listen to the status of your internet connection #

void main() async {
// IMPORTANT
// You can call anywhere you want
SNetworkConnectionChecker.instance.startListen();
runApp(const FullScreenWarningWithOpacity());
}
// ..........

SNetworkConnectionChecker.instance.isConnected.listen(
(value) {
// true connected, false not connected, null loading
print("Connection status changed $value");
},
);

/// .........

copied to clipboard
Use in UI #

Basic usage

MaterialApp(
title: 'SNetwork connection checker example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
builder: (context, child) {
return Scaffold(
body: SNetworkConnectionCheckerWidget(
loadingBuilder: () {
return const Center(child: Text("Loading"));
},
disConnectedBuilder: () {
return const Center(child: Text("Custom disconnected page"));
},
child: child!,
),
);
},
home: const Scaffold(
body: Center(
child: Text("Connected"),
),
),
);
}

copied to clipboard

other usage


MaterialApp(
title: 'SNetwork connection checker example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
builder: (context, child) {
return Scaffold(
body: SNetworkConnectionChecker.instance.isConnected.builder((loading, isConnected, error, context) {
if (isConnected == null) {
return const Center(
child: Text("Loading"),
);
}
return Stack(
children: [
AnimatedOpacity(
opacity: isConnected ? 1 : 0.1,
duration: const Duration(milliseconds: 100),
child: IgnorePointer(
ignoring: isConnected == false,
child: child,
),
),
if (!isConnected)
const Align(
alignment: Alignment.center,
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("No connection"),
Text("Please check your network connection"),
],
)),
)
],
);
}),
);
},
home: const Scaffold(
body: Center(
child: Text("Home page"),
),
),
);
}


copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.