flutter_offline icon indicating copy to clipboard operation
flutter_offline copied to clipboard

wrap library whole application

Open pishguy opened this issue 3 years ago • 7 comments

is any solution to wrap the library inside whole application like MaterialApp instead of define inside each screen and avoid extending that?

pishguy avatar Sep 27 '20 05:09 pishguy

Yup. You use MaterialApp builder.

@override
  Widget build(BuildContext context) {
    return new MaterialApp(
      builder: (context, widget) {
        return OfflineBuilder(
            connectivityBuilder: (
              BuildContext context,
              ConnectivityResult connectivity,
              Widget child,
            ) {
              final bool connected = connectivity != ConnectivityResult.none;

              if (!connected) {
                return OfflineScreen();
              }

              return child;
            },
            child: widget);
      },
    );
  }

sajphon avatar Feb 05 '21 13:02 sajphon

How could we do if we want to go deep into the app and then when the interned is disconnected then it return the no internet screen but after the internet is back we want it to stay in the same screen as the time the internet lose?

routmartin avatar Mar 05 '21 02:03 routmartin

How could we do if we want to go deep into the app and then when the interned is disconnected then it return the no internet screen but after the internet is back we want it to stay in the same screen as the time the internet lose?

I think for this implementation you should do it for every screen. it means you should wrap your Scaffold with this library. you can test sample code which that's in library readme

pishguy avatar Mar 05 '21 07:03 pishguy

ok thank you

routmartin avatar Mar 10 '21 07:03 routmartin

@sajphon Thanks dude the solution is working very well. But there is one issue is internet connect get connect it's start from splash screen How can we Solve this issue.??? @jogboms

Mustafa74Dev avatar Jul 05 '22 10:07 Mustafa74Dev

@sajphon Thanks dude the solution is working very well. But there is one issue is internet connect get connect it's start from splash screen How can we Solve this issue.??? @jogboms

MustafaDev-shaikh avatar Jul 05 '22 10:07 MustafaDev-shaikh

@MustafaDev-shaikh @Mustafa74Dev use a Stack and show your OfflineScreen on top of your main app, this way the main app stays in the tree and doesn't lose state.

Stack(
  children: [
    MyMainApp(),
    if (!connected) {
      return OfflineScreen();
    },
  ],
)

Didn't test this code but this is the general idea ⬆️

Janos-Dobszai-EF avatar Nov 10 '23 09:11 Janos-Dobszai-EF