Sorry for weak English. I am doing Integration test for my Advicer app. When the Switch button taped then the theme will change from light to dark mode, but the button taped during integration test and it is not changing the theme.
Here is code for my Switch button in UI:
Switch(
value: Provider.of<ThemeService>(context).isDarkModeON,
onChanged: (_) {
Provider.of<ThemeService>(context, listen: false).toggleTheme();
},
),
And this is code for my Integration test:
group('ThemeChanging', () {
final GlobalKey appBarKey = GlobalKey();
testWidgets('tap on switch button and theme will change',
(widgetTester) async {
await widgetTester.pumpWidget(MultiProvider(
providers: [
ChangeNotifierProvider(
create: (context) => ThemeService(),
),
],
child: MaterialApp(
home: Scaffold(
appBar: AppBar(
key: appBarKey,
title: const Text('Advicer'),
actions: [
Consumer<ThemeService>(
builder: (context, themeService, child) {
return Switch(
value: Provider.of<ThemeService>(context).isDarkModeON,
onChanged: (value) =>
Provider.of<ThemeService>(context, listen: false)
.toggleTheme(),
);
},
),
],
),
),
),
));
final switchFinder = find.byType(Switch);
final initialTheme = appBarKey.currentContext;
await widgetTester.tap(switchFinder);
await widgetTester.pumpAndSettle();
expect(switchFinder, findsOneWidget);
final changedTheme = appBarKey.currentContext;
expect(changedTheme != initialTheme, false);
});
});