flutter off/online connectivity
a tidy flutter utility to handle offline/online connectivity like a boss. it provides support for both ios and android platforms (of course).
installing
dependencies:
flutter_offline: "^0.2.2"
import
import 'package:flutter_offline/flutter_offline.dart';
how to use
import 'package:flutter/material.dart';
import 'package:flutter_offline/flutter_offline.dart';
class demopage extends statelesswidget {
@override
widget build(buildcontext context) {
return new scaffold(
appbar: new appbar(
title: new text("offline demo"),
),
body: offlinebuilder(
connectivitybuilder: (
buildcontext context,
conectivityresult cnct,
widget child,
) {
final bool connected = cnct != conectivityresult.none;
return new stack(
fit: stackfit.expand,
children: [
positioned(
height: 24.0,
left: 0.0,
right: 0.0,
child: container(
color: connected ? color(0xff00ee44) : color(0xffee4400),
child: center(
child: text("${connected ? 'online' : 'offline'}"),
),
),
),
center(
child: new text(
'yay!',
),
),
],
);
},
child: column(
mainaxisalignment: mainaxisalignment.center,
children: <widget>[
new text(
'there are no bottons to push :)',
),
new text(
'just turn off your internet.',
),
],
),
),
);
}
}
for more info, please, refer to the main.dart
in the example.
Comments are closed.