Commit 30d7326b authored by Adam Barth's avatar Adam Barth Committed by GitHub

Tap on dropdown button in tests does not work (#6566)

The theme fallback mechanism was busted by the shadowThemeOnly change.

Fixes #6562
parent fc03057b
...@@ -101,8 +101,12 @@ class Theme extends InheritedWidget { ...@@ -101,8 +101,12 @@ class Theme extends InheritedWidget {
/// ``` /// ```
static ThemeData of(BuildContext context, { bool shadowThemeOnly: false }) { static ThemeData of(BuildContext context, { bool shadowThemeOnly: false }) {
final Theme theme = context.inheritFromWidgetOfExactType(Theme); final Theme theme = context.inheritFromWidgetOfExactType(Theme);
final ThemeData themeData = theme?.data ?? _kFallbackTheme; if (shadowThemeOnly) {
return shadowThemeOnly ? (theme.isMaterialAppTheme ? null : themeData) : themeData; if (theme == null || theme.isMaterialAppTheme)
return null;
return theme.data;
}
return (theme != null) ? theme.data : _kFallbackTheme;
} }
@override @override
......
...@@ -64,6 +64,72 @@ void main() { ...@@ -64,6 +64,72 @@ void main() {
expect(value, equals('two')); expect(value, equals('two'));
}); });
testWidgets('Drop down button with no app', (WidgetTester tester) async {
List<String> items = <String>['one', 'two', 'three', 'four'];
String value = items.first;
void didChangeValue(String newValue) {
value = newValue;
}
Widget build() {
return new Navigator(
initialRoute: '/',
onGenerateRoute: (RouteSettings settings) {
return new MaterialPageRoute<Null>(
settings: settings,
builder: (BuildContext context) {
return new Material(
child: new Center(
child: new DropdownButton<String>(
value: value,
items: items.map((String item) {
return new DropdownMenuItem<String>(
value: item,
child: new Text(item),
);
}).toList(),
onChanged: didChangeValue,
),
)
);
},
);
}
);
}
await tester.pumpWidget(build());
await tester.tap(find.text('one'));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // finish the menu animation
expect(value, equals('one'));
await tester.tap(find.text('three').last);
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // finish the menu animation
expect(value, equals('three'));
await tester.tap(find.text('three'));
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // finish the menu animation
expect(value, equals('three'));
await tester.pumpWidget(build());
await tester.tap(find.text('two').last);
await tester.pump();
await tester.pump(const Duration(seconds: 1)); // finish the menu animation
expect(value, equals('two'));
});
testWidgets('Drop down screen edges', (WidgetTester tester) async { testWidgets('Drop down screen edges', (WidgetTester tester) async {
int value = 4; int value = 4;
List<DropdownMenuItem<int>> items = <DropdownMenuItem<int>>[]; List<DropdownMenuItem<int>> items = <DropdownMenuItem<int>>[];
......
...@@ -34,6 +34,21 @@ void main() { ...@@ -34,6 +34,21 @@ void main() {
expect(Theme.of(tester.element(find.text('menuItem'))).brightness, equals(Brightness.dark)); expect(Theme.of(tester.element(find.text('menuItem'))).brightness, equals(Brightness.dark));
}); });
testWidgets('Fallback theme', (WidgetTester tester) async {
BuildContext capturedContext;
await tester.pumpWidget(
new Builder(
builder: (BuildContext context) {
capturedContext = context;
return new Container();
}
)
);
expect(Theme.of(capturedContext), equals(new ThemeData.fallback()));
expect(Theme.of(capturedContext, shadowThemeOnly: true), isNull);
});
testWidgets('PopupMenu inherits shadowed app theme', (WidgetTester tester) async { testWidgets('PopupMenu inherits shadowed app theme', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/5572 // Regression test for https://github.com/flutter/flutter/issues/5572
final Key popupMenuButtonKey = new UniqueKey(); final Key popupMenuButtonKey = new UniqueKey();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment