ConnectivityWidget class
Connectivity Widget
Widget that is aware of the network status from the network.
Has a a builder parameter so that the child widget can be built in accordance to the online/offline status.
A onlineCallback and offlineCallback are provided so that methods can be called when the device is turned online or offline, respectively
offlineBanner is the banner to be shown at the bottom of the child widget created in the builder. Its visibility can be switched off with the offlineBanner parameter
Example:
ConnectivityWidget(
onlineCallback: _incrementCounter,
builder: (context, isOnline) => Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("${isOnline ? 'Online' : 'Offline'}", style: TextStyle(fontSize: 30, color: isOnline ? Colors.green : Colors.red),),
SizedBox(height: 20,),
Text(
'Number of times we connected to the internet:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.display1,
),
],
),
),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- ConnectivityWidget
Constructors
- ConnectivityWidget({required ConnectivityBuilder builder, VoidCallback? onlineCallback, VoidCallback? offlineCallback, bool showOfflineBanner = true, bool disableAnimations = false, Widget? offlineBanner, Widget? initialLoadingWidget, Key? key})
Properties
- builder → ConnectivityBuilder
-
Builder method for the child widget.
final
- disableAnimations → bool
-
Disables animations
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialLoadingWidget → Widget?
-
Loader widget to show while the first connection check is in progress
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- offlineBanner → Widget?
-
OfflineBanner to be shown at the bottom of the widget
final
- offlineCallback → VoidCallback?
-
Callback for when the device is offline
final
- onlineCallback → VoidCallback?
-
Callback for when the device is online
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- showOfflineBanner → bool
-
Flag to show or hide the offlineBanner
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< StatefulWidget> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of
DiagnosticsNode
objects describing this node's children.inherited -
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited