Change LicensePage's loading color from scaffoldBackgroundColor to cardColor (#64639)

* wrap LicensePage's loading widget with cardColor

* Set AnimatedSwitcer's duration in LicensePage to zero

* Remove AnimatedSwitcher

* Add test code for checking color is same
This commit is contained in:
GodHyum 2020-09-18 09:06:26 +09:00 committed by GitHub
parent 84aae22c3e
commit d26268bb9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 75 additions and 29 deletions

View file

@ -611,41 +611,40 @@ class _PackagesViewState extends State<_PackagesView> {
return FutureBuilder<_LicenseData>(
future: licenses,
builder: (BuildContext context, AsyncSnapshot<_LicenseData> snapshot) {
return AnimatedSwitcher(
transitionBuilder: (Widget child, Animation<double> animation) => FadeTransition(opacity: animation, child: child),
duration: kThemeAnimationDuration,
child: LayoutBuilder(
key: ValueKey<ConnectionState>(snapshot.connectionState),
builder: (BuildContext context, BoxConstraints constraints) {
switch (snapshot.connectionState) {
case ConnectionState.done:
_initDefaultDetailPage(snapshot.data, context);
return ValueListenableBuilder<int>(
valueListenable: widget.selectedId,
builder: (BuildContext context, int selectedId, Widget _) {
return Center(
child: Material(
color: Theme.of(context).cardColor,
elevation: 4.0,
child: Container(
constraints: BoxConstraints.loose(const Size.fromWidth(600.0)),
child: _packagesList(context, selectedId, snapshot.data, widget.isLateral),
),
return LayoutBuilder(
key: ValueKey<ConnectionState>(snapshot.connectionState),
builder: (BuildContext context, BoxConstraints constraints) {
switch (snapshot.connectionState) {
case ConnectionState.done:
_initDefaultDetailPage(snapshot.data, context);
return ValueListenableBuilder<int>(
valueListenable: widget.selectedId,
builder: (BuildContext context, int selectedId, Widget _) {
return Center(
child: Material(
color: Theme.of(context).cardColor,
elevation: 4.0,
child: Container(
constraints: BoxConstraints.loose(const Size.fromWidth(600.0)),
child: _packagesList(context, selectedId, snapshot.data, widget.isLateral),
),
);
},
);
default:
return Column(
),
);
},
);
default:
return Material(
color: Theme.of(context).cardColor,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
widget.about,
const Center(child: CircularProgressIndicator()),
],
);
}
},
),
),
);
}
},
);
},
);

View file

@ -664,6 +664,53 @@ void main() {
expect(box.localToGlobal(Offset.zero), equals(originalOffset.translate(0.0, -20.0)));
});
testWidgets("LicensePage's color must be same whether loading or done", (WidgetTester tester) async {
const Color scaffoldColor = Color(0xFF123456);
const Color cardColor = Color(0xFF654321);
await tester.pumpWidget(MaterialApp(
theme: ThemeData.light().copyWith(
scaffoldBackgroundColor: scaffoldColor,
cardColor: cardColor,
),
home: Scaffold(
body: Center(
child: Builder(
builder: (BuildContext context) => GestureDetector(
child: const Text('Show licenses'),
onTap: () {
showLicensePage(
context: context,
applicationName: 'MyApp',
applicationVersion: '1.0.0',
);
}
),
),
),
),
));
await tester.tap(find.text('Show licenses'));
await tester.pump();
await tester.pump();
// Check color when loading.
final List<Material> materialLoadings = tester.widgetList<Material>(find.byType(Material)).toList();
expect(materialLoadings.length, equals(4));
expect(materialLoadings[1].color, scaffoldColor);
expect(materialLoadings[2].color, cardColor);
await tester.pumpAndSettle();
// Check color when done.
expect(find.byKey(const ValueKey<ConnectionState>(ConnectionState.done)), findsOneWidget);
final List<Material> materialDones = tester.widgetList<Material>(find.byType(Material)).toList();
expect(materialDones.length, equals(3));
expect(materialDones[0].color, scaffoldColor);
expect(materialDones[1].color, cardColor);
});
}
class FakeLicenseEntry extends LicenseEntry {