jogboms / flutter_offline Goto Github PK
View Code? Open in Web Editor NEW✈️ A tidy utility to handle offline/online connectivity like a Boss
License: MIT License
✈️ A tidy utility to handle offline/online connectivity like a Boss
License: MIT License
how can i set delay to show internet connection is connected or disconnected? i dont like to have this slidebar on top of screen to show your are connected or diconnected
I need to know the connectivity within the child as well. How could I pass the connectivity state?
I have the following code, which runs perfectly on Android. But on iOS it does not seem to react to the online/offline as on Android.
I have redacted the URL's in the code:
class HomePage extends StatefulWidget {
_State createState() => _State();
}
class _State extends State<HomePage> {
FlutterWebviewPlugin fwp;
final String initialUrl = 'https://example.com/link/';
@override
void initState() {
super.initState();
fwp = FlutterWebviewPlugin();
fwp.onStateChanged.listen(onStateChange);
}
@override
void dispose() {
fwp.dispose();
super.dispose();
}
void onStateChange(WebViewStateChanged state) {
List<String> doNotSave = <String>[
initialUrl,
];
var uri = Uri.parse(state.url);
if (state.type == WebViewState.finishLoad && !doNotSave.contains(state.url) && (uri.queryParameters["link"] == "true")) {
storage.setString('url', state.url);
print("Saved!");
}
}
Widget build(BuildContext context) {
// Uncomment to reset URL
// storage.setString('url', '');
String savedUrl = storage.getString('url') ?? '';
String urlToLoad = savedUrl != '' ? savedUrl : initialUrl;
return new Scaffold(
body: OfflineBuilder(
connectivityBuilder: (
BuildContext context,
ConnectivityResult connectivity,
Widget child,
) {
final bool connected = connectivity != ConnectivityResult.none;
if (connected == true) { // Show link-page or URL from database
fwp.reloadUrl(urlToLoad);
}
else { // Offline 404
fwp.reloadUrl(Uri.dataFromString('<html><body>404</body></html>', mimeType: 'text/html').toString());
}
// Loading dots
return WebviewScaffold(
url: Uri.dataFromString('<html><body>Loading...</body></html>', mimeType: 'text/html').toString(),
withJavascript: true,
useWideViewPort: false,
withZoom: false,
scrollBar: false
);
},
child: Column(
),
),
);
}
}
As you probably can see the app is launched with the Loading...
being shown, and if it is online it should show the urlToLoad
and if it is online it shows a page with 404
. And it should react if the connection status changes at any time.
Why isn't this working on iOS?
It only shows me the Loading...
part, but nothing else.
Execution failed for task ':connectivity:compileDebugJavaWithJavac'.
[ +3 ms] Swift Compiler Error (Xcode): Cannot find type 'Reachability' in scope
/Users/tebalink/development/flutter/.pub-cache/hosted/pub.dartlang.org/connectivity_plus-2.3.6/ios/Classes/ReachabilityConnectivityProvider.swift:3:29
Hi,
I used the flutter_offline package. I included this permission in AndroidManifest.Xml, located the main folder. In debug mode, flutter_offline is working fine. Whenever I build, it does not work for me. Do I miss something else?
Thanks
Sathiya R
fluttercommunity/plus_plugins#2169
Fix is to upgrade the dependency to 5.x
Great Package you made, and it made easy for determining if the user has connected.
I have this kind of issue when I want to have a Duration for that Connectivity. I want to hide that widget once the connection is either online or offline in a matter of duration.
Hello, do you have a working example of a widget test for this? Because to me it looks like everything in the child
of OfflineBuilder
doesn't get picked up by widget tests and isn't found with finders. :(
if I just add folowing code with child:Container() empty it works fine? so why there is a need for child
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(
'MY page content here!',
),
),
],
);
},
child:Container()
widget should at least be inside the builder.
there is no way to get the connectivityresult if you place the main widget in the child property and it needs to check connectivity
Whenever I'm upgrading my dependencies and reviewing upgraded packages' CHANGELOG.md tabs on Pub, I'm missing any explanation of what changed in new releases of flutter_offline.
It would be great to keep a proper change log to let users know whether an upgrade is likely to break their app or not.
If the notion has been to not maintain the change log until a 1.0 release, well, this package de facto already has a lot of users and perhaps it ought to be a version 1.0, semantically versioned and with a change log. Just a thought.
flutter_offline currently depends on network_info_plus: ^2.1.2
, which is a really old version. Version 3 and even version 4 were released since then.
Please depend on network_info_plus: ^4.0.0
.
The interface does not refresh when the network is disconnected to connect.
Hello everyone, I have a problem with the library. I created an abstract class to handle connectivity across multiple pages in the same way. But I'm getting the error:
`════════ Exception caught by widgets library ═══════════════════════════════════
The following ProviderNotFoundException was thrown building StreamBuilder(state: _StreamBuilderBaseState<ConnectivityResult, AsyncSnapshot>#ab4f1):
Error: Could not find the correct Provider<StateStreamable<Object?>> above this BlocBuilder<StateStreamable<Object?>, Object?> Widget
This happens because you used a BuildContext
that does not include the provider
of your choice. There are a few common scenarios:
You added a new provider in your main.dart
and performed a hot-reload.
To fix, perform a hot-restart.
The provider you are trying to read is in a different route.
Providers are "scoped". So if you insert of provider inside a route, then
other routes will not be able to access that provider.
You used a BuildContext
that is an ancestor of the provider you are trying to read.
Make sure that BlocBuilder<StateStreamable<Object?>, Object?> is under your MultiProvider/Provider<StateStreamable<Object?>>.
This usually happens when you are creating a provider and trying to read it immediately.
For example, instead of:
Widget build(BuildContext context) {
return Provider<Example>(
create: (_) => Example(),
// Will throw a ProviderNotFoundError, because `context` is associated
// to the widget that is the parent of `Provider<Example>`
child: Text(context.watch<Example>().toString()),
);
}
consider using builder
like so:
Widget build(BuildContext context) {
return Provider<Example>(
create: (_) => Example(),
// we use `builder` to obtain a new `BuildContext` that has access to the provider
builder: (context, child) {
// No longer throws
return Text(context.watch<Example>().toString());
}
);
}
If none of these solutions work, consider asking for help on StackOverflow:
https://stackoverflow.com/questions/tagged/flutter
The relevant error-causing widget was:
OfflineBuilder OfflineBuilder:file:///C:/..../glufri/lib/widgets/connectivity_widget.dart:9:41
When the exception was thrown, this was the stack:
#0 Provider._inheritedElementOf (package:provider/src/provider.dart:343:7)
#1 Provider.of (package:provider/src/provider.dart:293:30)
#2 ReadContext.read (package:provider/src/provider.dart:649:21)
#3 _BlocBuilderBaseState.initState (package:flutter_bloc/src/bloc_builder.dart:130:36)
#4 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:5611:55)
#5 ComponentElement.mount (package:flutter/src/widgets/framework.dart:5456:5)
#6 Element.inflateWidget (package:flutter/src/widgets/framework.dart:4335:16)
#7 Element.updateChild (package:flutter/src/widgets/framework.dart:3840:20)
#8 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#9 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#10 Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#11 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2904:19)
#12 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:989:21)
#13 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:448:5)
#14 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1386:15)
#15 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1311:9)
#16 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1169:5)
#17 _invoke (dart:ui/hooks.dart:312:13)
#18 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:399:5)
#19 _drawFrame (dart:ui/hooks.dart:283:31)
`
Compiler message:
flutter/.pub-cache/hosted/pub.dartlang.org/flutter_offline-0.2.1/lib/src/utils.dart:13:30: Error: A constructor invocation can't have type arguments on the constructor name.
Try to place the type arguments on the class name.
return StreamTransformer.fromHandlers<ConnectivityResult,
^^^^^^^^^^^^
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel dev, v0.11.3, on Mac OS X 10.13.6 17G65, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK 28.0.2)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.0)
[✓] Android Studio (version 3.2)
[!] VS Code (version 1.28.2)
[✓] Connected device (1 available)
connectivity: ^0.3.1 blocking to migrate on AndroidX, Need to update connectivity dependencies to latest connectivity: ^0.4.2
Hi,
This plugin is very cool but clearly it's a problem to wrap every single screen in an OfflineBuilder()...
That's a lot of duplicated / boilerplate code for each one.
Does someone managed to "extract" the code of the OfflineBuilder() to put it in the main.dart for example ?
Thanks in advance
PlatformException(error, NetworkCallback was not registered, null, null)
Network call back error is showing when I am using the flutter offline package. plz, guide how should I solve it.
This happens on launch.
After I've implement your package, the IOS application works perfectly but on the android it always throwing Missing plugin Exception
Device log
I/flutter ( 5730): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter ( 5730): The following OfflineBuilderError was thrown building StreamBuilder<ConnectivityResult>(dirty,
I/flutter ( 5730): state: _StreamBuilderBaseState<ConnectivityResult, AsyncSnapshot<ConnectivityResult>>#e2477):
I/flutter ( 5730): MissingPluginException(No implementation found for method check on channel
I/flutter ( 5730): plugins.flutter.io/connectivity)
I/flutter ( 5730):
I/flutter ( 5730): The relevant error-causing widget was:
I/flutter ( 5730): StreamBuilder<ConnectivityResult>
I/flutter ( 5730): file:///Users/wichayut/Development/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_offline-0.3.0/lib/src/main.dart:81:12
I/flutter ( 5730):
I/flutter ( 5730): When the exception was thrown, this was the stack:
I/flutter ( 5730): #0 OfflineBuilderState.build.<anonymous closure> (package:flutter_offline/src/main.dart:92:11)
I/flutter ( 5730): #1 StreamBuilder.build (package:flutter/src/widgets/async.dart:509:81)
I/flutter ( 5730): #2 _StreamBuilderBaseState.build (package:flutter/src/widgets/async.dart:127:48)
I/flutter ( 5730): #3 StatefulElement.build (package:flutter/src/widgets/framework.dart:4619:28)
I/flutter ( 5730): #4 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4502:15)
I/flutter ( 5730): #5 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4675:11)
I/flutter ( 5730): #6 Element.rebuild (package:flutter/src/widgets/framework.dart:4218:5)
I/flutter ( 5730): #7 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2627:33)
I/flutter ( 5730): #8 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:864:20)
I/flutter ( 5730): #9 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:284:5)
I/flutter ( 5730): #10 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1113:15)
I/flutter ( 5730): #11 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1052:9)
I/flutter ( 5730): #12 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:968:5)
I/flutter ( 5730): #16 _invoke (dart:ui/hooks.dart:261:10)
I/flutter ( 5730): #17 _drawFrame (dart:ui/hooks.dart:219:3)
I/flutter ( 5730): (elided 3 frames from dart:async)
I/flutter ( 5730):
I/flutter ( 5730): ════════════════════════════════════════════════════════════════════════════════════════════════════
Main.dart
home: OfflineBuilder(
connectivityBuilder: (
BuildContext context,
ConnectivityResult connectivity,
Widget child,
) {
final bool connected =
connectivity != ConnectivityResult.none;
return Scaffold(
body: connected
? Scaffold(
body: authProvider.isLogin
? MainScreen()
: FutureBuilder(
future: authProvider.autoLogin(),
builder: (context, snapshot) =>
snapshot.connectionState ==
ConnectionState.waiting
? LogoScreen()
: LoginScreen()))
: Center(child: new Text('No internet!')));
},
child: Center()),
Flutter doctor
Connected views:
wichayut@Wichayuts-MacBook-Pro relifnow_frontend_v2 % flutter doctor -v
[✓] Flutter (Channel master, v1.18.1-pre.9, on Mac OS X 10.15.4 19E266, locale en-TH)
• Flutter version 1.18.1-pre.9 at /Users/wichayut/Development/flutter
• Framework revision f9c58bea49 (10 hours ago), 2020-04-04 21:31:55 -0700
• Engine revision cb6fc30534
• Dart version 2.8.0 (build 2.8.0-dev.20.0 80ae6ed91d)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/wichayut/Library/Android/sdk
• Platform android-29, build-tools 29.0.3
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.4)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.4, Build version 11E146
• CocoaPods version 1.9.1
[✓] Android Studio (version 3.6)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 45.0.1
• Dart plugin version 192.7761
• Java version OpenJDK Runtime Environment (build 1.8.0_212-release-1586-b4-5784211)
[✓] VS Code (version 1.43.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.9.0
[✓] Connected device (2 available)
• sdk gphone x86 • emulator-5554 • android-x86 • Android 10 (API 29) (emulator)
• Dew’s iPhone • 7a530c8cd5eff84a0e6e0ca0051aa8033e641cfe • ios • iOS 13.4
• No issues found!
I am using the version is 'flutter_offline: ^0.2.1' I have published my app in play store . In my play store console it showing crash report.
java.lang.RuntimeException: at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0 (LoadedApk.java:1407) at android.app.-$$Lambda$LoadedApk$ReceiverDispatcher$Args$_BumDX2UKsnxLVrE6UJsJZkotuA.run (Unknown Source:2) at android.os.Handler.handleCallback (Handler.java:873) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loop (Looper.java:193) at android.app.ActivityThread.main (ActivityThread.java:6806) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:547) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:873) Caused by: java.lang.RuntimeException: at io.flutter.embedding.engine.FlutterJNI.ensureAttachedToNative (Unknown Source:9) at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage (Unknown Source) at io.flutter.embedding.engine.dart.DartMessenger.send (Unknown Source:33) at io.flutter.embedding.engine.dart.DartExecutor.send (Unknown Source:3) at io.flutter.view.FlutterNativeView.send (Unknown Source:2) at io.flutter.plugin.common.EventChannel$IncomingStreamRequestHandler$EventSinkImplementation.success (Unknown Source:49) at io.flutter.plugins.connectivity.ConnectivityPlugin$1.onReceive (Unknown Source:13) at android.app.LoadedApk$ReceiverDispatcher$Args.lambda$getRunnable$0 (LoadedApk.java:1397)
It is happening in android 9 version.
More than number of devices it crashing. Please solve the issue.
After adding the plugin to a new flutter application (Stable Channel, migrated to androidX) a deprecation warning is present when running a build (Android only).
The warning presented:
Note: /Users/dwulff/.pub-cache/hosted/pub.dartlang.org/connectivity-0.4.2/android/src/main/java/io/flutter/plugins/connectivity/ConnectivityPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
The iOS application never opens. When I tried to archive it I am getting the following error
Multiple commands produce '/Users/mdhasanrahman/Library/Developer/Xcode/DerivedData/Runner-fgzktmibyndpbgfkmsizqhgncvxe/Build/Intermediates.noindex/ArchiveIntermediates/Runner/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Reachability.framework':
Target 'Reachability' has create directory command with output '/Users/mdhasanrahman/Library/Developer/Xcode/DerivedData/Runner-fgzktmibyndpbgfkmsizqhgncvxe/Build/Intermediates.noindex/ArchiveIntermediates/Runner/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Reachability.framework'
Target 'ReachabilitySwift' has create directory command with output '/Users/mdhasanrahman/Library/Developer/Xcode/DerivedData/Runner-fgzktmibyndpbgfkmsizqhgncvxe/Build/Intermediates.noindex/ArchiveIntermediates/Runner/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/Reachability.framework'
I need flutter offline to check the status of the connection but I got the below mentioned error because of connectivity: ^0.4.5+3 dependencies.
The following PlatformException was thrown while de-activating platform stream on channel plugins.flutter.io/connectivity_status:
**PlatformException(error, NetworkCallback was not registered, null, null)**
When the exception was thrown, this was the stack:
#0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
#1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
<asynchronous suspension>
#2 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
#3 EventChannel.receiveBroadcastStream.<anonymous closure> (package:flutter/src/services/platform_channel.dart:552:29)
...
This is not an issue rather a suggestion or a question.
I am not able to find a way to retry checking if the device has connected to internet again.
Like having a button to trigger retry check?
I know this process done automatically but don't you think it is a good UX for the user to have retry button?
Hello.
I am found a package wifi_info_flutter in the project. A very useful library for this functionality. But it is not used anywhere.
Maybe was there something missing in the implementation?
Am using the flutter offline, package version - 0.3.0
this depends on connectivity package versioned - 0.4.6
When I try to build release apk , the following output is thrown resulting in build failure.
The built failed likely due to AndroidX incompatibilities in a plugin. The tool is about to try using Jetfier to solve the incompatibility.
Building plugin connectivity...
Running Gradle task 'assembleAarRelease'...
Running Gradle task 'assembleAarRelease'... Done 1.2s
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'connectivity'.
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 0s
The plugin connectivity could not be built due to the issue above.
Any help on how to fix this?
is any solution to wrap the library inside whole application like MaterialApp
instead of define inside each screen and avoid extending that?
is any feature to get wifi name and ip address when device connected?
Hi there,
Great package!
Are you planning to migrate this to null safety?
Cheers,
Derek
how come snapshot.connectionState is always waiting when turning wifi off to on ?
once the future connects to an api, it cant resolve the hostname, like it's still offline. thoughts?
this is how it looks like
OfflineBuilder(
connectivityBuilder: (context, connectivity, child) {
final bool connected = connectivity != ConnectivityResult.none;
print('connected='+connected.toString());
return connected ? child : 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: FutureBuilder<Root?>(
future: _fetch,
builder: (context, snapshot) {
print(snapshot.connectionState);
if (snapshot.hasData)
return _getScaffoldBody(snapshot.connectionState);
return Center(child: CircularProgressIndicator());
}
),
),
My Application have n number of pages, for now to show offline page I need to integrate this (OfflineBuilder) Widget on each page.
Is any way to show offline Widget on top of any page from single location? so, It will not subscribe/unsubscribe network stream on each page and easy to manage.
This package uses the plus
packages (which have support for all platforms) and the pub.dev page says that this package has support for all platforms. So is the sentence It provides support for both iOS and Android platforms (offcourse)
still up-to-date? It confuses a bit because you think this package has only support for iOS and Android.
Something better would be It provides support for all platforms (iOS, Android, Web, macOS, Linux und Windows)
.
Because sometimes, the network is working, but can't access our own service, I'm more concerned about the users being able to access our service properly!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.