FilledStacks / FilledStacks/responsive_builder

ScreenTypeLayout widgets don't rebuild on browser refresh

Open
#26 1 comment 0 reactions 0 assignees View on GitHub
question
Dominant language
Dart
Stars
524
Forks
90
PR merge metrics
No merged PRs in 30d

Description

The StartupView of my app checks whether the user is logged in and navigates to "Home" or "LoginView".

When using responsive_builder, the widgets are not rebuilt when the user refreshes the browser.

My code:

```
class StartUpView extends StatelessWidget {
const StartUpView({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
print('StartupView');
return ScreenTypeLayout(
breakpoints: ScreenBreakpoints(desktop: 1920, tablet: 900, watch: 375),
mobile: StartUpViewMobile(),
tablet: StartUpViewTablet(),
desktop: StartupViewDesktop()
);
}
}

class StartUpViewDesktop extends StatelessWidget {
const StartUpViewDesktop({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
print('StartupViewDesktop');
return ViewModelBuilder.reactive(
viewModelBuilder: () => StartUpViewModel(),
onModelReady: (model) => model.handleStartUpLogic(),
builder: (context, model, child) => Scaffold(
extendBodyBehindAppBar: true,
extendBody: true,
body: Center(
child: CircularProgressIndicator(
strokeWidth: 3,
valueColor: AlwaysStoppedAnimation(
Theme.of(context).accentColor,
),
),
),
),
);
}
}

class StartUpViewModel extends BaseModel {
final AuthenticationService _authenticationService =
locator();
final NavigationService _navigationService = locator();

Future handleStartUpLogic() async {
bool firstTime = true;
_authenticationService.authChanges.listen((user) async {
if (user != null) {
_navigationService.clearStackAndShow(Routes.homeView);
}
if (!firstTime && user == null) {
if (_authenticationService.platform == 'WEB') {
_navigationService.clearStackAndShow(Routes.loginView);
} else {
_navigationService.clearStackAndShow(Routes.welcomeView);
}
}
firstTime = false;
});
}
}
```

The console output on startup:
```
StartupView
StartupViewDesktop
```
When I refresh the browser, the StartupViewDesktop widget isn't rebuilt. The console output is:
```
StartupView
```
and it adds the page to the navigation stack which makes the widget
`Navigator.of(context).canPop() == true`

![Screenshot 2021-03-21 at 13 07 55](https://user-images.githubusercontent.com/34537296/111904445-5ea33f00-8a47-11eb-9800-6a075319b16c.jpg)

All works as expected when using
```
class StartUpView extends StatelessWidget {
const StartUpView({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
print('StartupView');
return StartupViewDesktop();
}
}
```
then, the StartupViewDesktop is rebuilt on refreshing the browser and
`Navigator.of(context).canPop() == false`

![Screenshot 2021-03-21 at 13 15 21](https://user-images.githubusercontent.com/34537296/111904482-84c8df00-8a47-11eb-8ec7-f473ce2f6195.jpg)

Looks like responsive_builder doesn't handle the widget state appropriately?

Thanks for your help!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.