Fix performance regression with _InheritedTheme (#10311)
Check ThemeData instead of Theme.
This commit is contained in:
parent
ccad2849e7
commit
c168afc070
@ -155,7 +155,7 @@ class _InheritedTheme extends InheritedWidget {
|
|||||||
final Theme theme;
|
final Theme theme;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool updateShouldNotify(_InheritedTheme old) => theme != old.theme;
|
bool updateShouldNotify(_InheritedTheme old) => theme.data != old.theme.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An interpolation between two [ThemeData]s.
|
/// An interpolation between two [ThemeData]s.
|
||||||
|
@ -265,4 +265,72 @@ void main() {
|
|||||||
expect(glyphText.text.style.color, Colors.orange);
|
expect(glyphText.text.style.color, Colors.orange);
|
||||||
expect(glyphText.text.style.fontSize, 20.0);
|
expect(glyphText.text.style.fontSize, 20.0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets(
|
||||||
|
'Same ThemeData reapplied does not trigger descendents rebuilds',
|
||||||
|
(WidgetTester tester) async {
|
||||||
|
testBuildCalled = 0;
|
||||||
|
ThemeData themeData = new ThemeData(primaryColor: const Color(0xFF000000));
|
||||||
|
|
||||||
|
await tester.pumpWidget(
|
||||||
|
new Theme(
|
||||||
|
data: themeData,
|
||||||
|
child: const Test(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
expect(testBuildCalled, 1);
|
||||||
|
|
||||||
|
// Pump the same widgets again.
|
||||||
|
await tester.pumpWidget(
|
||||||
|
new Theme(
|
||||||
|
data: themeData,
|
||||||
|
child: const Test(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// No repeated build calls to the child since it's the same theme data.
|
||||||
|
expect(testBuildCalled, 1);
|
||||||
|
|
||||||
|
// New instance of theme data but still the same content.
|
||||||
|
themeData = new ThemeData(primaryColor: const Color(0xFF000000));
|
||||||
|
await tester.pumpWidget(
|
||||||
|
new Theme(
|
||||||
|
data: themeData,
|
||||||
|
child: const Test(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// Still no repeated calls.
|
||||||
|
expect(testBuildCalled, 1);
|
||||||
|
|
||||||
|
// Different now.
|
||||||
|
themeData = new ThemeData(primaryColor: const Color(0xFF222222));
|
||||||
|
await tester.pumpWidget(
|
||||||
|
new Theme(
|
||||||
|
data: themeData,
|
||||||
|
child: const Test(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
// Should call build again.
|
||||||
|
expect(testBuildCalled, 2);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
int testBuildCalled;
|
||||||
|
class Test extends StatefulWidget {
|
||||||
|
const Test();
|
||||||
|
|
||||||
|
@override
|
||||||
|
_TestState createState() => new _TestState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TestState extends State<Test> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
testBuildCalled += 1;
|
||||||
|
return new Container(
|
||||||
|
decoration: new BoxDecoration(
|
||||||
|
color: Theme.of(context).primaryColor,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user