features
coneectivity service is for checking the internet connection using provider.
installation
- add the latest version of package to your pubspec.yaml (and run
dart pub get
):
dependencies:
connectivity_service: ^0.0.3
- import the package and use it in your flutter app.
import 'package:connectivity_service/connectivity_service.dart';
example
- add the provider in mateerial app
import 'package:flutter/material.dart';
void main() {
runapp(const myapp());
}
class myapp extends statelesswidget {
const myapp({key? key}) : super(key: key);
// this widget is the root of your application.
@override
widget build(buildcontext context) {
return multiprovider(
providers: [
streamprovider<connectivitysatus>(
create: (context) =>
coneectivityservice().connectionstatuscontroller.stream,
initialdata: connectivitysatus.offline)
],
child: materialapp(
title: 'flutter application',
theme: themedata(
primaryswatch: colors.blue,
),
home: const homepage(),
),
);
}
}
- then add ‘networksensitive’ where you need.
import 'package:connectivity_service/enum/network_sensitivity.dart';
import 'package:flutter/material.dart';
class homepage extends statefulwidget {
const homepage({key? key}) : super(key: key);
@override
state<homepage> createstate() => _homepagestate();
}
class _homepagestate extends state<homepage> {
@override
widget build(buildcontext context) {
return scaffold(
body: safearea(
child: networksensitive(
child:text('your design here'),
),
),
);
}
}
- in ‘networksensitive’ page you can create your own design on the offline section. for now it is a simple text ‘no internet!’ but you can design here anything.
Comments are closed.