Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrap library whole application #33

Open
pishguy opened this issue Sep 27, 2020 · 7 comments
Open

wrap library whole application #33

pishguy opened this issue Sep 27, 2020 · 7 comments

Comments

@pishguy
Copy link

pishguy commented Sep 27, 2020

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

@sajphon
Copy link

sajphon commented Feb 5, 2021

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);
      },
    );
  }

@routmartin
Copy link

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?

@pishguy
Copy link
Author

pishguy commented Mar 5, 2021

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

@routmartin
Copy link

ok thank you

@Mustafa74Dev
Copy link

@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
Copy link

@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

@Janos-Dobszai-EF
Copy link

Janos-Dobszai-EF commented Nov 10, 2023

@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 ⬆️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants