Created
April 2, 2021 18:14
-
-
Save chunhtai/b666b3192e2356d315f9cb434d780811 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testWidgets('BackButtonListener takes priority over root back dispatcher', (WidgetTester tester) async { | |
final SimpleRouteInformationProvider provider = SimpleRouteInformationProvider(); | |
provider.value = const RouteInformation( | |
location: 'initial', | |
); | |
final BackButtonDispatcher outerDispatcher = RootBackButtonDispatcher(); | |
await tester.pumpWidget(buildBoilerPlate( | |
Router<RouteInformation>( | |
backButtonDispatcher: outerDispatcher, | |
routeInformationProvider: provider, | |
routeInformationParser: SimpleRouteInformationParser(), | |
routerDelegate: SimpleRouterDelegate( | |
builder: (BuildContext context, RouteInformation? information) { | |
// Creates the sub-router. | |
return Column( | |
children: <Widget>[ | |
Text(information!.location!), | |
BackButtonListener( | |
child: Container(), | |
onBackPressed: () { | |
provider.value = const RouteInformation( | |
location: 'popped inner1', | |
); | |
return SynchronousFuture<bool>(true); | |
}, | |
), | |
], | |
); | |
}, | |
onPopRoute: () { | |
provider.value = const RouteInformation( | |
location: 'popped outter', | |
); | |
return SynchronousFuture<bool>(true); | |
} | |
), | |
) | |
)); | |
await tester.pumpWidget(buildBoilerPlate( | |
Router<RouteInformation>( | |
backButtonDispatcher: outerDispatcher, | |
routeInformationProvider: provider, | |
routeInformationParser: SimpleRouteInformationParser(), | |
routerDelegate: SimpleRouterDelegate( | |
builder: (BuildContext context, RouteInformation? information) { | |
// Creates the sub-router. | |
return Column( | |
children: <Widget>[ | |
Text(information!.location!), | |
BackButtonListener( | |
child: Container(), | |
onBackPressed: () { | |
provider.value = const RouteInformation( | |
location: 'a different call back', | |
); | |
return SynchronousFuture<bool>(true); | |
}, | |
), | |
], | |
); | |
}, | |
onPopRoute: () { | |
provider.value = const RouteInformation( | |
location: 'popped outter', | |
); | |
return SynchronousFuture<bool>(true); | |
} | |
), | |
) | |
)); | |
// This should trigger didUpdateWidget | |
await tester.pump(); | |
await tester.pumpWidget(buildBoilerPlate( | |
Router<RouteInformation>( | |
backButtonDispatcher: outerDispatcher, | |
routeInformationProvider: provider, | |
routeInformationParser: SimpleRouteInformationParser(), | |
routerDelegate: SimpleRouterDelegate( | |
builder: (BuildContext context, RouteInformation? information) { | |
// Creates the sub-router. | |
return Column( | |
children: <Widget>[ | |
Text(information!.location!), | |
Text('a different widget'), | |
], | |
); | |
}, | |
onPopRoute: () { | |
provider.value = const RouteInformation( | |
location: 'popped outter', | |
); | |
return SynchronousFuture<bool>(true); | |
} | |
), | |
) | |
)); | |
// This should trigger dispose | |
await tester.pump(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment