mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Anywhere that accepted IconData now accepts either an Icon or an ImageIcon. Places that used to take an IconData in an `icon` argument, notably IconButton and DrawerItem, now take a Widget in that slot. You can wrap the value that used to be passed in in an Icon constructor to get the same result. Icon itself now takes the icon as a positional argument, for brevity. ThemeData now has an iconTheme as well as a primaryIconTheme, the same way it has had a textTheme and primaryTextTheme for a while. IconTheme.of() always returns a value now (though that value itself may have nulls in it). It defaults to the ThemeData.iconTheme. IconThemeData.fallback() is a new method that returns an icon theme data structure with all fields filled in. IconTheme.merge() is a new constructor that takes a context and creates a widget that mixes in the new values with the inherited values. Most places that introduced an IconTheme widget now use IconTheme.merge. IconThemeData.merge and IconThemeData.copyWith act in a way analogous to the similarly-named members of TextStyle. ImageIcon is introduced. It acts like Icon but takes an ImageProvider instead of an IconData. Also: Fix the analyzer to actually check the stocks app.
81 lines
2.3 KiB
Dart
81 lines
2.3 KiB
Dart
// Copyright 2015 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
testWidgets('ImageIcon sizing - no theme, default size', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
new Center(
|
|
child: new ImageIcon(null)
|
|
)
|
|
);
|
|
|
|
RenderBox renderObject = tester.renderObject(find.byType(ImageIcon));
|
|
expect(renderObject.size, equals(const Size.square(24.0)));
|
|
});
|
|
|
|
testWidgets('ImageIcon sizing - no theme, explicit size', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
new Center(
|
|
child: new ImageIcon(
|
|
null,
|
|
size: 96.0
|
|
)
|
|
)
|
|
);
|
|
|
|
RenderBox renderObject = tester.renderObject(find.byType(ImageIcon));
|
|
expect(renderObject.size, equals(const Size.square(96.0)));
|
|
});
|
|
|
|
testWidgets('ImageIcon sizing - sized theme', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
new Center(
|
|
child: new IconTheme(
|
|
data: new IconThemeData(size: 36.0),
|
|
child: new ImageIcon(null)
|
|
)
|
|
)
|
|
);
|
|
|
|
RenderBox renderObject = tester.renderObject(find.byType(ImageIcon));
|
|
expect(renderObject.size, equals(const Size.square(36.0)));
|
|
});
|
|
|
|
testWidgets('ImageIcon sizing - sized theme, explicit size', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
new Center(
|
|
child: new IconTheme(
|
|
data: new IconThemeData(size: 36.0),
|
|
child: new ImageIcon(
|
|
null,
|
|
size: 48.0
|
|
)
|
|
)
|
|
)
|
|
);
|
|
|
|
RenderBox renderObject = tester.renderObject(find.byType(ImageIcon));
|
|
expect(renderObject.size, equals(const Size.square(48.0)));
|
|
});
|
|
|
|
testWidgets('ImageIcon sizing - sizeless theme, default size', (WidgetTester tester) async {
|
|
await tester.pumpWidget(
|
|
new Center(
|
|
child: new IconTheme(
|
|
data: new IconThemeData(),
|
|
child: new ImageIcon(null)
|
|
)
|
|
)
|
|
);
|
|
|
|
RenderBox renderObject = tester.renderObject(find.byType(ImageIcon));
|
|
expect(renderObject.size, equals(const Size.square(24.0)));
|
|
});
|
|
}
|