Migrate Flutter gallery test to null safety (#69048)

This commit is contained in:
Emmanuel Garcia
2020-11-06 20:38:12 -08:00
committed by GitHub
parent 52d49fb358
commit 7ba775a994
106 changed files with 1584 additions and 1624 deletions

View File

@@ -29,15 +29,13 @@ dependencies:
coverage: 0.14.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
crypto: 2.1.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
csslib: 0.16.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dart_style: 1.3.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
fake_async: 1.2.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
glob: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
html: 0.14.0+4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
http: 0.12.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
http_multi_server: 2.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
http_parser: 3.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
intl: 0.16.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
intl_translation: 0.17.10+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
intl: 0.17.0-nullsafety.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
io: 0.3.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
isolate: 2.0.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
js: 0.6.3-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -50,7 +48,6 @@ dependencies:
package_config: 1.9.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
path: 1.8.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pedantic: 1.10.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
petitparser: 3.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pool: 1.5.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pub_semver: 1.4.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
shelf: 0.7.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -77,4 +74,4 @@ dependencies:
flutter:
uses-material-design: true
# PUBSPEC CHECKSUM: 77af
# PUBSPEC CHECKSUM: 2c1c

View File

@@ -9,42 +9,23 @@ dependencies:
sdk: flutter
flutter_localizations:
sdk: flutter
intl: 0.16.1
intl_translation: 0.17.10+1
intl: 0.17.0-nullsafety.2
http: 0.12.2
isolate: 2.0.3
_fe_analyzer_shared: 7.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
analyzer: 0.39.17 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
args: 1.6.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
async: 2.5.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
characters: 1.1.0-nullsafety.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
charcode: 1.2.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
cli_util: 0.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
clock: 1.1.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
collection: 1.15.0-nullsafety.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
convert: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
crypto: 2.1.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
csslib: 0.16.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dart_style: 1.3.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
glob: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
html: 0.14.0+4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
http_parser: 3.1.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
js: 0.6.3-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
meta: 1.3.0-nullsafety.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
node_interop: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
node_io: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
package_config: 1.9.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
path: 1.8.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pedantic: 1.10.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
petitparser: 3.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pub_semver: 1.4.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
source_span: 1.8.0-nullsafety.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
string_scanner: 1.1.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
term_glyph: 1.2.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
typed_data: 1.3.0-nullsafety.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vector_math: 2.1.0-nullsafety.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
watcher: 0.9.7+15 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
yaml: 2.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
dev_dependencies:
flutter_test:
@@ -53,19 +34,33 @@ dev_dependencies:
sdk: flutter
test: 1.16.0-nullsafety.9
_fe_analyzer_shared: 7.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
analyzer: 0.39.17 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
archive: 2.0.13 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
args: 1.6.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
async: 2.5.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
boolean_selector: 2.1.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
clock: 1.1.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
cli_util: 0.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
convert: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
coverage: 0.14.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
crypto: 2.1.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
csslib: 0.16.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
fake_async: 1.2.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
file: 6.0.0-nullsafety.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
glob: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
html: 0.14.0+4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
http_multi_server: 2.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
io: 0.3.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
js: 0.6.3-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
logging: 0.11.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
matcher: 0.12.10-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
mime: 0.9.7 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
node_interop: 1.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
node_io: 1.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
node_preamble: 1.4.12 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
package_config: 1.9.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pool: 1.5.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pub_semver: 1.4.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
shelf: 0.7.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
shelf_packages_handler: 2.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
shelf_static: 0.2.8 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -78,11 +73,13 @@ dev_dependencies:
test_api: 0.2.19-nullsafety.6 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
test_core: 0.3.12-nullsafety.9 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
vm_service: 5.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
watcher: 0.9.7+15 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
web_socket_channel: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
webdriver: 2.1.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
webkit_inspection_protocol: 0.7.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
yaml: 2.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
flutter:
uses-material-design: true
# PUBSPEC CHECKSUM: b21f
# PUBSPEC CHECKSUM: 4b8b

View File

@@ -32,10 +32,10 @@ const double _kAppBarMidHeight = 256.0;
// TODO(hansmuller): it would be worth adding something like this to the framework.
class _RenderStatusBarPaddingSliver extends RenderSliver {
_RenderStatusBarPaddingSliver({
@required double maxHeight,
@required double scrollFactor,
}) : assert(maxHeight != null && maxHeight >= 0.0),
assert(scrollFactor != null && scrollFactor >= 1.0),
required double maxHeight,
required double scrollFactor,
}) : assert(maxHeight >= 0.0),
assert(scrollFactor >= 1.0),
_maxHeight = maxHeight,
_scrollFactor = scrollFactor;
@@ -43,7 +43,7 @@ class _RenderStatusBarPaddingSliver extends RenderSliver {
double get maxHeight => _maxHeight;
double _maxHeight;
set maxHeight(double value) {
assert(maxHeight != null && maxHeight >= 0.0);
assert(maxHeight >= 0.0);
if (_maxHeight == value)
return;
_maxHeight = value;
@@ -55,7 +55,7 @@ class _RenderStatusBarPaddingSliver extends RenderSliver {
double get scrollFactor => _scrollFactor;
double _scrollFactor;
set scrollFactor(double value) {
assert(scrollFactor != null && scrollFactor >= 1.0);
assert(scrollFactor >= 1.0);
if (_scrollFactor == value)
return;
_scrollFactor = value;
@@ -64,7 +64,7 @@ class _RenderStatusBarPaddingSliver extends RenderSliver {
@override
void performLayout() {
final double height = (maxHeight - constraints.scrollOffset / scrollFactor).clamp(0.0, maxHeight) as double;
final double height = (maxHeight - constraints.scrollOffset / scrollFactor).clamp(0.0, maxHeight);
geometry = SliverGeometry(
paintExtent: math.min(height, constraints.remainingPaintExtent),
scrollExtent: maxHeight,
@@ -75,11 +75,11 @@ class _RenderStatusBarPaddingSliver extends RenderSliver {
class _StatusBarPaddingSliver extends SingleChildRenderObjectWidget {
const _StatusBarPaddingSliver({
Key key,
@required this.maxHeight,
Key? key,
required this.maxHeight,
this.scrollFactor = 5.0,
}) : assert(maxHeight != null && maxHeight >= 0.0),
assert(scrollFactor != null && scrollFactor >= 1.0),
}) : assert(maxHeight >= 0.0),
assert(scrollFactor >= 1.0),
super(key: key);
final double maxHeight;
@@ -110,9 +110,9 @@ class _StatusBarPaddingSliver extends SingleChildRenderObjectWidget {
class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate {
_SliverAppBarDelegate({
@required this.minHeight,
@required this.maxHeight,
@required this.child,
required this.minHeight,
required this.maxHeight,
required this.child,
});
final double minHeight;
@@ -170,51 +170,51 @@ class _AllSectionsLayout extends MultiChildLayoutDelegate {
this.selectedIndex,
});
final Alignment translation;
final double tColumnToRow;
final double tCollapsed;
final int cardCount;
final double selectedIndex;
final Alignment? translation;
final double? tColumnToRow;
final double? tCollapsed;
final int? cardCount;
final double? selectedIndex;
Rect _interpolateRect(Rect begin, Rect end) {
return Rect.lerp(begin, end, tColumnToRow);
Rect? _interpolateRect(Rect begin, Rect end) {
return Rect.lerp(begin, end, tColumnToRow!);
}
Offset _interpolatePoint(Offset begin, Offset end) {
return Offset.lerp(begin, end, tColumnToRow);
Offset? _interpolatePoint(Offset begin, Offset end) {
return Offset.lerp(begin, end, tColumnToRow!);
}
@override
void performLayout(Size size) {
final double columnCardX = size.width / 5.0;
final double columnCardWidth = size.width - columnCardX;
final double columnCardHeight = size.height / cardCount;
final double columnCardHeight = size.height / cardCount!;
final double rowCardWidth = size.width;
final Offset offset = translation.alongSize(size);
final Offset offset = translation!.alongSize(size);
double columnCardY = 0.0;
double rowCardX = -(selectedIndex * rowCardWidth);
double rowCardX = -(selectedIndex! * rowCardWidth);
// When tCollapsed > 0 the titles spread apart
final double columnTitleX = size.width / 10.0;
final double rowTitleWidth = size.width * ((1 + tCollapsed) / 2.25);
double rowTitleX = (size.width - rowTitleWidth) / 2.0 - selectedIndex * rowTitleWidth;
final double rowTitleWidth = size.width * ((1 + tCollapsed!) / 2.25);
double rowTitleX = (size.width - rowTitleWidth) / 2.0 - selectedIndex! * rowTitleWidth;
// When tCollapsed > 0, the indicators move closer together
//final double rowIndicatorWidth = 48.0 + (1.0 - tCollapsed) * (rowTitleWidth - 48.0);
const double paddedSectionIndicatorWidth = kSectionIndicatorWidth + 8.0;
final double rowIndicatorWidth = paddedSectionIndicatorWidth +
(1.0 - tCollapsed) * (rowTitleWidth - paddedSectionIndicatorWidth);
double rowIndicatorX = (size.width - rowIndicatorWidth) / 2.0 - selectedIndex * rowIndicatorWidth;
(1.0 - tCollapsed!) * (rowTitleWidth - paddedSectionIndicatorWidth);
double rowIndicatorX = (size.width - rowIndicatorWidth) / 2.0 - selectedIndex! * rowIndicatorWidth;
// Compute the size and origin of each card, title, and indicator for the maxHeight
// "column" layout, and the midHeight "row" layout. The actual layout is just the
// interpolated value between the column and row layouts for t.
for (int index = 0; index < cardCount; index++) {
for (int index = 0; index < cardCount!; index++) {
// Layout the card for index.
final Rect columnCardRect = Rect.fromLTWH(columnCardX, columnCardY, columnCardWidth, columnCardHeight);
final Rect rowCardRect = Rect.fromLTWH(rowCardX, 0.0, rowCardWidth, size.height);
final Rect cardRect = _interpolateRect(columnCardRect, rowCardRect).shift(offset);
final Rect cardRect = _interpolateRect(columnCardRect, rowCardRect)!.shift(offset);
final String cardId = 'card$index';
if (hasChild(cardId)) {
layoutChild(cardId, BoxConstraints.tight(cardRect.size));
@@ -228,7 +228,7 @@ class _AllSectionsLayout extends MultiChildLayoutDelegate {
final double centeredRowTitleX = rowTitleX + (rowTitleWidth - titleSize.width) / 2.0;
final Offset columnTitleOrigin = Offset(columnTitleX, columnTitleY);
final Offset rowTitleOrigin = Offset(centeredRowTitleX, rowTitleY);
final Offset titleOrigin = _interpolatePoint(columnTitleOrigin, rowTitleOrigin);
final Offset titleOrigin = _interpolatePoint(columnTitleOrigin, rowTitleOrigin)!;
positionChild('title$index', titleOrigin + offset);
// Layout the selection indicator for index.
@@ -240,7 +240,7 @@ class _AllSectionsLayout extends MultiChildLayoutDelegate {
final double centeredRowIndicatorX = rowIndicatorX + (rowIndicatorWidth - indicatorSize.width) / 2.0;
final double rowIndicatorY = titleRect.bottomCenter.dy + 16.0;
final Offset rowIndicatorOrigin = Offset(centeredRowIndicatorX, rowIndicatorY);
final Offset indicatorOrigin = _interpolatePoint(columnIndicatorOrigin, rowIndicatorOrigin);
final Offset indicatorOrigin = _interpolatePoint(columnIndicatorOrigin, rowIndicatorOrigin)!;
positionChild('indicator$index', indicatorOrigin + offset);
columnCardY += columnCardHeight;
@@ -260,32 +260,29 @@ class _AllSectionsLayout extends MultiChildLayoutDelegate {
class _AllSectionsView extends AnimatedWidget {
_AllSectionsView({
Key key,
this.sectionIndex,
@required this.sections,
@required this.selectedIndex,
Key? key,
required this.sectionIndex,
required this.sections,
required this.selectedIndex,
this.minHeight,
this.midHeight,
this.maxHeight,
this.sectionCards = const <Widget>[],
}) : assert(sections != null),
assert(sectionCards != null),
assert(sectionCards.length == sections.length),
}) : assert(sectionCards.length == sections.length),
assert(sectionIndex >= 0 && sectionIndex < sections.length),
assert(selectedIndex != null),
assert(selectedIndex.value >= 0.0 && selectedIndex.value < sections.length.toDouble()),
assert(selectedIndex.value! >= 0.0 && selectedIndex.value! < sections.length.toDouble()),
super(key: key, listenable: selectedIndex);
final int sectionIndex;
final List<Section> sections;
final ValueNotifier<double> selectedIndex;
final double minHeight;
final double midHeight;
final double maxHeight;
final ValueNotifier<double?> selectedIndex;
final double? minHeight;
final double? midHeight;
final double? maxHeight;
final List<Widget> sectionCards;
double _selectedIndexDelta(int index) {
return (index.toDouble() - selectedIndex.value).abs().clamp(0.0, 1.0) as double;
return (index.toDouble() - selectedIndex.value!).abs().clamp(0.0, 1.0);
}
Widget _build(BuildContext context, BoxConstraints constraints) {
@@ -295,16 +292,16 @@ class _AllSectionsView extends AnimatedWidget {
// 0.0 when size.height equals the maxHeight, 1.0 when the size.height
// equals the midHeight.
final double tColumnToRow =
1.0 - ((size.height - midHeight) /
(maxHeight - midHeight)).clamp(0.0, 1.0);
1.0 - ((size.height - midHeight!) /
(maxHeight! - midHeight!)).clamp(0.0, 1.0);
// The layout's progress from from the midHeight row layout to
// a minHeight row layout. Its value is 0.0 when size.height equals
// midHeight and 1.0 when size.height equals minHeight.
final double tCollapsed =
1.0 - ((size.height - minHeight) /
(midHeight - minHeight)).clamp(0.0, 1.0);
1.0 - ((size.height - minHeight!) /
(midHeight! - minHeight!)).clamp(0.0, 1.0);
double _indicatorOpacity(int index) {
return 1.0 - _selectedIndexDelta(index) * 0.5;
@@ -343,7 +340,7 @@ class _AllSectionsView extends AnimatedWidget {
return CustomMultiChildLayout(
delegate: _AllSectionsLayout(
translation: Alignment((selectedIndex.value - sectionIndex) * 2.0 - 1.0, -1.0),
translation: Alignment((selectedIndex.value! - sectionIndex) * 2.0 - 1.0, -1.0),
tColumnToRow: tColumnToRow,
tCollapsed: tCollapsed,
cardCount: sections.length,
@@ -364,15 +361,14 @@ class _AllSectionsView extends AnimatedWidget {
// visible.
class _SnappingScrollPhysics extends ClampingScrollPhysics {
const _SnappingScrollPhysics({
ScrollPhysics parent,
@required this.midScrollOffset,
}) : assert(midScrollOffset != null),
super(parent: parent);
ScrollPhysics? parent,
required this.midScrollOffset,
}) : super(parent: parent);
final double midScrollOffset;
@override
_SnappingScrollPhysics applyTo(ScrollPhysics ancestor) {
_SnappingScrollPhysics applyTo(ScrollPhysics? ancestor) {
return _SnappingScrollPhysics(parent: buildParent(ancestor), midScrollOffset: midScrollOffset);
}
@@ -387,8 +383,8 @@ class _SnappingScrollPhysics extends ClampingScrollPhysics {
}
@override
Simulation createBallisticSimulation(ScrollMetrics position, double dragVelocity) {
final Simulation simulation = super.createBallisticSimulation(position, dragVelocity);
Simulation? createBallisticSimulation(ScrollMetrics position, double dragVelocity) {
final Simulation? simulation = super.createBallisticSimulation(position, dragVelocity);
final double offset = position.pixels;
if (simulation != null) {
@@ -419,7 +415,7 @@ class _SnappingScrollPhysics extends ClampingScrollPhysics {
}
class AnimationDemoHome extends StatefulWidget {
const AnimationDemoHome({ Key key }) : super(key: key);
const AnimationDemoHome({ Key? key }) : super(key: key);
static const String routeName = '/animation';
@@ -432,7 +428,7 @@ class _AnimationDemoHomeState extends State<AnimationDemoHome> {
final PageController _headingPageController = PageController();
final PageController _detailsPageController = PageController();
ScrollPhysics _headingScrollPhysics = const NeverScrollableScrollPhysics();
ValueNotifier<double> selectedIndex = ValueNotifier<double>(0.0);
ValueNotifier<double?> selectedIndex = ValueNotifier<double?>(0.0);
@override
Widget build(BuildContext context) {
@@ -492,7 +488,7 @@ class _AnimationDemoHomeState extends State<AnimationDemoHome> {
}
Iterable<Widget> _detailItemsFor(Section section) {
final Iterable<Widget> detailItems = section.details.map<Widget>((SectionDetail detail) {
final Iterable<Widget> detailItems = section.details!.map<Widget>((SectionDetail detail) {
return SectionDetailView(detail: detail);
});
return ListTile.divideTiles(context: context, tiles: detailItems);

View File

@@ -20,10 +20,10 @@ class SectionDetail {
this.imageAsset,
this.imageAssetPackage,
});
final String title;
final String subtitle;
final String imageAsset;
final String imageAssetPackage;
final String? title;
final String? subtitle;
final String? imageAsset;
final String? imageAssetPackage;
}
@immutable
@@ -36,12 +36,12 @@ class Section {
this.rightColor,
this.details,
});
final String title;
final String backgroundAsset;
final String backgroundAssetPackage;
final Color leftColor;
final Color rightColor;
final List<SectionDetail> details;
final String? title;
final String? backgroundAsset;
final String? backgroundAssetPackage;
final Color? leftColor;
final Color? rightColor;
final List<SectionDetail>? details;
@override
bool operator==(Object other) {

View File

@@ -10,9 +10,8 @@ const double kSectionIndicatorWidth = 32.0;
// The card for a single section. Displays the section's gradient and background image.
class SectionCard extends StatelessWidget {
const SectionCard({ Key key, @required this.section })
: assert(section != null),
super(key: key);
const SectionCard({ Key? key, required this.section })
: super(key: key);
final Section section;
@@ -27,13 +26,13 @@ class SectionCard extends StatelessWidget {
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: <Color>[
section.leftColor,
section.rightColor,
section.leftColor!,
section.rightColor!,
],
),
),
child: Image.asset(
section.backgroundAsset,
section.backgroundAsset!,
package: section.backgroundAssetPackage,
color: const Color.fromRGBO(255, 255, 255, 0.075),
colorBlendMode: BlendMode.modulate,
@@ -48,13 +47,11 @@ class SectionCard extends StatelessWidget {
// offset a little. It's supposed to look sort-of 3D.
class SectionTitle extends StatelessWidget {
const SectionTitle({
Key key,
@required this.section,
@required this.scale,
@required this.opacity,
}) : assert(section != null),
assert(scale != null),
assert(opacity != null && opacity >= 0.0 && opacity <= 1.0),
Key? key,
required this.section,
required this.scale,
required this.opacity,
}) : assert(opacity >= 0.0 && opacity <= 1.0),
super(key: key);
final Section section;
@@ -86,9 +83,9 @@ class SectionTitle extends StatelessWidget {
children: <Widget>[
Positioned(
top: 4.0,
child: Text(section.title, style: sectionTitleShadowStyle),
child: Text(section.title!, style: sectionTitleShadowStyle),
),
Text(section.title, style: sectionTitleStyle),
Text(section.title!, style: sectionTitleStyle),
],
),
),
@@ -99,7 +96,7 @@ class SectionTitle extends StatelessWidget {
// Small horizontal bar that indicates the selected section.
class SectionIndicator extends StatelessWidget {
const SectionIndicator({ Key key, this.opacity = 1.0 }) : super(key: key);
const SectionIndicator({ Key? key, this.opacity = 1.0 }) : super(key: key);
final double opacity;
@@ -117,8 +114,8 @@ class SectionIndicator extends StatelessWidget {
// Display a single SectionDetail.
class SectionDetailView extends StatelessWidget {
SectionDetailView({ Key key, @required this.detail })
: assert(detail != null && detail.imageAsset != null),
SectionDetailView({ Key? key, required this.detail })
: assert(detail.imageAsset != null),
assert((detail.imageAsset ?? detail.title) != null),
super(key: key);
@@ -131,7 +128,7 @@ class SectionDetailView extends StatelessWidget {
borderRadius: BorderRadius.circular(6.0),
image: DecorationImage(
image: AssetImage(
detail.imageAsset,
detail.imageAsset!,
package: detail.imageAssetPackage,
),
fit: BoxFit.cover,
@@ -153,8 +150,8 @@ class SectionDetailView extends StatelessWidget {
);
} else {
item = ListTile(
title: Text(detail.title),
subtitle: Text(detail.subtitle),
title: Text(detail.title!),
subtitle: Text(detail.subtitle!),
leading: SizedBox(width: 32.0, height: 32.0, child: image),
);
}

View File

@@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
import 'animation/home.dart';
class AnimationDemo extends StatelessWidget {
const AnimationDemo({Key key}) : super(key: key);
const AnimationDemo({Key? key}) : super(key: key);
static const String routeName = '/animation';

View File

@@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
import 'logic.dart';
class Calculator extends StatefulWidget {
const Calculator({Key key}) : super(key: key);
const Calculator({Key? key}) : super(key: key);
@override
_CalculatorState createState() => _CalculatorState();
@@ -43,7 +43,7 @@ class _CalculatorState extends State<Calculator> {
}
void handleNumberTap(int n) {
final CalcExpression expression = _expression.appendDigit(n);
final CalcExpression? expression = _expression.appendDigit(n);
if (expression != null) {
setState(() {
pushExpression(expression);
@@ -52,7 +52,7 @@ class _CalculatorState extends State<Calculator> {
}
void handlePointTap() {
final CalcExpression expression = _expression.appendPoint();
final CalcExpression? expression = _expression.appendPoint();
if (expression != null) {
setState(() {
pushExpression(expression);
@@ -61,7 +61,7 @@ class _CalculatorState extends State<Calculator> {
}
void handlePlusTap() {
final CalcExpression expression = _expression.appendOperation(Operation.Addition);
final CalcExpression? expression = _expression.appendOperation(Operation.Addition);
if (expression != null) {
setState(() {
pushExpression(expression);
@@ -70,7 +70,7 @@ class _CalculatorState extends State<Calculator> {
}
void handleMinusTap() {
final CalcExpression expression = _expression.appendMinus();
final CalcExpression? expression = _expression.appendMinus();
if (expression != null) {
setState(() {
pushExpression(expression);
@@ -79,7 +79,7 @@ class _CalculatorState extends State<Calculator> {
}
void handleMultTap() {
final CalcExpression expression = _expression.appendOperation(Operation.Multiplication);
final CalcExpression? expression = _expression.appendOperation(Operation.Multiplication);
if (expression != null) {
setState(() {
pushExpression(expression);
@@ -88,7 +88,7 @@ class _CalculatorState extends State<Calculator> {
}
void handleDivTap() {
final CalcExpression expression = _expression.appendOperation(Operation.Division);
final CalcExpression? expression = _expression.appendOperation(Operation.Division);
if (expression != null) {
setState(() {
pushExpression(expression);
@@ -97,7 +97,7 @@ class _CalculatorState extends State<Calculator> {
}
void handleEqualsTap() {
final CalcExpression resultExpression = _expression.computeResult();
final CalcExpression? resultExpression = _expression.computeResult();
if (resultExpression != null) {
setState(() {
setResult(resultExpression);
@@ -140,13 +140,13 @@ class _CalculatorState extends State<Calculator> {
class CalcDisplay extends StatelessWidget {
const CalcDisplay({ this.content });
final String content;
final String? content;
@override
Widget build(BuildContext context) {
return Center(
child: Text(
content,
content!,
style: const TextStyle(fontSize: 24.0),
),
);
@@ -156,7 +156,7 @@ class CalcDisplay extends StatelessWidget {
class KeyPad extends StatelessWidget {
const KeyPad({ this.calcState });
final _CalculatorState calcState;
final _CalculatorState? calcState;
@override
Widget build(BuildContext context) {
@@ -193,9 +193,9 @@ class KeyPad extends StatelessWidget {
NumberKey(3, calcState),
]),
KeyRow(<Widget>[
CalcKey('.', calcState.handlePointTap),
CalcKey('.', calcState!.handlePointTap),
NumberKey(0, calcState),
CalcKey('=', calcState.handleEqualsTap),
CalcKey('=', calcState!.handleEqualsTap),
]),
],
),
@@ -205,11 +205,11 @@ class KeyPad extends StatelessWidget {
color: themeData.backgroundColor,
child: Column(
children: <Widget>[
CalcKey('\u232B', calcState.handleDelTap),
CalcKey('\u00F7', calcState.handleDivTap),
CalcKey('\u00D7', calcState.handleMultTap),
CalcKey('-', calcState.handleMinusTap),
CalcKey('+', calcState.handlePlusTap),
CalcKey('\u232B', calcState!.handleDelTap),
CalcKey('\u00F7', calcState!.handleDivTap),
CalcKey('\u00D7', calcState!.handleMultTap),
CalcKey('-', calcState!.handleMinusTap),
CalcKey('+', calcState!.handlePlusTap),
],
),
),
@@ -263,8 +263,8 @@ class CalcKey extends StatelessWidget {
}
class NumberKey extends CalcKey {
NumberKey(int value, _CalculatorState calcState)
NumberKey(int value, _CalculatorState? calcState)
: super('$value', () {
calcState.handleNumberTap(value);
calcState!.handleNumberTap(value);
});
}

View File

@@ -9,10 +9,10 @@
class ExpressionToken {
ExpressionToken(this.stringRep);
final String stringRep;
final String? stringRep;
@override
String toString() => stringRep;
String toString() => stringRep!;
}
/// A token that represents a number.
@@ -71,7 +71,7 @@ class OperationToken extends ExpressionToken {
Operation operation;
static String opString(Operation operation) {
static String? opString(Operation operation) {
switch (operation) {
case Operation.Addition:
return ' + ';
@@ -82,8 +82,6 @@ class OperationToken extends ExpressionToken {
case Operation.Division:
return ' \u00F7 ';
}
assert(operation != null);
return null;
}
}
@@ -124,13 +122,13 @@ class CalcExpression {
: this(<ExpressionToken>[], ExpressionState.Start);
CalcExpression.result(FloatToken result)
: _list = <ExpressionToken>[],
: _list = <ExpressionToken?>[],
state = ExpressionState.Result {
_list.add(result);
}
/// The tokens comprising the expression.
final List<ExpressionToken> _list;
final List<ExpressionToken?> _list;
/// The state of the expression.
final ExpressionState state;
@@ -146,10 +144,10 @@ class CalcExpression {
/// Append a digit to the current expression and return a new expression
/// representing the result. Returns null to indicate that it is not legal
/// to append a digit in the current state.
CalcExpression appendDigit(int digit) {
CalcExpression? appendDigit(int digit) {
ExpressionState newState = ExpressionState.Number;
ExpressionToken newToken;
final List<ExpressionToken> outList = _list.toList();
ExpressionToken? newToken;
final List<ExpressionToken?> outList = _list.toList();
switch (state) {
case ExpressionState.Start:
// Start a new number with digit.
@@ -161,12 +159,12 @@ class CalcExpression {
newToken = IntToken('-$digit');
break;
case ExpressionState.Number:
final ExpressionToken last = outList.removeLast();
final ExpressionToken last = outList.removeLast()!;
newToken = IntToken('${last.stringRep}$digit');
break;
case ExpressionState.Point:
case ExpressionState.NumberWithPoint:
final ExpressionToken last = outList.removeLast();
final ExpressionToken last = outList.removeLast()!;
newState = ExpressionState.NumberWithPoint;
newToken = FloatToken('${last.stringRep}$digit');
break;
@@ -181,17 +179,17 @@ class CalcExpression {
/// Append a point to the current expression and return a new expression
/// representing the result. Returns null to indicate that it is not legal
/// to append a point in the current state.
CalcExpression appendPoint() {
ExpressionToken newToken;
final List<ExpressionToken> outList = _list.toList();
CalcExpression? appendPoint() {
ExpressionToken? newToken;
final List<ExpressionToken?> outList = _list.toList();
switch (state) {
case ExpressionState.Start:
newToken = FloatToken('.');
break;
case ExpressionState.LeadingNeg:
case ExpressionState.Number:
final ExpressionToken last = outList.removeLast();
newToken = FloatToken(last.stringRep + '.');
final ExpressionToken last = outList.removeLast()!;
newToken = FloatToken(last.stringRep! + '.');
break;
case ExpressionState.Point:
case ExpressionState.NumberWithPoint:
@@ -206,7 +204,7 @@ class CalcExpression {
/// Append an operation symbol to the current expression and return a new
/// expression representing the result. Returns null to indicate that it is not
/// legal to append an operation symbol in the current state.
CalcExpression appendOperation(Operation op) {
CalcExpression? appendOperation(Operation op) {
switch (state) {
case ExpressionState.Start:
case ExpressionState.LeadingNeg:
@@ -218,7 +216,7 @@ class CalcExpression {
case ExpressionState.Result:
break;
}
final List<ExpressionToken> outList = _list.toList();
final List<ExpressionToken?> outList = _list.toList();
outList.add(OperationToken(op));
return CalcExpression(outList, ExpressionState.Start);
}
@@ -226,7 +224,7 @@ class CalcExpression {
/// Append a leading minus sign to the current expression and return a new
/// expression representing the result. Returns null to indicate that it is not
/// legal to append a leading minus sign in the current state.
CalcExpression appendLeadingNeg() {
CalcExpression? appendLeadingNeg() {
switch (state) {
case ExpressionState.Start:
break;
@@ -238,7 +236,7 @@ class CalcExpression {
// Cannot enter leading neg now.
return null;
}
final List<ExpressionToken> outList = _list.toList();
final List<ExpressionToken?> outList = _list.toList();
outList.add(LeadingNegToken());
return CalcExpression(outList, ExpressionState.LeadingNeg);
}
@@ -248,7 +246,7 @@ class CalcExpression {
/// to append a minus sign in the current state. Depending on the current
/// state the minus sign will be interpreted as either a leading negative
/// sign or a subtraction operation.
CalcExpression appendMinus() {
CalcExpression? appendMinus() {
switch (state) {
case ExpressionState.Start:
return appendLeadingNeg();
@@ -266,7 +264,7 @@ class CalcExpression {
/// Computes the result of the current expression and returns a new
/// ResultExpression containing the result. Returns null to indicate that
/// it is not legal to compute a result in the current state.
CalcExpression computeResult() {
CalcExpression? computeResult() {
switch (state) {
case ExpressionState.Start:
case ExpressionState.LeadingNeg:
@@ -281,13 +279,13 @@ class CalcExpression {
// We make a copy of _list because CalcExpressions are supposed to
// be immutable.
final List<ExpressionToken> list = _list.toList();
final List<ExpressionToken?> list = _list.toList();
// We obey order-of-operations by computing the sum of the 'terms',
// where a "term" is defined to be a sequence of numbers separated by
// multiplication or division symbols.
num currentTermValue = removeNextTerm(list);
while (list.isNotEmpty) {
final OperationToken opToken = list.removeAt(0) as OperationToken;
final OperationToken opToken = list.removeAt(0)! as OperationToken;
final num nextTermValue = removeNextTerm(list);
switch (opToken.operation) {
case Operation.Addition:
@@ -311,13 +309,13 @@ class CalcExpression {
/// Removes the next "term" from `list` and returns its numeric value.
/// A "term" is a sequence of number tokens separated by multiplication
/// and division symbols.
static num removeNextTerm(List<ExpressionToken> list) {
assert(list != null && list.isNotEmpty);
final NumberToken firstNumToken = list.removeAt(0) as NumberToken;
static num removeNextTerm(List<ExpressionToken?> list) {
assert(list.isNotEmpty);
final NumberToken firstNumToken = list.removeAt(0)! as NumberToken;
num currentValue = firstNumToken.number;
while (list.isNotEmpty) {
bool isDivision = false;
final OperationToken nextOpToken = list.first as OperationToken;
final OperationToken nextOpToken = list.first! as OperationToken;
switch (nextOpToken.operation) {
case Operation.Addition:
case Operation.Subtraction:
@@ -331,7 +329,7 @@ class CalcExpression {
// Remove the operation token.
list.removeAt(0);
// Remove the next number token.
final NumberToken nextNumToken = list.removeAt(0) as NumberToken;
final NumberToken nextNumToken = list.removeAt(0)! as NumberToken;
final num nextNumber = nextNumToken.number;
if (isDivision)
currentValue /= nextNumber;

View File

@@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
import 'calculator/home.dart';
class CalculatorDemo extends StatelessWidget {
const CalculatorDemo({Key key}) : super(key: key);
const CalculatorDemo({Key? key}) : super(key: key);
static const String routeName = '/calculator';

View File

@@ -9,12 +9,12 @@ const double kColorItemHeight = 48.0;
class Palette {
Palette({ this.name, this.primary, this.accent, this.threshold = 900});
final String name;
final MaterialColor primary;
final MaterialAccentColor accent;
final String? name;
final MaterialColor? primary;
final MaterialAccentColor? accent;
final int threshold; // titles for indices > threshold are white, otherwise black
bool get isValid => name != null && primary != null && threshold != null;
bool get isValid => name != null && primary != null;
}
final List<Palette> allPalettes = <Palette>[
@@ -42,14 +42,11 @@ final List<Palette> allPalettes = <Palette>[
class ColorItem extends StatelessWidget {
const ColorItem({
Key key,
@required this.index,
@required this.color,
Key? key,
required this.index,
required this.color,
this.prefix = '',
}) : assert(index != null),
assert(color != null),
assert(prefix != null),
super(key: key);
}) : super(key: key);
final int index;
final Color color;
@@ -84,9 +81,9 @@ class ColorItem extends StatelessWidget {
class PaletteTabView extends StatelessWidget {
PaletteTabView({
Key key,
@required this.colors,
}) : assert(colors != null && colors.isValid),
Key? key,
required this.colors,
}) : assert(colors.isValid),
super(key: key);
final Palette colors;
@@ -97,8 +94,8 @@ class PaletteTabView extends StatelessWidget {
@override
Widget build(BuildContext context) {
final TextTheme textTheme = Theme.of(context).textTheme;
final TextStyle whiteTextStyle = textTheme.bodyText2.copyWith(color: Colors.white);
final TextStyle blackTextStyle = textTheme.bodyText2.copyWith(color: Colors.black);
final TextStyle whiteTextStyle = textTheme.bodyText2!.copyWith(color: Colors.white);
final TextStyle blackTextStyle = textTheme.bodyText2!.copyWith(color: Colors.black);
return Scrollbar(
child: ListView(
itemExtent: kColorItemHeight,
@@ -106,14 +103,14 @@ class PaletteTabView extends StatelessWidget {
...primaryKeys.map<Widget>((int index) {
return DefaultTextStyle(
style: index > colors.threshold ? whiteTextStyle : blackTextStyle,
child: ColorItem(index: index, color: colors.primary[index]),
child: ColorItem(index: index, color: colors.primary![index]!),
);
}),
if (colors.accent != null)
...accentKeys.map<Widget>((int index) {
return DefaultTextStyle(
style: index > colors.threshold ? whiteTextStyle : blackTextStyle,
child: ColorItem(index: index, color: colors.accent[index], prefix: 'A'),
child: ColorItem(index: index, color: colors.accent![index]!, prefix: 'A'),
);
}),
],

View File

@@ -6,10 +6,10 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
class _ContactCategory extends StatelessWidget {
const _ContactCategory({ Key key, this.icon, this.children }) : super(key: key);
const _ContactCategory({ Key? key, this.icon, this.children }) : super(key: key);
final IconData icon;
final List<Widget> children;
final IconData? icon;
final List<Widget>? children;
@override
Widget build(BuildContext context) {
@@ -20,7 +20,7 @@ class _ContactCategory extends StatelessWidget {
border: Border(bottom: BorderSide(color: themeData.dividerColor))
),
child: DefaultTextStyle(
style: Theme.of(context).textTheme.subtitle1,
style: Theme.of(context).textTheme.subtitle1!,
child: SafeArea(
top: false,
bottom: false,
@@ -32,7 +32,7 @@ class _ContactCategory extends StatelessWidget {
width: 72.0,
child: Icon(icon, color: themeData.primaryColor),
),
Expanded(child: Column(children: children)),
Expanded(child: Column(children: children!)),
],
),
),
@@ -42,14 +42,14 @@ class _ContactCategory extends StatelessWidget {
}
class _ContactItem extends StatelessWidget {
const _ContactItem({ Key key, this.icon, this.lines, this.tooltip, this.onPressed })
const _ContactItem({ Key? key, this.icon, required this.lines, this.tooltip, this.onPressed })
: assert(lines.length > 1),
super(key: key);
final IconData icon;
final IconData? icon;
final List<String> lines;
final String tooltip;
final VoidCallback onPressed;
final String? tooltip;
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) {

View File

@@ -14,24 +14,24 @@ class CupertinoAlertDemo extends StatefulWidget {
}
class _CupertinoAlertDemoState extends State<CupertinoAlertDemo> {
String lastSelectedValue;
String? lastSelectedValue;
void showDemoDialog({BuildContext context, Widget child}) {
void showDemoDialog({required BuildContext context, Widget? child}) {
showCupertinoDialog<String>(
context: context,
builder: (BuildContext context) => child,
).then((String value) {
builder: (BuildContext context) => child!,
).then((String? value) {
if (value != null) {
setState(() { lastSelectedValue = value; });
}
});
}
void showDemoActionSheet({BuildContext context, Widget child}) {
void showDemoActionSheet({required BuildContext context, Widget? child}) {
showCupertinoModalPopup<String>(
context: context,
builder: (BuildContext context) => child,
).then((String value) {
builder: (BuildContext context) => child!,
).then((String? value) {
if (value != null) {
setState(() { lastSelectedValue = value; });
}
@@ -196,10 +196,10 @@ class _CupertinoAlertDemoState extends State<CupertinoAlertDemo> {
}
class CupertinoDessertDialog extends StatelessWidget {
const CupertinoDessertDialog({Key key, this.title, this.content}) : super(key: key);
const CupertinoDessertDialog({Key? key, this.title, this.content}) : super(key: key);
final Widget title;
final Widget content;
final Widget? title;
final Widget? content;
@override
Widget build(BuildContext context) {

View File

@@ -44,7 +44,7 @@ class CupertinoNavigationDemo extends StatelessWidget {
final List<Color> colorItems;
final List<String> colorNameItems;
final int randomSeed;
final int? randomSeed;
@override
Widget build(BuildContext context) {
@@ -71,7 +71,6 @@ class CupertinoNavigationDemo extends StatelessWidget {
],
),
tabBuilder: (BuildContext context, int index) {
assert(index >= 0 && index <= 2);
switch (index) {
case 0:
return CupertinoTabView(
@@ -84,21 +83,19 @@ class CupertinoNavigationDemo extends StatelessWidget {
},
defaultTitle: 'Colors',
);
break;
case 1:
return CupertinoTabView(
builder: (BuildContext context) => CupertinoDemoTab2(),
defaultTitle: 'Support Chat',
);
break;
case 2:
return CupertinoTabView(
builder: (BuildContext context) => CupertinoDemoTab3(),
defaultTitle: 'Account',
);
break;
}
return null;
assert(false);
return const CupertinoTabView();
},
),
),
@@ -120,7 +117,7 @@ class ExitButton extends StatelessWidget {
),
onPressed: () {
// The demo is on the root navigator.
Navigator.of(context, rootNavigator: true).pop();
Navigator.of(context, rootNavigator: true)!.pop();
},
);
}
@@ -142,9 +139,9 @@ class CupertinoDemoTab1 extends StatelessWidget {
this.randomSeed,
});
final List<Color> colorItems;
final List<String> colorNameItems;
final int randomSeed;
final List<Color>? colorItems;
final List<String>? colorNameItems;
final int? randomSeed;
@override
Widget build(BuildContext context) {
@@ -170,8 +167,8 @@ class CupertinoDemoTab1 extends StatelessWidget {
return Tab1RowItem(
index: index,
lastItem: index == _kChildCount - 1,
color: colorItems[index],
colorName: colorNameItems[index],
color: colorItems![index],
colorName: colorNameItems![index],
randomSeed: randomSeed,
);
},
@@ -194,18 +191,18 @@ class Tab1RowItem extends StatelessWidget {
this.randomSeed,
});
final int index;
final bool lastItem;
final Color color;
final String colorName;
final int randomSeed;
final int? index;
final bool? lastItem;
final Color? color;
final String? colorName;
final int? randomSeed;
@override
Widget build(BuildContext context) {
final Widget row = GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).push(CupertinoPageRoute<void>(
Navigator.of(context)!.push(CupertinoPageRoute<void>(
title: colorName,
builder: (BuildContext context) => Tab1ItemPage(
color: color,
@@ -238,7 +235,7 @@ class Tab1RowItem extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(colorName),
Text(colorName!),
const Padding(padding: EdgeInsets.only(top: 8.0)),
Text(
'Buy this cool color',
@@ -273,7 +270,7 @@ class Tab1RowItem extends StatelessWidget {
),
);
if (lastItem) {
if (lastItem!) {
return row;
}
@@ -292,10 +289,10 @@ class Tab1RowItem extends StatelessWidget {
class Tab1ItemPage extends StatefulWidget {
const Tab1ItemPage({this.color, this.colorName, this.index, this.randomSeed});
final Color color;
final String colorName;
final int index;
final int randomSeed;
final Color? color;
final String? colorName;
final int? index;
final int? randomSeed;
@override
State<StatefulWidget> createState() => Tab1ItemPageState();
@@ -309,14 +306,14 @@ class Tab1ItemPageState extends State<Tab1ItemPage> {
final math.Random random = math.Random(widget.randomSeed);
return Color.fromARGB(
255,
(widget.color.red + random.nextInt(100) - 50).clamp(0, 255) as int,
(widget.color.green + random.nextInt(100) - 50).clamp(0, 255) as int,
(widget.color.blue + random.nextInt(100) - 50).clamp(0, 255) as int,
(widget.color!.red + random.nextInt(100) - 50).clamp(0, 255),
(widget.color!.green + random.nextInt(100) - 50).clamp(0, 255),
(widget.color!.blue + random.nextInt(100) - 50).clamp(0, 255),
);
});
}
List<Color> relatedColors;
late List<Color> relatedColors;
@override
Widget build(BuildContext context) {
@@ -350,7 +347,7 @@ class Tab1ItemPageState extends State<Tab1ItemPage> {
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
widget.colorName,
widget.colorName!,
style: const TextStyle(fontSize: 24.0, fontWeight: FontWeight.bold),
),
const Padding(padding: EdgeInsets.only(top: 6.0)),
@@ -594,13 +591,13 @@ enum Tab2ConversationBubbleColor {
class Tab2ConversationBubble extends StatelessWidget {
const Tab2ConversationBubble({this.text, this.color});
final String text;
final Tab2ConversationBubbleColor color;
final String? text;
final Tab2ConversationBubbleColor? color;
@override
Widget build(BuildContext context) {
Color backgroundColor;
Color foregroundColor;
Color? backgroundColor;
Color? foregroundColor;
switch (color) {
case Tab2ConversationBubbleColor.gray:
@@ -611,6 +608,8 @@ class Tab2ConversationBubble extends StatelessWidget {
backgroundColor = CupertinoTheme.of(context).primaryColor;
foregroundColor = CupertinoColors.white;
break;
default:
break;
}
return Container(
@@ -621,7 +620,7 @@ class Tab2ConversationBubble extends StatelessWidget {
margin: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 8.0),
padding: const EdgeInsets.symmetric(horizontal: 14.0, vertical: 10.0),
child: Text(
text,
text!,
style: TextStyle(
color: foregroundColor,
letterSpacing: -0.4,
@@ -636,8 +635,8 @@ class Tab2ConversationBubble extends StatelessWidget {
class Tab2ConversationAvatar extends StatelessWidget {
const Tab2ConversationAvatar({this.text, this.color});
final String text;
final Color color;
final String? text;
final Color? color;
@override
Widget build(BuildContext context) {
@@ -648,20 +647,20 @@ class Tab2ConversationAvatar extends StatelessWidget {
begin: FractionalOffset.topCenter,
end: FractionalOffset.bottomCenter,
colors: <Color>[
color,
color!,
Color.fromARGB(
color.alpha,
(color.red - 60).clamp(0, 255) as int,
(color.green - 60).clamp(0, 255) as int,
(color.blue - 60).clamp(0, 255) as int,
color!.alpha,
(color!.red - 60).clamp(0, 255),
(color!.green - 60).clamp(0, 255),
(color!.blue - 60).clamp(0, 255),
),
],
]
),
),
margin: const EdgeInsets.only(left: 8.0, bottom: 8.0),
padding: const EdgeInsets.all(12.0),
child: Text(
text,
text!,
style: const TextStyle(
color: CupertinoColors.white,
fontSize: 13.0,
@@ -675,8 +674,8 @@ class Tab2ConversationAvatar extends StatelessWidget {
class Tab2ConversationRow extends StatelessWidget {
const Tab2ConversationRow({this.avatar, this.text});
final Tab2ConversationAvatar avatar;
final String text;
final Tab2ConversationAvatar? avatar;
final String? text;
@override
Widget build(BuildContext context) {
@@ -687,7 +686,8 @@ class Tab2ConversationRow extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: isSelf ? CrossAxisAlignment.center : CrossAxisAlignment.end,
children: <Widget>[
if (avatar != null) avatar,
if (avatar != null)
avatar!,
CupertinoUserInterfaceLevel(
data: CupertinoUserInterfaceLevelData.elevated,
child: Tab2ConversationBubble(
@@ -752,7 +752,7 @@ class CupertinoDemoTab3 extends StatelessWidget {
const Padding(padding: EdgeInsets.only(top: 32.0)),
GestureDetector(
onTap: () {
Navigator.of(context, rootNavigator: true).push(
Navigator.of(context, rootNavigator: true)!.push(
CupertinoPageRoute<bool>(
fullscreenDialog: true,
builder: (BuildContext context) => Tab3Dialog(),
@@ -800,7 +800,7 @@ class Tab3Dialog extends StatelessWidget {
child: const Text('Cancel'),
padding: EdgeInsets.zero,
onPressed: () {
Navigator.of(context).pop(false);
Navigator.of(context)!.pop(false);
},
),
),

View File

@@ -20,10 +20,9 @@ class CupertinoPickerDemo extends StatefulWidget {
class _BottomPicker extends StatelessWidget {
const _BottomPicker({
Key key,
@required this.child,
}) : assert(child != null),
super(key: key);
Key? key,
required this.child,
}) : super(key: key);
final Widget child;
@@ -53,10 +52,9 @@ class _BottomPicker extends StatelessWidget {
class _Menu extends StatelessWidget {
const _Menu({
Key key,
@required this.children,
}) : assert(children != null),
super(key: key);
Key? key,
required this.children,
}) : super(key: key);
final List<Widget> children;

View File

@@ -16,7 +16,7 @@ class CupertinoRefreshControlDemo extends StatefulWidget {
}
class _CupertinoRefreshControlDemoState extends State<CupertinoRefreshControlDemo> {
List<List<String>> randomizedContacts;
late List<List<String>> randomizedContacts;
@override
void initState() {
@@ -64,7 +64,7 @@ class _CupertinoRefreshControlDemoState extends State<CupertinoRefreshControlDem
CupertinoSliverRefreshControl(
onRefresh: () {
return Future<void>.delayed(const Duration(seconds: 2))
..then<void>((_) {
..then((_) {
if (mounted) {
setState(() => repopulateList());
}
@@ -149,10 +149,10 @@ class _ListItem extends StatelessWidget {
this.called,
});
final String name;
final String place;
final String date;
final bool called;
final String? name;
final String? place;
final String? date;
final bool? called;
@override
Widget build(BuildContext context) {
@@ -164,7 +164,7 @@ class _ListItem extends StatelessWidget {
children: <Widget>[
Container(
width: 38.0,
child: called
child: called!
? Align(
alignment: Alignment.topCenter,
child: Icon(
@@ -191,7 +191,7 @@ class _ListItem extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
name,
name!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
@@ -200,7 +200,7 @@ class _ListItem extends StatelessWidget {
),
),
Text(
place,
place!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
@@ -213,7 +213,7 @@ class _ListItem extends StatelessWidget {
),
),
Text(
date,
date!,
style: TextStyle(
color: CupertinoColors.inactiveGray.resolveFrom(context),
fontSize: 15.0,

View File

@@ -43,9 +43,9 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro
),
};
int currentSegment = 0;
int? currentSegment = 0;
void onValueChanged(int newValue) {
void onValueChanged(int? newValue) {
setState(() {
currentSegment = newValue;
});
@@ -126,7 +126,7 @@ class _CupertinoSegmentedControlDemoState extends State<CupertinoSegmentedContro
),
],
),
child: icons[currentSegment],
child: icons[currentSegment!],
);
},
),

View File

@@ -14,8 +14,8 @@ class CupertinoTextFieldDemo extends StatefulWidget {
}
class _CupertinoTextFieldDemoState extends State<CupertinoTextFieldDemo> {
TextEditingController _chatTextController;
TextEditingController _locationTextController;
TextEditingController? _chatTextController;
TextEditingController? _locationTextController;
@override
void initState() {
@@ -49,12 +49,12 @@ class _CupertinoTextFieldDemoState extends State<CupertinoTextFieldDemo> {
color: CupertinoColors.activeGreen,
),
padding: const EdgeInsets.only(bottom: 4),
onPressed: ()=> setState(()=> _chatTextController.clear()),
onPressed: ()=> setState(()=> _chatTextController!.clear()),
),
),
autofocus: true,
suffixMode: OverlayVisibilityMode.editing,
onSubmitted: (String text)=> setState(()=> _chatTextController.clear()),
onSubmitted: (String text)=> setState(()=> _chatTextController!.clear()),
);
}

View File

@@ -33,7 +33,7 @@ class FortnightlyDemo extends StatelessWidget {
class ShortAppBar extends StatelessWidget {
const ShortAppBar({ this.onBackPressed });
final VoidCallback onBackPressed;
final VoidCallback? onBackPressed;
@override
Widget build(BuildContext context) {
@@ -118,7 +118,7 @@ over water meant for the whole central valley of California? The story will shoc
Text(
' ¬ ',
// TODO(larche): Replace textTheme.headline2.color with a ColorScheme value when known.
style: textTheme.overline.apply(color: textTheme.headline2.color),
style: textTheme.overline!.apply(color: textTheme.headline2!.color),
),
Text(
'CULTURE',
@@ -196,7 +196,7 @@ TextTheme _buildTextTheme(TextTheme base) {
theme = theme.apply(displayColor: Colors.black);
theme = theme.copyWith(
headline4: base.headline4.copyWith(
headline4: base.headline4!.copyWith(
fontFamily: 'Merriweather',
fontStyle: FontStyle.italic,
fontSize: 28,
@@ -204,21 +204,21 @@ TextTheme _buildTextTheme(TextTheme base) {
color: Colors.black,
height: .88,
),
headline2: base.headline2.copyWith(
headline2: base.headline2!.copyWith(
fontFamily: 'LibreFranklin',
fontSize: 18,
fontWeight: FontWeight.w500,
color: Colors.black.withAlpha(153),
),
headline5: base.headline5.copyWith(fontWeight: FontWeight.w500),
bodyText2: base.bodyText2.copyWith(
headline5: base.headline5!.copyWith(fontWeight: FontWeight.w500),
bodyText2: base.bodyText2!.copyWith(
fontFamily: 'Merriweather',
fontSize: 14,
fontWeight: FontWeight.w300,
color: const Color(0xFF666666),
height: 1.11,
),
bodyText1: base.bodyText1.copyWith(
bodyText1: base.bodyText1!.copyWith(
fontFamily: 'Merriweather',
fontSize: 16,
fontWeight: FontWeight.w300,

View File

@@ -12,8 +12,8 @@ import 'package:flutter/material.dart';
class Category {
const Category({ this.title, this.assets });
final String title;
final List<String> assets;
final String? title;
final List<String>? assets;
@override
String toString() => '$runtimeType("$title")';
}
@@ -95,21 +95,21 @@ const List<Category> allCategories = <Category>[
];
class CategoryView extends StatelessWidget {
const CategoryView({ Key key, this.category }) : super(key: key);
const CategoryView({ Key? key, this.category }) : super(key: key);
final Category category;
final Category? category;
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
return Scrollbar(
child: ListView(
key: PageStorageKey<Category>(category),
key: PageStorageKey<Category?>(category),
padding: const EdgeInsets.symmetric(
vertical: 16.0,
horizontal: 64.0,
),
children: category.assets.map<Widget>((String asset) {
children: category!.assets!.map<Widget>((String asset) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
@@ -149,7 +149,7 @@ class CategoryView extends StatelessWidget {
// BackdropDemo.
class BackdropPanel extends StatelessWidget {
const BackdropPanel({
Key key,
Key? key,
this.onTap,
this.onVerticalDragUpdate,
this.onVerticalDragEnd,
@@ -157,11 +157,11 @@ class BackdropPanel extends StatelessWidget {
this.child,
}) : super(key: key);
final VoidCallback onTap;
final GestureDragUpdateCallback onVerticalDragUpdate;
final GestureDragEndCallback onVerticalDragEnd;
final Widget title;
final Widget child;
final VoidCallback? onTap;
final GestureDragUpdateCallback? onVerticalDragUpdate;
final GestureDragEndCallback? onVerticalDragEnd;
final Widget? title;
final Widget? child;
@override
Widget build(BuildContext context) {
@@ -185,7 +185,7 @@ class BackdropPanel extends StatelessWidget {
padding: const EdgeInsetsDirectional.only(start: 16.0),
alignment: AlignmentDirectional.centerStart,
child: DefaultTextStyle(
style: theme.textTheme.subtitle1,
style: theme.textTheme.subtitle1!,
child: Tooltip(
message: 'Tap to dismiss',
child: title,
@@ -194,7 +194,7 @@ class BackdropPanel extends StatelessWidget {
),
),
const Divider(height: 1.0),
Expanded(child: child),
Expanded(child: child!),
],
),
);
@@ -204,15 +204,15 @@ class BackdropPanel extends StatelessWidget {
// Cross fades between 'Select a Category' and 'Asset Viewer'.
class BackdropTitle extends AnimatedWidget {
const BackdropTitle({
Key key,
Animation<double> listenable,
Key? key,
required Animation<double> listenable,
}) : super(key: key, listenable: listenable);
@override
Widget build(BuildContext context) {
final Animation<double> animation = listenable as Animation<double>;
return DefaultTextStyle(
style: Theme.of(context).primaryTextTheme.headline6,
style: Theme.of(context).primaryTextTheme.headline6!,
softWrap: false,
overflow: TextOverflow.ellipsis,
child: Stack(
@@ -247,7 +247,7 @@ class BackdropDemo extends StatefulWidget {
class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderStateMixin {
final GlobalKey _backdropKey = GlobalKey(debugLabel: 'Backdrop');
AnimationController _controller;
late AnimationController _controller;
Category _category = allCategories[0];
@override
@@ -283,7 +283,7 @@ class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderSt
}
double get _backdropHeight {
final RenderBox renderBox = _backdropKey.currentContext.findRenderObject() as RenderBox;
final RenderBox renderBox = _backdropKey.currentContext!.findRenderObject()! as RenderBox;
return renderBox.size.height;
}
@@ -294,7 +294,7 @@ class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderSt
if (_controller.isAnimating || _controller.status == AnimationStatus.completed)
return;
_controller.value -= details.primaryDelta / (_backdropHeight ?? details.primaryDelta);
_controller.value -= details.primaryDelta! / _backdropHeight;
}
void _handleDragEnd(DragEndDetails details) {
@@ -343,7 +343,7 @@ class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderSt
? Colors.white.withOpacity(0.25)
: Colors.transparent,
child: ListTile(
title: Text(category.title),
title: Text(category.title!),
selected: selected,
onTap: () {
_changeCategory(category);
@@ -359,8 +359,8 @@ class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderSt
children: <Widget>[
ListTileTheme(
iconColor: theme.primaryIconTheme.color,
textColor: theme.primaryTextTheme.headline6.color.withOpacity(0.6),
selectedColor: theme.primaryTextTheme.headline6.color,
textColor: theme.primaryTextTheme.headline6!.color!.withOpacity(0.6),
selectedColor: theme.primaryTextTheme.headline6!.color,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
@@ -375,7 +375,7 @@ class _BackdropDemoState extends State<BackdropDemo> with SingleTickerProviderSt
onTap: _toggleBackdropPanelVisibility,
onVerticalDragUpdate: _handleDragUpdate,
onVerticalDragEnd: _handleDragEnd,
title: Text(_category.title),
title: Text(_category.title!),
child: CategoryView(category: _category),
),
),

View File

@@ -13,7 +13,7 @@ enum BannerDemoAction {
}
class BannerDemo extends StatefulWidget {
const BannerDemo({ Key key }) : super(key: key);
const BannerDemo({ Key? key }) : super(key: key);
static const String routeName = '/material/banner';

View File

@@ -92,7 +92,7 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
"When the Scaffold's floating action button location changes, "
'the floating action button animates to its new position. '
'The BottomAppBar adapts its shape appropriately.';
_scaffoldMessengerKey.currentState.showSnackBar(
_scaffoldMessengerKey.currentState!.showSnackBar(
const SnackBar(content: Text(text)),
);
}
@@ -111,27 +111,27 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
_ChoiceValue<Widget> _fabShape = kCircularFab;
_ChoiceValue<bool> _showNotch = kShowNotchTrue;
_ChoiceValue<FloatingActionButtonLocation> _fabLocation = kFabEndDocked;
Color _babColor = kBabColors.first.color;
Color? _babColor = kBabColors.first.color;
void _onShowNotchChanged(_ChoiceValue<bool> value) {
void _onShowNotchChanged(_ChoiceValue<bool>? value) {
setState(() {
_showNotch = value;
_showNotch = value!;
});
}
void _onFabShapeChanged(_ChoiceValue<Widget> value) {
void _onFabShapeChanged(_ChoiceValue<Widget>? value) {
setState(() {
_fabShape = value;
_fabShape = value!;
});
}
void _onFabLocationChanged(_ChoiceValue<FloatingActionButtonLocation> value) {
void _onFabLocationChanged(_ChoiceValue<FloatingActionButtonLocation>? value) {
setState(() {
_fabLocation = value;
_fabLocation = value!;
});
}
void _onBabColorChanged(Color value) {
void _onBabColorChanged(Color? value) {
setState(() {
_babColor = value;
});
@@ -201,8 +201,8 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
);
}
NotchedShape _selectNotch() {
if (!_showNotch.value)
NotchedShape? _selectNotch() {
if (!_showNotch.value!)
return null;
if (_fabShape == kCircularFab)
return const CircularNotchedRectangle();
@@ -215,9 +215,9 @@ class _BottomAppBarDemoState extends State<BottomAppBarDemo> {
class _ChoiceValue<T> {
const _ChoiceValue({ this.value, this.title, this.label });
final T value;
final String title;
final String label; // For the Semantics widget that contains title
final T? value;
final String? title;
final String? label; // For the Semantics widget that contains title
@override
String toString() => '$runtimeType("$title")';
@@ -228,7 +228,7 @@ class _RadioItem<T> extends StatelessWidget {
final _ChoiceValue<T> value;
final _ChoiceValue<T> groupValue;
final ValueChanged<_ChoiceValue<T>> onChanged;
final ValueChanged<_ChoiceValue<T>?> onChanged;
@override
Widget build(BuildContext context) {
@@ -256,7 +256,7 @@ class _RadioItem<T> extends StatelessWidget {
onChanged(value);
},
child: Text(
value.title,
value.title!,
style: theme.textTheme.subtitle1,
),
),
@@ -272,7 +272,7 @@ class _RadioItem<T> extends StatelessWidget {
class _NamedColor {
const _NamedColor(this.color, this.name);
final Color color;
final Color? color;
final String name;
}
@@ -280,8 +280,8 @@ class _ColorsItem extends StatelessWidget {
const _ColorsItem(this.colors, this.selectedColor, this.onChanged);
final List<_NamedColor> colors;
final Color selectedColor;
final ValueChanged<Color> onChanged;
final Color? selectedColor;
final ValueChanged<Color?> onChanged;
@override
Widget build(BuildContext context) {
@@ -340,9 +340,9 @@ class _DemoBottomAppBar extends StatelessWidget {
this.shape,
});
final Color color;
final FloatingActionButtonLocation fabLocation;
final NotchedShape shape;
final Color? color;
final FloatingActionButtonLocation? fabLocation;
final NotchedShape? shape;
static final List<FloatingActionButtonLocation> kCenterLocations = <FloatingActionButtonLocation>[
FloatingActionButtonLocation.centerDocked,
@@ -421,8 +421,8 @@ class _DiamondFab extends StatelessWidget {
this.onPressed,
});
final Widget child;
final VoidCallback onPressed;
final Widget? child;
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) {
@@ -436,7 +436,7 @@ class _DiamondFab extends StatelessWidget {
height: 56.0,
child: IconTheme.merge(
data: IconThemeData(color: Theme.of(context).accentIconTheme.color),
child: child,
child: child!,
),
),
),
@@ -449,8 +449,8 @@ class _DiamondNotchedRectangle implements NotchedShape {
const _DiamondNotchedRectangle();
@override
Path getOuterPath(Rect host, Rect guest) {
if (!host.overlaps(guest))
Path getOuterPath(Rect host, Rect? guest) {
if (!host.overlaps(guest!))
return Path()..addRect(host);
assert(guest.width > 0.0);
@@ -492,12 +492,12 @@ class _DiamondBorder extends ShapeBorder {
}
@override
Path getInnerPath(Rect rect, { TextDirection textDirection }) {
Path getInnerPath(Rect rect, { TextDirection? textDirection }) {
return getOuterPath(rect, textDirection: textDirection);
}
@override
Path getOuterPath(Rect rect, { TextDirection textDirection }) {
Path getOuterPath(Rect rect, { TextDirection? textDirection }) {
return Path()
..moveTo(rect.left + rect.width / 2.0, rect.top)
..lineTo(rect.right, rect.top + rect.height / 2.0)
@@ -507,11 +507,11 @@ class _DiamondBorder extends ShapeBorder {
}
@override
void paint(Canvas canvas, Rect rect, { TextDirection textDirection }) { }
void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) { }
// This border doesn't support scaling.
@override
ShapeBorder scale(double t) {
return null;
return this;
}
}

View File

@@ -8,11 +8,11 @@ import '../../gallery/demo.dart';
class NavigationIconView {
NavigationIconView({
Widget icon,
Widget activeIcon,
String title,
Color color,
TickerProvider vsync,
required Widget icon,
Widget? activeIcon,
String? title,
Color? color,
required TickerProvider vsync,
}) : _icon = icon,
_color = color,
_title = title,
@@ -32,14 +32,14 @@ class NavigationIconView {
}
final Widget _icon;
final Color _color;
final String _title;
final Color? _color;
final String? _title;
final BottomNavigationBarItem item;
final AnimationController controller;
Animation<double> _animation;
late Animation<double> _animation;
FadeTransition transition(BottomNavigationBarType type, BuildContext context) {
Color iconColor;
Color? iconColor;
if (type == BottomNavigationBarType.shifting) {
iconColor = _color;
} else {
@@ -79,8 +79,8 @@ class CustomIcon extends StatelessWidget {
final IconThemeData iconTheme = IconTheme.of(context);
return Container(
margin: const EdgeInsets.all(4.0),
width: iconTheme.size - 8.0,
height: iconTheme.size - 8.0,
width: iconTheme.size! - 8.0,
height: iconTheme.size! - 8.0,
color: iconTheme.color,
);
}
@@ -92,10 +92,10 @@ class CustomInactiveIcon extends StatelessWidget {
final IconThemeData iconTheme = IconTheme.of(context);
return Container(
margin: const EdgeInsets.all(4.0),
width: iconTheme.size - 8.0,
height: iconTheme.size - 8.0,
width: iconTheme.size! - 8.0,
height: iconTheme.size! - 8.0,
decoration: BoxDecoration(
border: Border.all(color: iconTheme.color, width: 2.0),
border: Border.all(color: iconTheme.color!, width: 2.0),
),
);
}
@@ -112,7 +112,7 @@ class _BottomNavigationDemoState extends State<BottomNavigationDemo>
with TickerProviderStateMixin {
int _currentIndex = 0;
BottomNavigationBarType _type = BottomNavigationBarType.shifting;
List<NavigationIconView> _navigationViews;
late List<NavigationIconView> _navigationViews;
@override
void initState() {

View File

@@ -53,7 +53,7 @@ class ButtonsDemo extends StatefulWidget {
}
class _ButtonsDemoState extends State<ButtonsDemo> {
OutlinedBorder _buttonShape;
OutlinedBorder? _buttonShape;
@override
Widget build(BuildContext context) {
@@ -118,7 +118,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
);
}
Widget buildElevatedButton(OutlinedBorder shape) {
Widget buildElevatedButton(OutlinedBorder? shape) {
final ButtonStyle style = ElevatedButton.styleFrom(shape: shape);
return Align(
alignment: const Alignment(0.0, -0.2),
@@ -156,7 +156,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
style: style,
icon: const Icon(Icons.add, size: 18.0),
label: const Text('DISABLED', semanticsLabel: 'DISABLED BUTTON 2'),
onPressed: null,
onPressed: () {},
),
],
),
@@ -165,7 +165,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
);
}
Widget buildTextButton(OutlinedBorder shape) {
Widget buildTextButton(OutlinedBorder? shape) {
final ButtonStyle style = ElevatedButton.styleFrom(shape: shape);
return Align(
alignment: const Alignment(0.0, -0.2),
@@ -203,7 +203,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
style: style,
icon: const Icon(Icons.add_circle_outline, size: 18.0),
label: const Text('DISABLED', semanticsLabel: 'DISABLED BUTTON 4'),
onPressed: null,
onPressed: () {},
),
],
),
@@ -212,7 +212,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
);
}
Widget buildOutlinedButton(OutlinedBorder shape) {
Widget buildOutlinedButton(OutlinedBorder? shape) {
final ButtonStyle style = ElevatedButton.styleFrom(shape: shape);
return Align(
alignment: const Alignment(0.0, -0.2),
@@ -260,9 +260,9 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
}
// https://en.wikipedia.org/wiki/Free_Four
String dropdown1Value = 'Free';
String dropdown2Value;
String dropdown3Value = 'Four';
String? dropdown1Value = 'Free';
String? dropdown2Value;
String? dropdown3Value = 'Four';
Widget buildDropdownButton() {
return Padding(
@@ -274,7 +274,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
title: const Text('Simple dropdown:'),
trailing: DropdownButton<String>(
value: dropdown1Value,
onChanged: (String newValue) {
onChanged: (String? newValue) {
setState(() {
dropdown1Value = newValue;
});
@@ -295,7 +295,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
trailing: DropdownButton<String>(
value: dropdown2Value,
hint: const Text('Choose'),
onChanged: (String newValue) {
onChanged: (String? newValue) {
setState(() {
dropdown2Value = newValue;
});
@@ -315,7 +315,7 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
title: const Text('Scrollable dropdown:'),
trailing: DropdownButton<String>(
value: dropdown3Value,
onChanged: (String newValue) {
onChanged: (String? newValue) {
setState(() {
dropdown3Value = newValue;
});

View File

@@ -17,19 +17,14 @@ enum CardDemoType {
class TravelDestination {
const TravelDestination({
@required this.assetName,
@required this.assetPackage,
@required this.title,
@required this.description,
@required this.city,
@required this.location,
required this.assetName,
required this.assetPackage,
required this.title,
required this.description,
required this.city,
required this.location,
this.type = CardDemoType.standard,
}) : assert(assetName != null),
assert(assetPackage != null),
assert(title != null),
assert(description != null),
assert(city != null),
assert(location != null);
});
final String assetName;
final String assetPackage;
@@ -70,14 +65,13 @@ const List<TravelDestination> destinations = <TravelDestination>[
];
class TravelDestinationItem extends StatelessWidget {
const TravelDestinationItem({ Key key, @required this.destination, this.shape })
: assert(destination != null),
super(key: key);
const TravelDestinationItem({ Key? key, required this.destination, this.shape })
: super(key: key);
// This height will allow for all the Card's content to fit comfortably within the card.
static const double height = 338.0;
final TravelDestination destination;
final ShapeBorder shape;
final ShapeBorder? shape;
@override
Widget build(BuildContext context) {
@@ -106,14 +100,13 @@ class TravelDestinationItem extends StatelessWidget {
}
class TappableTravelDestinationItem extends StatelessWidget {
const TappableTravelDestinationItem({ Key key, @required this.destination, this.shape })
: assert(destination != null),
super(key: key);
const TappableTravelDestinationItem({ Key? key, required this.destination, this.shape })
: super(key: key);
// This height will allow for all the Card's content to fit comfortably within the card.
static const double height = 298.0;
final TravelDestination destination;
final ShapeBorder shape;
final ShapeBorder? shape;
@override
Widget build(BuildContext context) {
@@ -151,12 +144,11 @@ class TappableTravelDestinationItem extends StatelessWidget {
}
class SelectableTravelDestinationItem extends StatefulWidget {
const SelectableTravelDestinationItem({ Key key, @required this.destination, this.shape })
: assert(destination != null),
super(key: key);
const SelectableTravelDestinationItem({ Key? key, required this.destination, this.shape })
: super(key: key);
final TravelDestination destination;
final ShapeBorder shape;
final ShapeBorder? shape;
@override
_SelectableTravelDestinationItemState createState() => _SelectableTravelDestinationItemState();
@@ -231,11 +223,11 @@ class _SelectableTravelDestinationItemState extends State<SelectableTravelDestin
class SectionTitle extends StatelessWidget {
const SectionTitle({
Key key,
Key? key,
this.title,
}) : super(key: key);
final String title;
final String? title;
@override
Widget build(BuildContext context) {
@@ -243,24 +235,23 @@ class SectionTitle extends StatelessWidget {
padding: const EdgeInsets.fromLTRB(4.0, 4.0, 4.0, 12.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(title, style: Theme.of(context).textTheme.subtitle1),
child: Text(title!, style: Theme.of(context).textTheme.subtitle1),
),
);
}
}
class TravelDestinationContent extends StatelessWidget {
const TravelDestinationContent({ Key key, @required this.destination })
: assert(destination != null),
super(key: key);
const TravelDestinationContent({ Key? key, required this.destination })
: super(key: key);
final TravelDestination destination;
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final TextStyle titleStyle = theme.textTheme.headline5.copyWith(color: Colors.white);
final TextStyle descriptionStyle = theme.textTheme.subtitle1;
final TextStyle titleStyle = theme.textTheme.headline5!.copyWith(color: Colors.white);
final TextStyle descriptionStyle = theme.textTheme.subtitle1!;
final ButtonStyle textButtonStyle = TextButton.styleFrom(primary: Colors.amber.shade500);
return Column(
@@ -352,7 +343,7 @@ class CardsDemo extends StatefulWidget {
}
class _CardsDemoState extends State<CardsDemo> {
ShapeBorder _shape;
ShapeBorder? _shape;
@override
Widget build(BuildContext context) {
@@ -385,7 +376,7 @@ class _CardsDemoState extends State<CardsDemo> {
child: ListView(
padding: const EdgeInsets.only(top: 8.0, left: 8.0, right: 8.0),
children: destinations.map<Widget>((TravelDestination destination) {
Widget child;
Widget? child;
switch (destination.type) {
case CardDemoType.standard:
child = TravelDestinationItem(destination: destination, shape: _shape);

View File

@@ -88,13 +88,13 @@ const Map<String, Set<String>> _materialActions = <String, Set<String>>{
class _ChipsTile extends StatelessWidget {
const _ChipsTile({
Key key,
Key? key,
this.label,
this.children,
}) : super(key: key);
final String label;
final List<Widget> children;
final String? label;
final List<Widget>? children;
// Wraps a list of chips into a ListTile for display as a section in the demo.
@override
@@ -107,11 +107,11 @@ class _ChipsTile extends StatelessWidget {
Container(
padding: const EdgeInsets.only(top: 16.0, bottom: 4.0),
alignment: Alignment.center,
child: Text(label, textAlign: TextAlign.start),
child: Text(label!, textAlign: TextAlign.start),
),
if (children.isNotEmpty)
if (children!.isNotEmpty)
Wrap(
children: children.map<Widget>((Widget chip) {
children: children!.map<Widget>((Widget chip) {
return Padding(
padding: const EdgeInsets.all(2.0),
child: chip,
@@ -125,7 +125,7 @@ class _ChipsTile extends StatelessWidget {
alignment: Alignment.center,
constraints: const BoxConstraints(minWidth: 48.0, minHeight: 48.0),
padding: const EdgeInsets.all(8.0),
child: Text('None', style: Theme.of(context).textTheme.caption.copyWith(fontStyle: FontStyle.italic)),
child: Text('None', style: Theme.of(context).textTheme.caption!.copyWith(fontStyle: FontStyle.italic)),
),
),
],
@@ -188,7 +188,7 @@ class _ChipDemoState extends State<ChipDemo> {
}
String _capitalize(String name) {
assert(name != null && name.isNotEmpty);
assert(name.isNotEmpty);
return name.substring(0, 1).toUpperCase() + name.substring(1);
}
@@ -209,7 +209,7 @@ class _ChipDemoState extends State<ChipDemo> {
AssetImage _nameToAvatar(String name) {
assert(_avatars.containsKey(name));
return AssetImage(
_avatars[name],
_avatars[name]!,
package: 'flutter_gallery_assets',
);
}
@@ -218,7 +218,7 @@ class _ChipDemoState extends State<ChipDemo> {
if (_selectedAction.isEmpty) {
return '';
}
return _capitalize(_results[_selectedAction]) + '!';
return _capitalize(_results[_selectedAction]!) + '!';
}
@override
@@ -285,11 +285,11 @@ class _ChipDemoState extends State<ChipDemo> {
}).toList();
Set<String> allowedActions = <String>{};
if (_selectedMaterial != null && _selectedMaterial.isNotEmpty) {
if (_selectedMaterial.isNotEmpty) {
for (final String tool in _selectedTools) {
allowedActions.addAll(_toolActions[tool]);
allowedActions.addAll(_toolActions[tool]!);
}
allowedActions = allowedActions.intersection(_materialActions[_selectedMaterial]);
allowedActions = allowedActions.intersection(_materialActions[_selectedMaterial]!);
}
final List<Widget> actionChips = allowedActions.map<Widget>((String name) {

View File

@@ -18,7 +18,7 @@ class Dessert {
final int calcium;
final int iron;
bool selected = false;
bool? selected = false;
}
class DessertDataSource extends DataTableSource {
@@ -96,17 +96,17 @@ class DessertDataSource extends DataTableSource {
int _selectedCount = 0;
@override
DataRow getRow(int index) {
DataRow? getRow(int index) {
assert(index >= 0);
if (index >= _desserts.length)
return null;
final Dessert dessert = _desserts[index];
return DataRow.byIndex(
index: index,
selected: dessert.selected,
onSelectChanged: (bool value) {
selected: dessert.selected!,
onSelectChanged: (bool? value) {
if (dessert.selected != value) {
_selectedCount += value ? 1 : -1;
_selectedCount += value! ? 1 : -1;
assert(_selectedCount >= 0);
dessert.selected = value;
notifyListeners();
@@ -134,10 +134,10 @@ class DessertDataSource extends DataTableSource {
@override
int get selectedRowCount => _selectedCount;
void _selectAll(bool checked) {
void _selectAll(bool? checked) {
for (final Dessert dessert in _desserts)
dessert.selected = checked;
_selectedCount = checked ? _desserts.length : 0;
_selectedCount = checked! ? _desserts.length : 0;
notifyListeners();
}
}
@@ -150,8 +150,8 @@ class DataTableDemo extends StatefulWidget {
}
class _DataTableDemoState extends State<DataTableDemo> {
int _rowsPerPage = PaginatedDataTable.defaultRowsPerPage;
int _sortColumnIndex;
int? _rowsPerPage = PaginatedDataTable.defaultRowsPerPage;
int? _sortColumnIndex;
bool _sortAscending = true;
final DessertDataSource _dessertsDataSource = DessertDataSource();
@@ -178,8 +178,8 @@ class _DataTableDemoState extends State<DataTableDemo> {
children: <Widget>[
PaginatedDataTable(
header: const Text('Nutrition'),
rowsPerPage: _rowsPerPage,
onRowsPerPageChanged: (int value) { setState(() { _rowsPerPage = value; }); },
rowsPerPage: _rowsPerPage!,
onRowsPerPageChanged: (int? value) { setState(() { _rowsPerPage = value; }); },
sortColumnIndex: _sortColumnIndex,
sortAscending: _sortAscending,
onSelectAll: _dessertsDataSource._selectAll,

View File

@@ -9,7 +9,7 @@ import '../../gallery/demo.dart';
class _InputDropdown extends StatelessWidget {
const _InputDropdown({
Key key,
Key? key,
this.child,
this.labelText,
this.valueText,
@@ -17,11 +17,11 @@ class _InputDropdown extends StatelessWidget {
this.onPressed,
}) : super(key: key);
final String labelText;
final String valueText;
final TextStyle valueStyle;
final VoidCallback onPressed;
final Widget child;
final String? labelText;
final String? valueText;
final TextStyle? valueStyle;
final VoidCallback? onPressed;
final Widget? child;
@override
Widget build(BuildContext context) {
@@ -36,7 +36,7 @@ class _InputDropdown extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(valueText, style: valueStyle),
Text(valueText!, style: valueStyle),
Icon(Icons.arrow_drop_down,
color: Theme.of(context).brightness == Brightness.light ? Colors.grey.shade700 : Colors.white70,
),
@@ -49,7 +49,7 @@ class _InputDropdown extends StatelessWidget {
class _DateTimePicker extends StatelessWidget {
const _DateTimePicker({
Key key,
Key? key,
this.labelText,
this.selectedDate,
this.selectedTime,
@@ -57,35 +57,35 @@ class _DateTimePicker extends StatelessWidget {
this.selectTime,
}) : super(key: key);
final String labelText;
final DateTime selectedDate;
final TimeOfDay selectedTime;
final ValueChanged<DateTime> selectDate;
final ValueChanged<TimeOfDay> selectTime;
final String? labelText;
final DateTime? selectedDate;
final TimeOfDay? selectedTime;
final ValueChanged<DateTime>? selectDate;
final ValueChanged<TimeOfDay>? selectTime;
Future<void> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
final DateTime? picked = await showDatePicker(
context: context,
initialDate: selectedDate,
initialDate: selectedDate!,
firstDate: DateTime(2015, 8),
lastDate: DateTime(2101),
);
if (picked != null && picked != selectedDate)
selectDate(picked);
selectDate!(picked);
}
Future<void> _selectTime(BuildContext context) async {
final TimeOfDay picked = await showTimePicker(
final TimeOfDay? picked = await showTimePicker(
context: context,
initialTime: selectedTime,
initialTime: selectedTime!,
);
if (picked != null && picked != selectedTime)
selectTime(picked);
selectTime!(picked);
}
@override
Widget build(BuildContext context) {
final TextStyle valueStyle = Theme.of(context).textTheme.headline6;
final TextStyle? valueStyle = Theme.of(context).textTheme.headline6;
return Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
@@ -93,7 +93,7 @@ class _DateTimePicker extends StatelessWidget {
flex: 4,
child: _InputDropdown(
labelText: labelText,
valueText: DateFormat.yMMMd().format(selectedDate),
valueText: DateFormat.yMMMd().format(selectedDate!),
valueStyle: valueStyle,
onPressed: () { _selectDate(context); },
),
@@ -102,7 +102,7 @@ class _DateTimePicker extends StatelessWidget {
Expanded(
flex: 3,
child: _InputDropdown(
valueText: selectedTime.format(context),
valueText: selectedTime!.format(context),
valueStyle: valueStyle,
onPressed: () { _selectTime(context); },
),
@@ -125,7 +125,7 @@ class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> {
DateTime _toDate = DateTime.now();
TimeOfDay _toTime = const TimeOfDay(hour: 8, minute: 28);
final List<String> _allActivities = <String>['hiking', 'swimming', 'boating', 'fishing'];
String _activity = 'fishing';
String? _activity = 'fishing';
@override
Widget build(BuildContext context) {
@@ -153,7 +153,7 @@ class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> {
decoration: const InputDecoration(
labelText: 'Location',
),
style: Theme.of(context).textTheme.headline4.copyWith(fontSize: 20.0),
style: Theme.of(context).textTheme.headline4!.copyWith(fontSize: 20.0),
),
_DateTimePicker(
labelText: 'From',
@@ -195,7 +195,7 @@ class _DateAndTimePickerDemoState extends State<DateAndTimePickerDemo> {
isEmpty: _activity == null,
child: DropdownButton<String>(
value: _activity,
onChanged: (String newValue) {
onChanged: (String? newValue) {
setState(() {
_activity = newValue;
});

View File

@@ -21,12 +21,12 @@ const String _alertWithTitleText =
'data to Google, even when no apps are running.';
class DialogDemoItem extends StatelessWidget {
const DialogDemoItem({ Key key, this.icon, this.color, this.text, this.onPressed }) : super(key: key);
const DialogDemoItem({ Key? key, this.icon, this.color, this.text, this.onPressed }) : super(key: key);
final IconData icon;
final Color color;
final String text;
final VoidCallback onPressed;
final IconData? icon;
final Color? color;
final String? text;
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) {
@@ -39,7 +39,7 @@ class DialogDemoItem extends StatelessWidget {
Icon(icon, size: 36.0, color: color),
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: Text(text),
child: Text(text!),
),
],
),
@@ -56,7 +56,7 @@ class DialogDemo extends StatefulWidget {
class DialogDemoState extends State<DialogDemo> {
TimeOfDay _selectedTime;
TimeOfDay? _selectedTime;
@override
void initState() {
@@ -65,12 +65,12 @@ class DialogDemoState extends State<DialogDemo> {
_selectedTime = TimeOfDay(hour: now.hour, minute: now.minute);
}
void showDemoDialog<T>({ BuildContext context, Widget child }) {
void showDemoDialog<T>({ required BuildContext context, Widget? child }) {
showDialog<T>(
context: context,
builder: (BuildContext context) => child,
builder: (BuildContext context) => child!,
)
.then<void>((T value) { // The value passed to Navigator.pop() or null.
.then((T? value) { // The value passed to Navigator.pop() or null.
if (value != null) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('You selected: $value'),
@@ -82,7 +82,7 @@ class DialogDemoState extends State<DialogDemo> {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final TextStyle dialogTextStyle = theme.textTheme.subtitle1.copyWith(color: theme.textTheme.caption.color);
final TextStyle dialogTextStyle = theme.textTheme.subtitle1!.copyWith(color: theme.textTheme.caption!.color);
return Scaffold(
appBar: AppBar(
@@ -176,9 +176,9 @@ class DialogDemoState extends State<DialogDemo> {
onPressed: () {
showTimePicker(
context: context,
initialTime: _selectedTime,
initialTime: _selectedTime!,
)
.then<void>((TimeOfDay value) {
.then((TimeOfDay? value) {
if (value != null && value != _selectedTime) {
_selectedTime = value;
ScaffoldMessenger.of(context).showSnackBar(SnackBar(

View File

@@ -33,9 +33,9 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
curve: Curves.fastOutSlowIn,
));
AnimationController _controller;
Animation<double> _drawerContentsOpacity;
Animation<Offset> _drawerDetailsPosition;
late AnimationController _controller;
late Animation<double> _drawerContentsOpacity;
late Animation<Offset> _drawerDetailsPosition;
bool _showDrawerContents = true;
@override
@@ -58,7 +58,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
super.dispose();
}
IconData _backIcon() {
IconData? _backIcon() {
switch (Theme.of(context).platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
@@ -69,8 +69,6 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
case TargetPlatform.macOS:
return Icons.arrow_back_ios;
}
assert(false);
return null;
}
void _showNotImplementedMessage() {
@@ -211,7 +209,7 @@ class _DrawerDemoState extends State<DrawerDemo> with TickerProviderStateMixin {
body: Center(
child: InkWell(
onTap: () {
_scaffoldKey.currentState.openDrawer();
_scaffoldKey.currentState!.openDrawer();
},
child: Semantics(
button: true,

View File

@@ -14,7 +14,7 @@ enum Location {
}
typedef DemoItemBodyBuilder<T> = Widget Function(DemoItem<T> item);
typedef ValueToString<T> = String Function(T value);
typedef ValueToString<T> = String? Function(T value);
class DualHeaderWithHint extends StatelessWidget {
const DualHeaderWithHint({
@@ -24,10 +24,10 @@ class DualHeaderWithHint extends StatelessWidget {
this.showHint,
});
final String name;
final String value;
final String hint;
final bool showHint;
final String? name;
final String? value;
final String? hint;
final bool? showHint;
Widget _crossFade(Widget first, Widget second, bool isExpanded) {
return AnimatedCrossFade(
@@ -56,8 +56,8 @@ class DualHeaderWithHint extends StatelessWidget {
fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft,
child: Text(
name,
style: textTheme.bodyText2.copyWith(fontSize: 15.0),
name!,
style: textTheme.bodyText2!.copyWith(fontSize: 15.0),
),
),
),
@@ -67,9 +67,9 @@ class DualHeaderWithHint extends StatelessWidget {
child: Container(
margin: const EdgeInsets.only(left: 24.0),
child: _crossFade(
Text(value, style: textTheme.caption.copyWith(fontSize: 15.0)),
Text(hint, style: textTheme.caption.copyWith(fontSize: 15.0)),
showHint,
Text(value!, style: textTheme.caption!.copyWith(fontSize: 15.0)),
Text(hint!, style: textTheme.caption!.copyWith(fontSize: 15.0)),
showHint!,
),
),
),
@@ -87,9 +87,9 @@ class CollapsibleBody extends StatelessWidget {
});
final EdgeInsets margin;
final Widget child;
final VoidCallback onSave;
final VoidCallback onCancel;
final Widget? child;
final VoidCallback? onSave;
final VoidCallback? onCancel;
@override
Widget build(BuildContext context) {
@@ -106,8 +106,8 @@ class CollapsibleBody extends StatelessWidget {
) - margin,
child: Center(
child: DefaultTextStyle(
style: textTheme.caption.copyWith(fontSize: 15.0),
child: child,
style: textTheme.caption!.copyWith(fontSize: 15.0),
child: child!,
),
),
),
@@ -149,15 +149,15 @@ class DemoItem<T> {
this.value,
this.hint,
this.builder,
this.valueToString,
required this.valueToString,
}) : textController = TextEditingController(text: valueToString(value));
final String name;
final String hint;
final String? name;
final String? hint;
final TextEditingController textController;
final DemoItemBodyBuilder<T> builder;
final ValueToString<T> valueToString;
T value;
final DemoItemBodyBuilder<T>? builder;
final ValueToString<T?> valueToString;
T? value;
bool isExpanded = false;
ExpansionPanelHeaderBuilder get headerBuilder {
@@ -171,7 +171,7 @@ class DemoItem<T> {
};
}
Widget build() => builder(this);
Widget build() => builder!(this);
}
class ExpansionPanelsDemo extends StatefulWidget {
@@ -182,7 +182,7 @@ class ExpansionPanelsDemo extends StatefulWidget {
}
class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
List<DemoItem<dynamic>> _demoItems;
late List<DemoItem<dynamic>> _demoItems;
@override
void initState() {
@@ -193,7 +193,7 @@ class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
name: 'Trip',
value: 'Caribbean cruise',
hint: 'Change trip name',
valueToString: (String value) => value,
valueToString: (String? value) => value,
builder: (DemoItem<String> item) {
void close() {
setState(() {
@@ -206,8 +206,8 @@ class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
builder: (BuildContext context) {
return CollapsibleBody(
margin: const EdgeInsets.symmetric(horizontal: 16.0),
onSave: () { Form.of(context).save(); close(); },
onCancel: () { Form.of(context).reset(); close(); },
onSave: () { Form.of(context)!.save(); close(); },
onCancel: () { Form.of(context)!.reset(); close(); },
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: TextFormField(
@@ -216,7 +216,7 @@ class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
hintText: item.hint,
labelText: item.name,
),
onSaved: (String value) { item.value = value; },
onSaved: (String? value) { item.value = value; },
),
),
);
@@ -229,7 +229,7 @@ class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
name: 'Location',
value: Location.Bahamas,
hint: 'Select location',
valueToString: (Location location) => location.toString().split('.')[1],
valueToString: (Location? location) => location.toString().split('.')[1],
builder: (DemoItem<Location> item) {
void close() {
setState(() {
@@ -240,11 +240,11 @@ class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
child: Builder(
builder: (BuildContext context) {
return CollapsibleBody(
onSave: () { Form.of(context).save(); close(); },
onCancel: () { Form.of(context).reset(); close(); },
onSave: () { Form.of(context)!.save(); close(); },
onCancel: () { Form.of(context)!.reset(); close(); },
child: FormField<Location>(
initialValue: item.value,
onSaved: (Location result) { item.value = result; },
onSaved: (Location? result) { item.value = result; },
builder: (FormFieldState<Location> field) {
return Column(
mainAxisSize: MainAxisSize.min,
@@ -282,7 +282,7 @@ class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
name: 'Sun',
value: 80.0,
hint: 'Select sun level',
valueToString: (double amount) => '${amount.round()}',
valueToString: (double? amount) => '${amount!.round()}',
builder: (DemoItem<double> item) {
void close() {
setState(() {
@@ -294,11 +294,11 @@ class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
child: Builder(
builder: (BuildContext context) {
return CollapsibleBody(
onSave: () { Form.of(context).save(); close(); },
onCancel: () { Form.of(context).reset(); close(); },
onSave: () { Form.of(context)!.save(); close(); },
onCancel: () { Form.of(context)!.reset(); close(); },
child: FormField<double>(
initialValue: item.value,
onSaved: (double value) { item.value = value; },
onSaved: (double? value) { item.value = value; },
builder: (FormFieldState<double> field) {
return Container(
// Allow room for the value indicator.
@@ -307,9 +307,9 @@ class _ExpansionPanelsDemoState extends State<ExpansionPanelsDemo> {
min: 0.0,
max: 100.0,
divisions: 5,
activeColor: Colors.orange[100 + (field.value * 5.0).round()],
label: '${field.value.round()}',
value: field.value,
activeColor: Colors.orange[100 + (field.value! * 5.0).round()],
label: '${field.value!.round()}',
value: field.value!,
onChanged: field.didChange,
),
);

View File

@@ -15,9 +15,8 @@ enum DismissDialogAction {
}
class DateTimeItem extends StatelessWidget {
DateTimeItem({ Key key, DateTime dateTime, @required this.onChanged })
: assert(onChanged != null),
date = DateTime(dateTime.year, dateTime.month, dateTime.day),
DateTimeItem({ Key? key, required DateTime dateTime, required this.onChanged })
: date = DateTime(dateTime.year, dateTime.month, dateTime.day),
time = TimeOfDay(hour: dateTime.hour, minute: dateTime.minute),
super(key: key);
@@ -30,7 +29,7 @@ class DateTimeItem extends StatelessWidget {
final ThemeData theme = Theme.of(context);
return DefaultTextStyle(
style: theme.textTheme.subtitle1,
style: theme.textTheme.subtitle1!,
child: Row(
children: <Widget>[
Expanded(
@@ -47,7 +46,7 @@ class DateTimeItem extends StatelessWidget {
firstDate: date.subtract(const Duration(days: 30)),
lastDate: date.add(const Duration(days: 30)),
)
.then<void>((DateTime value) {
.then((DateTime? value) {
if (value != null)
onChanged(DateTime(value.year, value.month, value.day, time.hour, time.minute));
});
@@ -74,7 +73,7 @@ class DateTimeItem extends StatelessWidget {
context: context,
initialTime: time,
)
.then<void>((TimeOfDay value) {
.then((TimeOfDay? value) {
if (value != null)
onChanged(DateTime(date.year, date.month, date.day, value.hour, value.minute));
});
@@ -101,11 +100,11 @@ class FullScreenDialogDemo extends StatefulWidget {
class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
DateTime _fromDateTime = DateTime.now();
DateTime _toDateTime = DateTime.now();
bool _allDayValue = false;
bool? _allDayValue = false;
bool _saveNeeded = false;
bool _hasLocation = false;
bool _hasName = false;
String _eventName;
late String _eventName;
Future<bool> _onWillPop() async {
_saveNeeded = _hasLocation || _hasName || _saveNeeded;
@@ -113,9 +112,9 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
return true;
final ThemeData theme = Theme.of(context);
final TextStyle dialogTextStyle = theme.textTheme.subtitle1.copyWith(color: theme.textTheme.caption.color);
final TextStyle dialogTextStyle = theme.textTheme.subtitle1!.copyWith(color: theme.textTheme.caption!.color);
return await showDialog<bool>(
return await (showDialog<bool>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
@@ -127,19 +126,19 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
TextButton(
child: const Text('CANCEL'),
onPressed: () {
Navigator.of(context).pop(false); // Pops the confirmation dialog but not the page.
Navigator.of(context)!.pop(false); // Pops the confirmation dialog but not the page.
},
),
TextButton(
child: const Text('DISCARD'),
onPressed: () {
Navigator.of(context).pop(true); // Returning true to _onWillPop will pop again.
Navigator.of(context)!.pop(true); // Returning true to _onWillPop will pop again.
},
),
],
);
},
) ?? false;
) as Future<bool>);
}
@override
@@ -151,7 +150,7 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
title: Text(_hasName ? _eventName : 'Event Name TBD'),
actions: <Widget> [
TextButton(
child: Text('SAVE', style: theme.textTheme.bodyText2.copyWith(color: Colors.white)),
child: Text('SAVE', style: theme.textTheme.bodyText2!.copyWith(color: Colors.white)),
onPressed: () {
Navigator.pop(context, DismissDialogAction.save);
},
@@ -238,7 +237,7 @@ class FullScreenDialogDemoState extends State<FullScreenDialogDemo> {
children: <Widget> [
Checkbox(
value: _allDayValue,
onChanged: (bool value) {
onChanged: (bool? value) {
setState(() {
_allDayValue = value;
_saveNeeded = true;

View File

@@ -26,21 +26,21 @@ class Photo {
this.isFavorite = false,
});
final String assetName;
final String assetPackage;
final String title;
final String caption;
final String? assetName;
final String? assetPackage;
final String? title;
final String? caption;
bool isFavorite;
String get tag => assetName; // Assuming that all asset names are unique.
String? get tag => assetName; // Assuming that all asset names are unique.
bool get isValid => assetName != null && title != null && caption != null && isFavorite != null;
bool get isValid => assetName != null && title != null && caption != null;
}
class GridPhotoViewer extends StatefulWidget {
const GridPhotoViewer({ Key key, this.photo }) : super(key: key);
const GridPhotoViewer({ Key? key, this.photo }) : super(key: key);
final Photo photo;
final Photo? photo;
@override
_GridPhotoViewerState createState() => _GridPhotoViewerState();
@@ -49,25 +49,25 @@ class GridPhotoViewer extends StatefulWidget {
class _GridTitleText extends StatelessWidget {
const _GridTitleText(this.text);
final String text;
final String? text;
@override
Widget build(BuildContext context) {
return FittedBox(
fit: BoxFit.scaleDown,
alignment: Alignment.centerLeft,
child: Text(text),
child: Text(text!),
);
}
}
class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation<Offset> _flingAnimation;
late AnimationController _controller;
late Animation<Offset> _flingAnimation;
Offset _offset = Offset.zero;
double _scale = 1.0;
Offset _normalizedOffset;
double _previousScale;
late Offset _normalizedOffset;
late double _previousScale;
@override
void initState() {
@@ -85,11 +85,11 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv
// The maximum offset value is 0,0. If the size of this renderer's box is w,h
// then the minimum offset value is w - _scale * w, h - _scale * h.
Offset _clampOffset(Offset offset) {
final Size size = context.size;
final Size size = context.size!;
final Offset minOffset = Offset(size.width, size.height) * (1.0 - _scale);
return Offset(
offset.dx.clamp(minOffset.dx, 0.0) as double,
offset.dy.clamp(minOffset.dy, 0.0) as double,
offset.dx.clamp(minOffset.dx, 0.0),
offset.dy.clamp(minOffset.dy, 0.0),
);
}
@@ -110,7 +110,7 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv
void _handleOnScaleUpdate(ScaleUpdateDetails details) {
setState(() {
_scale = (_previousScale * details.scale).clamp(1.0, 4.0) as double;
_scale = (_previousScale * details.scale).clamp(1.0, 4.0);
// Ensure that image location under the focal point stays in the same place despite scaling.
_offset = _clampOffset(details.focalPoint - _normalizedOffset * _scale);
});
@@ -121,7 +121,7 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv
if (magnitude < _kMinFlingVelocity)
return;
final Offset direction = details.velocity.pixelsPerSecond / magnitude;
final double distance = (Offset.zero & context.size).shortestSide;
final double distance = (Offset.zero & context.size!).shortestSide;
_flingAnimation = _controller.drive(Tween<Offset>(
begin: _offset,
end: _clampOffset(_offset + direction * distance),
@@ -143,8 +143,8 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv
..translate(_offset.dx, _offset.dy)
..scale(_scale),
child: Image.asset(
widget.photo.assetName,
package: widget.photo.assetPackage,
widget.photo!.assetName!,
package: widget.photo!.assetPackage,
fit: BoxFit.cover,
),
),
@@ -155,13 +155,11 @@ class _GridPhotoViewerState extends State<GridPhotoViewer> with SingleTickerProv
class GridDemoPhotoItem extends StatelessWidget {
GridDemoPhotoItem({
Key key,
@required this.photo,
@required this.tileStyle,
@required this.onBannerTap,
}) : assert(photo != null && photo.isValid),
assert(tileStyle != null),
assert(onBannerTap != null),
Key? key,
required this.photo,
required this.tileStyle,
required this.onBannerTap,
}) : assert(photo.isValid),
super(key: key);
final Photo photo;
@@ -173,11 +171,11 @@ class GridDemoPhotoItem extends StatelessWidget {
builder: (BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(photo.title),
title: Text(photo.title!),
),
body: SizedBox.expand(
child: Hero(
tag: photo.tag,
tag: photo.tag!,
child: GridPhotoViewer(photo: photo),
),
),
@@ -193,10 +191,10 @@ class GridDemoPhotoItem extends StatelessWidget {
child: GestureDetector(
onTap: () { showPhoto(context); },
child: Hero(
key: Key(photo.assetName),
tag: photo.tag,
key: Key(photo.assetName!),
tag: photo.tag!,
child: Image.asset(
photo.assetName,
photo.assetName!,
package: photo.assetPackage,
fit: BoxFit.cover,
),
@@ -243,13 +241,11 @@ class GridDemoPhotoItem extends StatelessWidget {
child: image,
);
}
assert(tileStyle != null);
return null;
}
}
class GridListDemo extends StatefulWidget {
const GridListDemo({ Key key }) : super(key: key);
const GridListDemo({ Key? key }) : super(key: key);
static const String routeName = '/material/grid-list';

View File

@@ -109,7 +109,7 @@ class _IconsDemoCard extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final TextStyle textStyle = theme.textTheme.subtitle1.copyWith(color: theme.textTheme.caption.color);
final TextStyle textStyle = theme.textTheme.subtitle1!.copyWith(color: theme.textTheme.caption!.color);
return Card(
child: DefaultTextStyle(
style: textStyle,

View File

@@ -23,17 +23,17 @@ class LeaveBehindItem implements Comparable<LeaveBehindItem> {
LeaveBehindItem.from(LeaveBehindItem item)
: index = item.index, name = item.name, subject = item.subject, body = item.body;
final int index;
final String name;
final String subject;
final String body;
final int? index;
final String? name;
final String? subject;
final String? body;
@override
int compareTo(LeaveBehindItem other) => index.compareTo(other.index);
int compareTo(LeaveBehindItem other) => index!.compareTo(other.index!);
}
class LeaveBehindDemo extends StatefulWidget {
const LeaveBehindDemo({ Key key }) : super(key: key);
const LeaveBehindDemo({ Key? key }) : super(key: key);
static const String routeName = '/material/leave-behind';
@@ -44,7 +44,7 @@ class LeaveBehindDemo extends StatefulWidget {
class LeaveBehindDemoState extends State<LeaveBehindDemo> {
DismissDirection _dismissDirection = DismissDirection.horizontal;
bool _confirmDismiss = true;
List<LeaveBehindItem> leaveBehindItems;
late List<LeaveBehindItem> leaveBehindItems;
void initListItems() {
leaveBehindItems = List<LeaveBehindItem>.generate(16, (int index) {
@@ -188,12 +188,12 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
class _LeaveBehindListItem extends StatelessWidget {
const _LeaveBehindListItem({
Key key,
@required this.item,
@required this.onArchive,
@required this.onDelete,
@required this.dismissDirection,
@required this.confirmDismiss,
Key? key,
required this.item,
required this.onArchive,
required this.onDelete,
required this.dismissDirection,
required this.confirmDismiss,
}) : super(key: key);
final LeaveBehindItem item;
@@ -263,7 +263,7 @@ class _LeaveBehindListItem extends StatelessWidget {
border: Border(bottom: BorderSide(color: theme.dividerColor)),
),
child: ListTile(
title: Text(item.name),
title: Text(item.name!),
subtitle: Text('${item.subject}\n${item.body}'),
isThreeLine: true,
),
@@ -272,7 +272,7 @@ class _LeaveBehindListItem extends StatelessWidget {
);
}
Future<bool> _showConfirmationDialog(BuildContext context, String action) {
Future<bool?> _showConfirmationDialog(BuildContext context, String action) {
return showDialog<bool>(
context: context,
barrierDismissible: true,

View File

@@ -21,7 +21,7 @@ enum _MaterialListType {
}
class ListDemo extends StatefulWidget {
const ListDemo({ Key key }) : super(key: key);
const ListDemo({ Key? key }) : super(key: key);
static const String routeName = '/material/list';
@@ -32,26 +32,26 @@ class ListDemo extends StatefulWidget {
class _ListDemoState extends State<ListDemo> {
static final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
PersistentBottomSheetController<void> _bottomSheet;
_MaterialListType _itemType = _MaterialListType.threeLine;
bool _dense = false;
bool _showAvatars = true;
bool _showIcons = false;
bool _showDividers = false;
PersistentBottomSheetController<void>? _bottomSheet;
_MaterialListType? _itemType = _MaterialListType.threeLine;
bool? _dense = false;
bool? _showAvatars = true;
bool? _showIcons = false;
bool? _showDividers = false;
bool _reverseSort = false;
List<String> items = <String>[
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
];
void changeItemType(_MaterialListType type) {
void changeItemType(_MaterialListType? type) {
setState(() {
_itemType = type;
});
_bottomSheet?.setState(() { });
_bottomSheet?.setState!(() { });
}
void _showConfigurationSheet() {
final PersistentBottomSheetController<void> bottomSheet = scaffoldKey.currentState.showBottomSheet<void>((BuildContext bottomSheetContext) {
final PersistentBottomSheetController<void> bottomSheet = scaffoldKey.currentState!.showBottomSheet<void>((BuildContext bottomSheetContext) {
return Container(
decoration: const BoxDecoration(
border: Border(top: BorderSide(color: Colors.black26)),
@@ -65,7 +65,7 @@ class _ListDemoState extends State<ListDemo> {
dense: true,
title: const Text('One-line'),
trailing: Radio<_MaterialListType>(
value: _showAvatars ? _MaterialListType.oneLineWithAvatar : _MaterialListType.oneLine,
value: _showAvatars! ? _MaterialListType.oneLineWithAvatar : _MaterialListType.oneLine,
groupValue: _itemType,
onChanged: changeItemType,
),
@@ -99,11 +99,14 @@ class _ListDemoState extends State<ListDemo> {
title: const Text('Show avatar'),
trailing: Checkbox(
value: _showAvatars,
onChanged: (bool value) {
onChanged: (bool? value) {
setState(() {
_showAvatars = value;
});
_bottomSheet?.setState(() { });
final StateSetter? bottomSheetSetState = _bottomSheet?.setState;
if (bottomSheetSetState != null) {
bottomSheetSetState(() { });
}
},
),
),
@@ -114,11 +117,14 @@ class _ListDemoState extends State<ListDemo> {
title: const Text('Show icon'),
trailing: Checkbox(
value: _showIcons,
onChanged: (bool value) {
onChanged: (bool? value) {
setState(() {
_showIcons = value;
});
_bottomSheet?.setState(() { });
final StateSetter? bottomSheetSetState = _bottomSheet?.setState;
if (bottomSheetSetState != null) {
bottomSheetSetState(() { });
}
},
),
),
@@ -129,11 +135,14 @@ class _ListDemoState extends State<ListDemo> {
title: const Text('Show dividers'),
trailing: Checkbox(
value: _showDividers,
onChanged: (bool value) {
onChanged: (bool? value) {
setState(() {
_showDividers = value;
});
_bottomSheet?.setState(() { });
final StateSetter? bottomSheetSetState = _bottomSheet?.setState;
if (bottomSheetSetState != null) {
bottomSheetSetState(() { });
}
},
),
),
@@ -144,11 +153,14 @@ class _ListDemoState extends State<ListDemo> {
title: const Text('Dense layout'),
trailing: Checkbox(
value: _dense,
onChanged: (bool value) {
onChanged: (bool? value) {
setState(() {
_dense = value;
});
_bottomSheet?.setState(() { });
final StateSetter? bottomSheetSetState = _bottomSheet?.setState;
if (bottomSheetSetState != null) {
bottomSheetSetState(() { });
}
},
),
),
@@ -162,7 +174,7 @@ class _ListDemoState extends State<ListDemo> {
_bottomSheet = bottomSheet;
});
_bottomSheet.closed.whenComplete(() {
_bottomSheet?.closed.whenComplete(() {
if (mounted) {
setState(() {
_bottomSheet = null;
@@ -172,7 +184,7 @@ class _ListDemoState extends State<ListDemo> {
}
Widget buildListTile(BuildContext context, String item) {
Widget secondary;
Widget? secondary;
if (_itemType == _MaterialListType.twoLine) {
secondary = const Text('Additional item information.');
} else if (_itemType == _MaterialListType.threeLine) {
@@ -184,18 +196,18 @@ class _ListDemoState extends State<ListDemo> {
child: ListTile(
isThreeLine: _itemType == _MaterialListType.threeLine,
dense: _dense,
leading: _showAvatars ? ExcludeSemantics(child: CircleAvatar(child: Text(item))) : null,
leading: _showAvatars != null ? ExcludeSemantics(child: CircleAvatar(child: Text(item))) : null,
title: Text('This item represents $item.'),
subtitle: secondary,
trailing: _showIcons ? Icon(Icons.info, color: Theme.of(context).disabledColor) : null,
trailing: _showIcons != null ? Icon(Icons.info, color: Theme.of(context).disabledColor) : null,
),
);
}
@override
Widget build(BuildContext context) {
final String layoutText = _dense ? ' \u2013 Dense' : '';
String itemTypeText;
final String layoutText = _dense != null ? ' \u2013 Dense' : '';
String? itemTypeText;
switch (_itemType) {
case _MaterialListType.oneLine:
case _MaterialListType.oneLineWithAvatar:
@@ -207,10 +219,12 @@ class _ListDemoState extends State<ListDemo> {
case _MaterialListType.threeLine:
itemTypeText = 'Three-line';
break;
default:
break;
}
Iterable<Widget> listTiles = items.map<Widget>((String item) => buildListTile(context, item));
if (_showDividers)
if (_showDividers != null)
listTiles = ListTile.divideTiles(context: context, tiles: listTiles);
return Scaffold(
@@ -242,7 +256,7 @@ class _ListDemoState extends State<ListDemo> {
),
body: Scrollbar(
child: ListView(
padding: EdgeInsets.symmetric(vertical: _dense ? 4.0 : 8.0),
padding: EdgeInsets.symmetric(vertical: _dense != null ? 4.0 : 8.0),
children: listTiles.toList(),
),
),

View File

@@ -7,7 +7,7 @@ import 'package:flutter/material.dart';
import '../../gallery/demo.dart';
class MenuDemo extends StatefulWidget {
const MenuDemo({ Key key }) : super(key: key);
const MenuDemo({ Key? key }) : super(key: key);
static const String routeName = '/material/menu';
@@ -20,13 +20,13 @@ class MenuDemoState extends State<MenuDemo> {
final String _simpleValue1 = 'Menu item value one';
final String _simpleValue2 = 'Menu item value two';
final String _simpleValue3 = 'Menu item value three';
String _simpleValue;
String? _simpleValue;
final String _checkedValue1 = 'One';
final String _checkedValue2 = 'Two';
final String _checkedValue3 = 'Free';
final String _checkedValue4 = 'Four';
List<String> _checkedValues;
late List<String> _checkedValues;
@override
void initState() {
@@ -165,7 +165,7 @@ class MenuDemoState extends State<MenuDemo> {
onSelected: showMenuSelection,
child: ListTile(
title: const Text('An item with a simple menu'),
subtitle: Text(_simpleValue),
subtitle: Text(_simpleValue!),
),
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
PopupMenuItem<String>(

View File

@@ -11,7 +11,7 @@ import '../../gallery/demo.dart';
enum IndicatorType { overscroll, refresh }
class OverscrollDemo extends StatefulWidget {
const OverscrollDemo({ Key key }) : super(key: key);
const OverscrollDemo({ Key? key }) : super(key: key);
static const String routeName = '/material/overscroll';
@@ -28,13 +28,13 @@ class OverscrollDemoState extends State<OverscrollDemo> {
Future<void> _handleRefresh() {
final Completer<void> completer = Completer<void>();
Timer(const Duration(seconds: 3), () { completer.complete(); });
return completer.future.then<void>((_) {
return completer.future.then((_) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text('Refresh complete'),
action: SnackBarAction(
label: 'RETRY',
onPressed: () {
_refreshIndicatorKey.currentState.show();
_refreshIndicatorKey.currentState!.show();
},
),
));
@@ -52,7 +52,7 @@ class OverscrollDemoState extends State<OverscrollDemo> {
icon: const Icon(Icons.refresh),
tooltip: 'Refresh',
onPressed: () {
_refreshIndicatorKey.currentState.show();
_refreshIndicatorKey.currentState!.show();
},
),
],

View File

@@ -9,17 +9,17 @@ import '../../gallery/demo.dart';
class _PageSelector extends StatelessWidget {
const _PageSelector({ this.icons });
final List<Icon> icons;
final List<Icon>? icons;
void _handleArrowButtonPress(BuildContext context, int delta) {
final TabController controller = DefaultTabController.of(context);
final TabController controller = DefaultTabController.of(context)!;
if (!controller.indexIsChanging)
controller.animateTo((controller.index + delta).clamp(0, icons.length - 1) as int);
controller.animateTo((controller.index + delta).clamp(0, icons!.length - 1));
}
@override
Widget build(BuildContext context) {
final TabController controller = DefaultTabController.of(context);
final TabController? controller = DefaultTabController.of(context);
final Color color = Theme.of(context).accentColor;
return SafeArea(
top: false,
@@ -54,7 +54,7 @@ class _PageSelector extends StatelessWidget {
color: color,
),
child: TabBarView(
children: icons.map<Widget>((Icon icon) {
children: icons!.map<Widget>((Icon icon) {
return Container(
padding: const EdgeInsets.all(12.0),
child: Card(

View File

@@ -16,7 +16,7 @@ class PersistentBottomSheetDemo extends StatefulWidget {
class _PersistentBottomSheetDemoState extends State<PersistentBottomSheetDemo> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
VoidCallback _showBottomSheetCallback;
VoidCallback? _showBottomSheetCallback;
@override
void initState() {
@@ -28,7 +28,7 @@ class _PersistentBottomSheetDemoState extends State<PersistentBottomSheetDemo> {
setState(() { // disable the button
_showBottomSheetCallback = null;
});
_scaffoldKey.currentState.showBottomSheet<void>((BuildContext context) {
_scaffoldKey.currentState!.showBottomSheet<void>((BuildContext context) {
final ThemeData themeData = Theme.of(context);
return Container(
decoration: BoxDecoration(

View File

@@ -14,8 +14,8 @@ class ProgressIndicatorDemo extends StatefulWidget {
}
class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation<double> _animation;
late AnimationController _controller;
late Animation<double> _animation;
@override
void initState() {
@@ -64,7 +64,7 @@ class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> with Sing
});
}
Widget _buildIndicators(BuildContext context, Widget child) {
Widget _buildIndicators(BuildContext context, Widget? child) {
final List<Widget> indicators = <Widget>[
const SizedBox(
width: 200.0,
@@ -109,7 +109,7 @@ class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo> with Sing
body: Center(
child: SingleChildScrollView(
child: DefaultTextStyle(
style: Theme.of(context).textTheme.headline6,
style: Theme.of(context).textTheme.headline6!,
child: GestureDetector(
onTap: _handleTap,
behavior: HitTestBehavior.opaque,

View File

@@ -20,7 +20,7 @@ enum _ReorderableListType {
}
class ReorderableListDemo extends StatefulWidget {
const ReorderableListDemo({ Key key }) : super(key: key);
const ReorderableListDemo({ Key? key }) : super(key: key);
static const String routeName = '/material/reorderable-list';
@@ -33,38 +33,38 @@ class _ListItem {
final String value;
bool checkState;
bool? checkState;
}
class _ListDemoState extends State<ReorderableListDemo> {
static final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
PersistentBottomSheetController<void> _bottomSheet;
_ReorderableListType _itemType = _ReorderableListType.threeLine;
bool _reverse = false;
PersistentBottomSheetController<void>? _bottomSheet;
_ReorderableListType? _itemType = _ReorderableListType.threeLine;
bool? _reverse = false;
bool _reverseSort = false;
final List<_ListItem> _items = <String>[
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
].map<_ListItem>((String item) => _ListItem(item, false)).toList();
void changeItemType(_ReorderableListType type) {
void changeItemType(_ReorderableListType? type) {
setState(() {
_itemType = type;
});
// Rebuild the bottom sheet to reflect the selected list view.
_bottomSheet?.setState(() {
_bottomSheet?.setState!(() {
// Trigger a rebuild.
});
// Close the bottom sheet to give the user a clear view of the list.
_bottomSheet?.close();
}
void changeReverse(bool newValue) {
void changeReverse(bool? newValue) {
setState(() {
_reverse = newValue;
});
// Rebuild the bottom sheet to reflect the selected list view.
_bottomSheet?.setState(() {
_bottomSheet?.setState!(() {
// Trigger a rebuild.
});
// Close the bottom sheet to give the user a clear view of the list.
@@ -73,7 +73,7 @@ class _ListDemoState extends State<ReorderableListDemo> {
void _showConfigurationSheet() {
setState(() {
_bottomSheet = scaffoldKey.currentState.showBottomSheet<void>((BuildContext bottomSheetContext) {
_bottomSheet = scaffoldKey.currentState!.showBottomSheet<void>((BuildContext bottomSheetContext) {
return DecoratedBox(
decoration: const BoxDecoration(
border: Border(top: BorderSide(color: Colors.black26)),
@@ -115,7 +115,7 @@ class _ListDemoState extends State<ReorderableListDemo> {
});
// Garbage collect the bottom sheet when it closes.
_bottomSheet.closed.whenComplete(() {
_bottomSheet?.closed.whenComplete(() {
if (mounted) {
setState(() {
_bottomSheet = null;
@@ -129,14 +129,14 @@ class _ListDemoState extends State<ReorderableListDemo> {
const Widget secondary = Text(
'Even more additional list item information appears on line three.',
);
Widget listTile;
late Widget listTile;
switch (_itemType) {
case _ReorderableListType.threeLine:
listTile = CheckboxListTile(
key: Key(item.value),
isThreeLine: true,
value: item.checkState ?? false,
onChanged: (bool newValue) {
onChanged: (bool? newValue) {
setState(() {
item.checkState = newValue;
});
@@ -157,6 +157,11 @@ class _ListDemoState extends State<ReorderableListDemo> {
),
);
break;
default:
listTile = Container(
key: Key(item.value),
);
break;
}
return listTile;
@@ -210,7 +215,7 @@ class _ListDemoState extends State<ReorderableListDemo> {
child: Text('Header of the list', style: Theme.of(context).textTheme.headline5))
: null,
onReorder: _onReorder,
reverse: _reverse,
reverse: _reverse!,
scrollDirection: _itemType == _ReorderableListType.horizontalAvatar ? Axis.horizontal : Axis.vertical,
padding: const EdgeInsets.symmetric(vertical: 8.0),
children: _items.map<Widget>(buildListTile).toList(),

View File

@@ -14,8 +14,8 @@ enum TabsDemoStyle {
class _Page {
const _Page({ this.icon, this.text });
final IconData icon;
final String text;
final IconData? icon;
final String? text;
}
const List<_Page> _allPages = <_Page>[
@@ -43,7 +43,7 @@ class ScrollableTabsDemo extends StatefulWidget {
}
class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTickerProviderStateMixin {
TabController _controller;
TabController? _controller;
TabsDemoStyle _demoStyle = TabsDemoStyle.iconsAndText;
bool _customIndicator = false;
@@ -55,7 +55,7 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke
@override
void dispose() {
_controller.dispose();
_controller!.dispose();
super.dispose();
}
@@ -65,7 +65,7 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke
});
}
Decoration getIndicator() {
Decoration? getIndicator() {
if (!_customIndicator)
return const UnderlineTabIndicator();
@@ -117,7 +117,6 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke
),
);
}
return null;
}
@override
@@ -161,7 +160,6 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke
isScrollable: true,
indicator: getIndicator(),
tabs: _allPages.map<Tab>((_Page page) {
assert(_demoStyle != null);
switch (_demoStyle) {
case TabsDemoStyle.iconsAndText:
return Tab(text: page.text, icon: Icon(page.icon));
@@ -169,9 +167,10 @@ class ScrollableTabsDemoState extends State<ScrollableTabsDemo> with SingleTicke
return Tab(icon: Icon(page.icon));
case TabsDemoStyle.textOnly:
return Tab(text: page.text);
default:
return Tab();
}
return null;
}).toList(),
}).toList()
),
),
body: TabBarView(

View File

@@ -17,7 +17,7 @@ class _SearchDemoState extends State<SearchDemo> {
final _SearchDemoSearchDelegate _delegate = _SearchDemoSearchDelegate();
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
int _lastIntegerSelected;
int? _lastIntegerSelected;
@override
Widget build(BuildContext context) {
@@ -32,7 +32,7 @@ class _SearchDemoState extends State<SearchDemo> {
progress: _delegate.transitionAnimation,
),
onPressed: () {
_scaffoldKey.currentState.openDrawer();
_scaffoldKey.currentState!.openDrawer();
},
),
title: const Text('Numbers'),
@@ -41,7 +41,7 @@ class _SearchDemoState extends State<SearchDemo> {
tooltip: 'Search',
icon: const Icon(Icons.search),
onPressed: () async {
final int selected = await showSearch<int>(
final int? selected = await showSearch<int?>(
context: context,
delegate: _delegate,
);
@@ -98,7 +98,7 @@ class _SearchDemoState extends State<SearchDemo> {
floatingActionButton: FloatingActionButton.extended(
tooltip: 'Back', // Tests depend on this label to exit the demo.
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context)!.pop();
},
label: const Text('Close demo'),
icon: const Icon(Icons.close),
@@ -133,7 +133,7 @@ class _SearchDemoState extends State<SearchDemo> {
}
}
class _SearchDemoSearchDelegate extends SearchDelegate<int> {
class _SearchDemoSearchDelegate extends SearchDelegate<int?> {
final List<int> _data = List<int>.generate(100001, (int i) => i).reversed.toList();
final List<int> _history = <int>[42607, 85604, 66374, 44, 174];
@@ -170,7 +170,7 @@ class _SearchDemoSearchDelegate extends SearchDelegate<int> {
@override
Widget buildResults(BuildContext context) {
final int searched = int.tryParse(query);
final int? searched = int.tryParse(query);
if (searched == null || !_data.contains(searched)) {
return Center(
child: Text(
@@ -228,26 +228,26 @@ class _SearchDemoSearchDelegate extends SearchDelegate<int> {
class _ResultCard extends StatelessWidget {
const _ResultCard({this.integer, this.title, this.searchDelegate});
final int integer;
final String title;
final SearchDelegate<int> searchDelegate;
final int? integer;
final String? title;
final SearchDelegate<int?>? searchDelegate;
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
return GestureDetector(
onTap: () {
searchDelegate.close(context, integer);
searchDelegate!.close(context, integer);
},
child: Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Text(title),
Text(title!),
Text(
'$integer',
style: theme.textTheme.headline5.copyWith(fontSize: 72.0),
style: theme.textTheme.headline5!.copyWith(fontSize: 72.0),
),
],
),
@@ -260,33 +260,33 @@ class _ResultCard extends StatelessWidget {
class _SuggestionList extends StatelessWidget {
const _SuggestionList({this.suggestions, this.query, this.onSelected});
final List<String> suggestions;
final String query;
final ValueChanged<String> onSelected;
final List<String>? suggestions;
final String? query;
final ValueChanged<String>? onSelected;
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
return ListView.builder(
itemCount: suggestions.length,
itemCount: suggestions!.length,
itemBuilder: (BuildContext context, int i) {
final String suggestion = suggestions[i];
final String suggestion = suggestions![i];
return ListTile(
leading: query.isEmpty ? const Icon(Icons.history) : const Icon(null),
leading: query!.isEmpty ? const Icon(Icons.history) : const Icon(null),
title: RichText(
text: TextSpan(
text: suggestion.substring(0, query.length),
style: theme.textTheme.subtitle1.copyWith(fontWeight: FontWeight.bold),
text: suggestion.substring(0, query!.length),
style: theme.textTheme.subtitle1!.copyWith(fontWeight: FontWeight.bold),
children: <TextSpan>[
TextSpan(
text: suggestion.substring(query.length),
text: suggestion.substring(query!.length),
style: theme.textTheme.subtitle1,
),
],
),
),
onTap: () {
onSelected(suggestion);
onSelected!(suggestion);
},
);
},

View File

@@ -67,13 +67,13 @@ class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
);
}
bool checkboxValueA = true;
bool checkboxValueB = false;
bool checkboxValueC;
int radioValue = 0;
bool? checkboxValueA = true;
bool? checkboxValueB = false;
bool? checkboxValueC;
int? radioValue = 0;
bool switchValue = false;
void handleRadioValueChanged(int value) {
void handleRadioValueChanged(int? value) {
setState(() {
radioValue = value;
});
@@ -92,7 +92,7 @@ class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
label: 'Checkbox A',
child: Checkbox(
value: checkboxValueA,
onChanged: (bool value) {
onChanged: (bool? value) {
setState(() {
checkboxValueA = value;
});
@@ -103,7 +103,7 @@ class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
label: 'Checkbox B',
child: Checkbox(
value: checkboxValueB,
onChanged: (bool value) {
onChanged: (bool? value) {
setState(() {
checkboxValueB = value;
});
@@ -115,7 +115,7 @@ class _SelectionControlsDemoState extends State<SelectionControlsDemo> {
child: Checkbox(
value: checkboxValueC,
tristate: true,
onChanged: (bool value) {
onChanged: (bool? value) {
setState(() {
checkboxValueC = value;
});

View File

@@ -61,15 +61,15 @@ class _CustomRangeThumbShape extends RangeSliderThumbShape {
void paint(
PaintingContext context,
Offset center, {
@required Animation<double> activationAnimation,
@required Animation<double> enableAnimation,
required Animation<double> activationAnimation,
required Animation<double> enableAnimation,
bool isDiscrete = false,
bool isEnabled = false,
bool isOnTop,
@required SliderThemeData sliderTheme,
TextDirection textDirection,
Thumb thumb,
bool isPressed,
bool? isOnTop,
required SliderThemeData sliderTheme,
TextDirection? textDirection,
Thumb? thumb,
bool? isPressed,
}) {
final Canvas canvas = context.canvas;
final ColorTween colorTween = ColorTween(
@@ -78,7 +78,7 @@ class _CustomRangeThumbShape extends RangeSliderThumbShape {
);
final double size = _thumbSize * sizeTween.evaluate(enableAnimation);
Path thumbPath;
late Path thumbPath;
switch (textDirection) {
case TextDirection.rtl:
switch (thumb) {
@@ -88,6 +88,8 @@ class _CustomRangeThumbShape extends RangeSliderThumbShape {
case Thumb.end:
thumbPath = _leftTriangle(size, center);
break;
default:
break;
}
break;
case TextDirection.ltr:
@@ -98,10 +100,14 @@ class _CustomRangeThumbShape extends RangeSliderThumbShape {
case Thumb.end:
thumbPath = _rightTriangle(size, center);
break;
default:
break;
}
break;
default:
break;
}
canvas.drawPath(thumbPath, Paint()..color = colorTween.evaluate(enableAnimation));
canvas.drawPath(thumbPath, Paint()..color = colorTween.evaluate(enableAnimation)!);
}
}
@@ -123,16 +129,16 @@ class _CustomThumbShape extends SliderComponentShape {
void paint(
PaintingContext context,
Offset thumbCenter, {
Animation<double> activationAnimation,
Animation<double> enableAnimation,
bool isDiscrete,
TextPainter labelPainter,
RenderBox parentBox,
SliderThemeData sliderTheme,
TextDirection textDirection,
double value,
double textScaleFactor,
Size sizeWithOverflow,
Animation<double>? activationAnimation,
required Animation<double> enableAnimation,
bool? isDiscrete,
TextPainter? labelPainter,
RenderBox? parentBox,
required SliderThemeData sliderTheme,
TextDirection? textDirection,
double? value,
double? textScaleFactor,
Size? sizeWithOverflow,
}) {
final Canvas canvas = context.canvas;
final ColorTween colorTween = ColorTween(
@@ -141,7 +147,7 @@ class _CustomThumbShape extends SliderComponentShape {
);
final double size = _thumbSize * sizeTween.evaluate(enableAnimation);
final Path thumbPath = _downTriangle(size, thumbCenter);
canvas.drawPath(thumbPath, Paint()..color = colorTween.evaluate(enableAnimation));
canvas.drawPath(thumbPath, Paint()..color = colorTween.evaluate(enableAnimation)!);
}
}
@@ -164,16 +170,16 @@ class _CustomValueIndicatorShape extends SliderComponentShape {
void paint(
PaintingContext context,
Offset thumbCenter, {
Animation<double> activationAnimation,
Animation<double> enableAnimation,
bool isDiscrete,
TextPainter labelPainter,
RenderBox parentBox,
SliderThemeData sliderTheme,
TextDirection textDirection,
double value,
double textScaleFactor,
Size sizeWithOverflow,
required Animation<double> activationAnimation,
required Animation<double> enableAnimation,
bool? isDiscrete,
required TextPainter labelPainter,
RenderBox? parentBox,
required SliderThemeData sliderTheme,
TextDirection? textDirection,
double? value,
double? textScaleFactor,
Size? sizeWithOverflow,
}) {
final Canvas canvas = context.canvas;
final ColorTween enableColor = ColorTween(
@@ -187,7 +193,7 @@ class _CustomValueIndicatorShape extends SliderComponentShape {
final double size = _indicatorSize * sizeTween.evaluate(enableAnimation);
final Offset slideUpOffset = Offset(0.0, -slideUpTween.evaluate(activationAnimation));
final Path thumbPath = _upTriangle(size, thumbCenter + slideUpOffset);
final Color paintColor = enableColor.evaluate(enableAnimation).withAlpha((255.0 * activationAnimation.value).round());
final Color paintColor = enableColor.evaluate(enableAnimation)!.withAlpha((255.0 * activationAnimation.value).round());
canvas.drawPath(
thumbPath,
Paint()..color = paintColor,
@@ -259,10 +265,10 @@ class _SlidersState extends State<_Sliders> {
child: TextField(
textAlign: TextAlign.center,
onSubmitted: (String value) {
final double newValue = double.tryParse(value);
final double? newValue = double.tryParse(value);
if (newValue != null && newValue != _continuousValue) {
setState(() {
_continuousValue = newValue.clamp(0.0, 100.0) as double;
_continuousValue = newValue.clamp(0.0, 100.0);
});
}
},
@@ -326,7 +332,7 @@ class _SlidersState extends State<_Sliders> {
valueIndicatorColor: Colors.deepPurpleAccent,
thumbShape: _CustomThumbShape(),
valueIndicatorShape: _CustomValueIndicatorShape(),
valueIndicatorTextStyle: theme.accentTextTheme.bodyText1.copyWith(color: theme.colorScheme.onSurface),
valueIndicatorTextStyle: theme.accentTextTheme.bodyText1!.copyWith(color: theme.colorScheme.onSurface),
),
child: Slider(
value: _discreteCustomValue,

View File

@@ -19,7 +19,7 @@ const String _text3 =
'By default snackbars automatically disappear after a few seconds ';
class SnackBarDemo extends StatefulWidget {
const SnackBarDemo({ Key key }) : super(key: key);
const SnackBarDemo({ Key? key }) : super(key: key);
static const String routeName = '/material/snack-bar';

View File

@@ -13,17 +13,17 @@ const String _kGalleryAssetsPackage = 'flutter_gallery_assets';
class _Page {
_Page({ this.label });
final String label;
String get id => label.characters.first;
final String? label;
String get id => label!.characters.first;
@override
String toString() => '$runtimeType("$label")';
}
class _CardData {
const _CardData({ this.title, this.imageAsset, this.imageAssetPackage });
final String title;
final String imageAsset;
final String imageAssetPackage;
final String? title;
final String? imageAsset;
final String? imageAssetPackage;
}
final Map<_Page, List<_CardData>> _allPages = <_Page, List<_CardData>>{
@@ -97,8 +97,8 @@ class _CardDataItem extends StatelessWidget {
const _CardDataItem({ this.page, this.data });
static const double height = 272.0;
final _Page page;
final _CardData data;
final _Page? page;
final _CardData? data;
@override
Widget build(BuildContext context) {
@@ -110,23 +110,23 @@ class _CardDataItem extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Align(
alignment: page.id == 'H'
alignment: page!.id == 'H'
? Alignment.centerLeft
: Alignment.centerRight,
child: CircleAvatar(child: Text(page.id)),
child: CircleAvatar(child: Text(page!.id)),
),
SizedBox(
width: 144.0,
height: 144.0,
child: Image.asset(
data.imageAsset,
package: data.imageAssetPackage,
data!.imageAsset!,
package: data!.imageAssetPackage,
fit: BoxFit.contain,
),
),
Center(
child: Text(
data.title,
data!.title!,
style: Theme.of(context).textTheme.headline6,
),
),
@@ -187,7 +187,7 @@ class TabsDemo extends StatelessWidget {
itemExtent: _CardDataItem.height,
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
final _CardData data = _allPages[page][index];
final _CardData data = _allPages[page]![index];
return Padding(
padding: const EdgeInsets.symmetric(
vertical: 8.0,
@@ -198,7 +198,7 @@ class TabsDemo extends StatelessWidget {
),
);
},
childCount: _allPages[page].length,
childCount: _allPages[page]!.length,
),
),
),

View File

@@ -15,13 +15,13 @@ const String _explanatoryText =
class _Page {
_Page({ this.label, this.colors, this.icon });
final String label;
final MaterialColor colors;
final IconData icon;
final String? label;
final MaterialColor? colors;
final IconData? icon;
Color get labelColor => colors != null ? colors.shade300 : Colors.grey.shade300;
Color get labelColor => colors != null ? colors!.shade300 : Colors.grey.shade300;
bool get fabDefined => colors != null && icon != null;
Color get fabColor => colors.shade400;
Color get fabColor => colors!.shade400;
Icon get fabIcon => Icon(icon);
Key get fabKey => ValueKey<Color>(fabColor);
}
@@ -44,32 +44,32 @@ class TabsFabDemo extends StatefulWidget {
class _TabsFabDemoState extends State<TabsFabDemo> with SingleTickerProviderStateMixin {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
TabController _controller;
_Page _selectedPage;
TabController? _controller;
late _Page _selectedPage;
bool _extendedButtons = false;
@override
void initState() {
super.initState();
_controller = TabController(vsync: this, length: _allPages.length);
_controller.addListener(_handleTabSelection);
_controller!.addListener(_handleTabSelection);
_selectedPage = _allPages[0];
}
@override
void dispose() {
_controller.dispose();
_controller!.dispose();
super.dispose();
}
void _handleTabSelection() {
setState(() {
_selectedPage = _allPages[_controller.index];
_selectedPage = _allPages[_controller!.index];
});
}
void _showExplanatoryText() {
_scaffoldKey.currentState.showBottomSheet<void>((BuildContext context) {
_scaffoldKey.currentState!.showBottomSheet<void>((BuildContext context) {
return Container(
decoration: BoxDecoration(
border: Border(top: BorderSide(color: Theme.of(context).dividerColor))
@@ -86,11 +86,11 @@ class _TabsFabDemoState extends State<TabsFabDemo> with SingleTickerProviderStat
return Builder(
builder: (BuildContext context) {
return Container(
key: ValueKey<String>(page.label),
key: ValueKey<String?>(page.label),
padding: const EdgeInsets.fromLTRB(48.0, 48.0, 48.0, 96.0),
child: Card(
child: Center(
child: Text(page.label,
child: Text(page.label!,
style: TextStyle(
color: page.labelColor,
fontSize: 32.0,
@@ -104,7 +104,7 @@ class _TabsFabDemoState extends State<TabsFabDemo> with SingleTickerProviderStat
);
}
Widget buildFloatingActionButton(_Page page) {
Widget? buildFloatingActionButton(_Page page) {
if (!page.fabDefined)
return null;
@@ -114,7 +114,7 @@ class _TabsFabDemoState extends State<TabsFabDemo> with SingleTickerProviderStat
tooltip: 'Show explanation',
backgroundColor: page.fabColor,
icon: page.fabIcon,
label: Text(page.label.toUpperCase()),
label: Text(page.label!.toUpperCase()),
onPressed: _showExplanatoryText,
);
}
@@ -136,7 +136,7 @@ class _TabsFabDemoState extends State<TabsFabDemo> with SingleTickerProviderStat
title: const Text('FAB per tab'),
bottom: TabBar(
controller: _controller,
tabs: _allPages.map<Widget>((_Page page) => Tab(text: page.label.toUpperCase())).toList(),
tabs: _allPages.map<Widget>((_Page page) => Tab(text: page.label!.toUpperCase())).toList(),
),
actions: <Widget>[
MaterialDemoDocumentationButton(TabsFabDemo.routeName),

View File

@@ -9,7 +9,7 @@ import 'package:flutter/gestures.dart' show DragStartBehavior;
import '../../gallery/demo.dart';
class TextFormFieldDemo extends StatefulWidget {
const TextFormFieldDemo({ Key key }) : super(key: key);
const TextFormFieldDemo({ Key? key }) : super(key: key);
static const String routeName = '/material/text-form-field';
@@ -18,9 +18,9 @@ class TextFormFieldDemo extends StatefulWidget {
}
class PersonData {
String name = '';
String phoneNumber = '';
String email = '';
String? name = '';
String? phoneNumber = '';
String? email = '';
String password = '';
}
@@ -35,13 +35,13 @@ class PasswordField extends StatefulWidget {
this.onFieldSubmitted,
});
final Key fieldKey;
final String hintText;
final String labelText;
final String helperText;
final FormFieldSetter<String> onSaved;
final FormFieldValidator<String> validator;
final ValueChanged<String> onFieldSubmitted;
final Key? fieldKey;
final String? hintText;
final String? labelText;
final String? helperText;
final FormFieldSetter<String>? onSaved;
final FormFieldValidator<String>? validator;
final ValueChanged<String>? onFieldSubmitted;
@override
_PasswordFieldState createState() => _PasswordFieldState();
@@ -99,7 +99,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
final GlobalKey<FormFieldState<String>> _passwordFieldKey = GlobalKey<FormFieldState<String>>();
final _UsNumberTextInputFormatter _phoneNumberFormatter = _UsNumberTextInputFormatter();
void _handleSubmitted() {
final FormState form = _formKey.currentState;
final FormState form = _formKey.currentState!;
if (!form.validate()) {
_autovalidateMode = AutovalidateMode.always; // Start validating on every change.
showInSnackBar('Please fix the errors in red before submitting.');
@@ -109,9 +109,9 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
}
}
String _validateName(String value) {
String? _validateName(String? value) {
_formWasEdited = true;
if (value.isEmpty)
if (value!.isEmpty)
return 'Name is required.';
final RegExp nameExp = RegExp(r'^[A-Za-z ]+$');
if (!nameExp.hasMatch(value))
@@ -119,18 +119,18 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
return null;
}
String _validatePhoneNumber(String value) {
String? _validatePhoneNumber(String? value) {
_formWasEdited = true;
final RegExp phoneExp = RegExp(r'^\(\d\d\d\) \d\d\d\-\d\d\d\d$');
if (!phoneExp.hasMatch(value))
if (!phoneExp.hasMatch(value!))
return '(###) ###-#### - Enter a US phone number.';
return null;
}
String _validatePassword(String value) {
String? _validatePassword(String? value) {
_formWasEdited = true;
final FormFieldState<String> passwordField = _passwordFieldKey.currentState;
if (passwordField.value == null || passwordField.value.isEmpty)
final FormFieldState<String> passwordField = _passwordFieldKey.currentState!;
if (passwordField.value == null || passwordField.value!.isEmpty)
return 'Please enter a password.';
if (passwordField.value != value)
return "The passwords don't match";
@@ -138,11 +138,11 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
}
Future<bool> _warnUserAboutInvalidData() async {
final FormState form = _formKey.currentState;
final FormState? form = _formKey.currentState;
if (form == null || !_formWasEdited || form.validate())
return true;
return await showDialog<bool>(
return await (showDialog<bool>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
@@ -151,16 +151,16 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
actions: <Widget> [
TextButton(
child: const Text('YES'),
onPressed: () { Navigator.of(context).pop(true); },
onPressed: () { Navigator.of(context)!.pop(true); },
),
TextButton(
child: const Text('NO'),
onPressed: () { Navigator.of(context).pop(false); },
onPressed: () { Navigator.of(context)!.pop(false); },
),
],
);
},
) ?? false;
) as Future<bool>);
}
@override
@@ -195,7 +195,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
hintText: 'What do people call you?',
labelText: 'Name *',
),
onSaved: (String value) { person.name = value; },
onSaved: (String? value) { person.name = value; },
validator: _validateName,
),
const SizedBox(height: 24.0),
@@ -209,7 +209,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
prefixText: '+1',
),
keyboardType: TextInputType.phone,
onSaved: (String value) { person.phoneNumber = value; },
onSaved: (String? value) { person.phoneNumber = value; },
validator: _validatePhoneNumber,
// TextInputFormatters are applied in sequence.
inputFormatters: <TextInputFormatter> [
@@ -228,7 +228,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
labelText: 'E-mail',
),
keyboardType: TextInputType.emailAddress,
onSaved: (String value) { person.email = value; },
onSaved: (String? value) { person.email = value; },
),
const SizedBox(height: 24.0),
TextFormField(
@@ -265,7 +265,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
),
const SizedBox(height: 24.0),
TextFormField(
enabled: person.password != null && person.password.isNotEmpty,
enabled: person.password.isNotEmpty,
decoration: const InputDecoration(
border: UnderlineInputBorder(),
filled: true,

View File

@@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
class PestoDemo extends StatelessWidget {
const PestoDemo({ Key key }) : super(key: key);
const PestoDemo({ Key? key }) : super(key: key);
static const String routeName = '/pesto';
@@ -21,7 +21,7 @@ const double _kAppBarHeight = 128.0;
const double _kFabHalfSize = 28.0; // TODO(mpcomplete): needs to adapt to screen size
const double _kRecipePageMaxWidth = 500.0;
final Set<Recipe> _favoriteRecipes = <Recipe>{};
final Set<Recipe?> _favoriteRecipes = <Recipe?>{};
final ThemeData _kTheme = ThemeData(
brightness: Brightness.light,
@@ -46,10 +46,10 @@ class PestoFavorites extends StatelessWidget {
class PestoStyle extends TextStyle {
const PestoStyle({
double fontSize = 12.0,
FontWeight fontWeight,
FontWeight? fontWeight,
Color color = Colors.black87,
double letterSpacing,
double height,
double? letterSpacing,
double? height,
}) : super(
inherit: false,
color: color,
@@ -64,9 +64,9 @@ class PestoStyle extends TextStyle {
// Displays a grid of recipe cards.
class RecipeGridPage extends StatefulWidget {
const RecipeGridPage({ Key key, this.recipes }) : super(key: key);
const RecipeGridPage({ Key? key, this.recipes }) : super(key: key);
final List<Recipe> recipes;
final List<Recipe?>? recipes;
@override
_RecipeGridPageState createState() => _RecipeGridPageState();
@@ -89,7 +89,7 @@ class _RecipeGridPageState extends State<RecipeGridPage> {
},
),
body: CustomScrollView(
semanticChildCount: widget.recipes.length,
semanticChildCount: widget.recipes!.length,
slivers: <Widget>[
_buildAppBar(context, statusBarHeight),
_buildBody(context, statusBarHeight),
@@ -127,7 +127,7 @@ class _RecipeGridPageState extends State<RecipeGridPage> {
bottom: extraPadding,
),
child: Center(
child: PestoLogo(height: logoHeight, t: t.clamp(0.0, 1.0) as double),
child: PestoLogo(height: logoHeight, t: t.clamp(0.0, 1.0)),
),
);
},
@@ -153,13 +153,13 @@ class _RecipeGridPageState extends State<RecipeGridPage> {
),
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
final Recipe recipe = widget.recipes[index];
final Recipe? recipe = widget.recipes![index];
return RecipeCard(
recipe: recipe,
onTap: () { showRecipePage(context, recipe); },
);
},
childCount: widget.recipes.length,
childCount: widget.recipes!.length,
),
),
);
@@ -172,7 +172,7 @@ class _RecipeGridPageState extends State<RecipeGridPage> {
));
}
void showRecipePage(BuildContext context, Recipe recipe) {
void showRecipePage(BuildContext context, Recipe? recipe) {
Navigator.push(context, MaterialPageRoute<void>(
settings: const RouteSettings(name: '/pesto/recipe'),
builder: (BuildContext context) {
@@ -188,8 +188,8 @@ class _RecipeGridPageState extends State<RecipeGridPage> {
class PestoLogo extends StatefulWidget {
const PestoLogo({this.height, this.t});
final double height;
final double t;
final double? height;
final double? t;
@override
_PestoLogoState createState() => _PestoLogoState();
@@ -217,7 +217,7 @@ class _PestoLogoState extends State<PestoLogo> {
return Semantics(
namesRoute: true,
child: Transform(
transform: Matrix4.identity()..scale(widget.height / kLogoHeight),
transform: Matrix4.identity()..scale(widget.height! / kLogoHeight),
alignment: Alignment.topCenter,
child: SizedBox(
width: kLogoWidth,
@@ -225,7 +225,7 @@ class _PestoLogoState extends State<PestoLogo> {
clipBehavior: Clip.none,
children: <Widget>[
Positioned.fromRect(
rect: _imageRectTween.lerp(widget.t),
rect: _imageRectTween.lerp(widget.t!)!,
child: Image.asset(
_kSmallLogoImage,
package: _kGalleryAssetsPackage,
@@ -233,9 +233,9 @@ class _PestoLogoState extends State<PestoLogo> {
),
),
Positioned.fromRect(
rect: _textRectTween.lerp(widget.t),
rect: _textRectTween.lerp(widget.t!)!,
child: Opacity(
opacity: _textOpacity.transform(widget.t),
opacity: _textOpacity.transform(widget.t!),
child: Text('PESTO', style: titleStyle, textAlign: TextAlign.center),
),
),
@@ -249,10 +249,10 @@ class _PestoLogoState extends State<PestoLogo> {
// A card with the recipe's image, author, and title.
class RecipeCard extends StatelessWidget {
const RecipeCard({ Key key, this.recipe, this.onTap }) : super(key: key);
const RecipeCard({ Key? key, this.recipe, this.onTap }) : super(key: key);
final Recipe recipe;
final VoidCallback onTap;
final Recipe? recipe;
final VoidCallback? onTap;
TextStyle get titleStyle => const PestoStyle(fontSize: 24.0, fontWeight: FontWeight.w600);
TextStyle get authorStyle => const PestoStyle(fontWeight: FontWeight.w500, color: Colors.black54);
@@ -266,14 +266,14 @@ class RecipeCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Hero(
tag: 'packages/$_kGalleryAssetsPackage/${recipe.imagePath}',
tag: 'packages/$_kGalleryAssetsPackage/${recipe!.imagePath}',
child: AspectRatio(
aspectRatio: 4.0 / 3.0,
child: Image.asset(
recipe.imagePath,
package: recipe.imagePackage,
recipe!.imagePath!,
package: recipe!.imagePackage,
fit: BoxFit.cover,
semanticLabel: recipe.name,
semanticLabel: recipe!.name,
),
),
),
@@ -283,8 +283,8 @@ class RecipeCard extends StatelessWidget {
Padding(
padding: const EdgeInsets.all(16.0),
child: Image.asset(
recipe.ingredientsImagePath,
package: recipe.ingredientsImagePackage,
recipe!.ingredientsImagePath!,
package: recipe!.ingredientsImagePackage,
width: 48.0,
height: 48.0,
),
@@ -294,8 +294,8 @@ class RecipeCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(recipe.name, style: titleStyle, softWrap: false, overflow: TextOverflow.ellipsis),
Text(recipe.author, style: authorStyle),
Text(recipe!.name!, style: titleStyle, softWrap: false, overflow: TextOverflow.ellipsis),
Text(recipe!.author!, style: authorStyle),
],
),
),
@@ -311,9 +311,9 @@ class RecipeCard extends StatelessWidget {
// Displays one recipe. Includes the recipe sheet with a background image.
class RecipePage extends StatefulWidget {
const RecipePage({ Key key, this.recipe }) : super(key: key);
const RecipePage({ Key? key, this.recipe }) : super(key: key);
final Recipe recipe;
final Recipe? recipe;
@override
_RecipePageState createState() => _RecipePageState();
@@ -342,10 +342,10 @@ class _RecipePageState extends State<RecipePage> {
right: 0.0,
height: appBarHeight + _kFabHalfSize,
child: Hero(
tag: 'packages/$_kGalleryAssetsPackage/${widget.recipe.imagePath}',
tag: 'packages/$_kGalleryAssetsPackage/${widget.recipe!.imagePath}',
child: Image.asset(
widget.recipe.imagePath,
package: widget.recipe.imagePackage,
widget.recipe!.imagePath!,
package: widget.recipe!.imagePackage,
fit: fullWidth ? BoxFit.fitWidth : BoxFit.cover,
),
),
@@ -429,7 +429,7 @@ class _RecipePageState extends State<RecipePage> {
/// Displays the recipe's name and instructions.
class RecipeSheet extends StatelessWidget {
RecipeSheet({ Key key, this.recipe }) : super(key: key);
RecipeSheet({ Key? key, this.recipe }) : super(key: key);
final TextStyle titleStyle = const PestoStyle(fontSize: 34.0);
final TextStyle descriptionStyle = const PestoStyle(fontSize: 15.0, color: Colors.black54, height: 24.0/15.0);
@@ -437,7 +437,7 @@ class RecipeSheet extends StatelessWidget {
final TextStyle itemAmountStyle = PestoStyle(fontSize: 15.0, color: _kTheme.primaryColor, height: 24.0/15.0);
final TextStyle headingStyle = const PestoStyle(fontSize: 16.0, fontWeight: FontWeight.bold, height: 24.0/15.0);
final Recipe recipe;
final Recipe? recipe;
@override
Widget build(BuildContext context) {
@@ -457,8 +457,8 @@ class RecipeSheet extends StatelessWidget {
TableCell(
verticalAlignment: TableCellVerticalAlignment.middle,
child: Image.asset(
recipe.ingredientsImagePath,
package: recipe.ingredientsImagePackage,
recipe!.ingredientsImagePath!,
package: recipe!.ingredientsImagePackage,
width: 32.0,
height: 32.0,
alignment: Alignment.centerLeft,
@@ -467,7 +467,7 @@ class RecipeSheet extends StatelessWidget {
),
TableCell(
verticalAlignment: TableCellVerticalAlignment.middle,
child: Text(recipe.name, style: titleStyle),
child: Text(recipe!.name!, style: titleStyle),
),
]
),
@@ -476,7 +476,7 @@ class RecipeSheet extends StatelessWidget {
const SizedBox(),
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 4.0),
child: Text(recipe.description, style: descriptionStyle),
child: Text(recipe!.description!, style: descriptionStyle),
),
]
),
@@ -489,8 +489,8 @@ class RecipeSheet extends StatelessWidget {
),
]
),
...recipe.ingredients.map<TableRow>((RecipeIngredient ingredient) {
return _buildItemRow(ingredient.amount, ingredient.description);
...recipe!.ingredients!.map<TableRow>((RecipeIngredient ingredient) {
return _buildItemRow(ingredient.amount!, ingredient.description!);
}),
TableRow(
children: <Widget>[
@@ -501,8 +501,8 @@ class RecipeSheet extends StatelessWidget {
),
]
),
...recipe.steps.map<TableRow>((RecipeStep step) {
return _buildItemRow(step.duration ?? '', step.description);
...recipe!.steps!.map<TableRow>((RecipeStep step) {
return _buildItemRow(step.duration ?? '', step.description!);
}),
],
),
@@ -540,29 +540,29 @@ class Recipe {
this.steps,
});
final String name;
final String author;
final String description;
final String imagePath;
final String imagePackage;
final String ingredientsImagePath;
final String ingredientsImagePackage;
final List<RecipeIngredient> ingredients;
final List<RecipeStep> steps;
final String? name;
final String? author;
final String? description;
final String? imagePath;
final String? imagePackage;
final String? ingredientsImagePath;
final String? ingredientsImagePackage;
final List<RecipeIngredient>? ingredients;
final List<RecipeStep>? steps;
}
class RecipeIngredient {
const RecipeIngredient({this.amount, this.description});
final String amount;
final String description;
final String? amount;
final String? description;
}
class RecipeStep {
const RecipeStep({this.duration, this.description});
final String duration;
final String description;
final String? duration;
final String? description;
}
const List<Recipe> kPestoRecipes = <Recipe>[

View File

@@ -20,7 +20,7 @@ class ShrineApp extends StatefulWidget {
class _ShrineAppState extends State<ShrineApp> with SingleTickerProviderStateMixin {
// Controller to coordinate both the opening/closing of backdrop and sliding
// of expanding bottom sheet
AnimationController _controller;
late AnimationController _controller;
@override
void initState() {
@@ -55,7 +55,7 @@ class _ShrineAppState extends State<ShrineApp> with SingleTickerProviderStateMix
}
}
Route<dynamic> _getRoute(RouteSettings settings) {
Route<dynamic>? _getRoute(RouteSettings settings) {
if (settings.name != '/login') {
return null;
}
@@ -98,11 +98,11 @@ ThemeData _buildShrineTheme() {
TextTheme _buildShrineTextTheme(TextTheme base) {
return base.copyWith(
headline5: base.headline5.copyWith(fontWeight: FontWeight.w500),
headline6: base.headline6.copyWith(fontSize: 18.0),
caption: base.caption.copyWith(fontWeight: FontWeight.w400, fontSize: 14.0),
bodyText1: base.bodyText1.copyWith(fontWeight: FontWeight.w500, fontSize: 16.0),
button: base.button.copyWith(fontWeight: FontWeight.w500, fontSize: 14.0),
headline5: base.headline5!.copyWith(fontWeight: FontWeight.w500),
headline6: base.headline6!.copyWith(fontSize: 18.0),
caption: base.caption!.copyWith(fontWeight: FontWeight.w400, fontSize: 14.0),
bodyText1: base.bodyText1!.copyWith(fontWeight: FontWeight.w500, fontSize: 16.0),
button: base.button!.copyWith(fontWeight: FontWeight.w500, fontSize: 14.0),
).apply(
fontFamily: 'Raleway',
displayColor: kShrineBrown900,

View File

@@ -3,7 +3,6 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
import 'package:flutter_gallery/demo/shrine/login.dart';
@@ -15,37 +14,37 @@ const double _kPeakVelocityProgress = 0.379146;
class _TappableWhileStatusIs extends StatefulWidget {
const _TappableWhileStatusIs(
this.status, {
Key key,
Key? key,
this.controller,
this.child,
}) : super(key: key);
final AnimationController controller;
final AnimationController? controller;
final AnimationStatus status;
final Widget child;
final Widget? child;
@override
_TappableWhileStatusIsState createState() => _TappableWhileStatusIsState();
}
class _TappableWhileStatusIsState extends State<_TappableWhileStatusIs> {
bool _active;
bool? _active;
@override
void initState() {
super.initState();
widget.controller.addStatusListener(_handleStatusChange);
_active = widget.controller.status == widget.status;
widget.controller!.addStatusListener(_handleStatusChange);
_active = widget.controller!.status == widget.status;
}
@override
void dispose() {
widget.controller.removeStatusListener(_handleStatusChange);
widget.controller!.removeStatusListener(_handleStatusChange);
super.dispose();
}
void _handleStatusChange(AnimationStatus status) {
final bool value = widget.controller.status == widget.status;
final bool value = widget.controller!.status == widget.status;
if (_active != value) {
setState(() {
_active = value;
@@ -56,11 +55,11 @@ class _TappableWhileStatusIsState extends State<_TappableWhileStatusIs> {
@override
Widget build(BuildContext context) {
Widget child = AbsorbPointer(
absorbing: !_active,
absorbing: !_active!,
child: widget.child,
);
if (!_active) {
if (!_active!) {
child = FocusScope(
canRequestFocus: false,
debugLabel: '$_TappableWhileStatusIs',
@@ -73,13 +72,13 @@ class _TappableWhileStatusIsState extends State<_TappableWhileStatusIs> {
class _FrontLayer extends StatelessWidget {
const _FrontLayer({
Key key,
Key? key,
this.onTap,
this.child,
}) : super(key: key);
final VoidCallback onTap;
final Widget child;
final VoidCallback? onTap;
final Widget? child;
@override
Widget build(BuildContext context) {
@@ -100,7 +99,7 @@ class _FrontLayer extends StatelessWidget {
),
),
Expanded(
child: child,
child: child!,
),
],
),
@@ -110,16 +109,14 @@ class _FrontLayer extends StatelessWidget {
class _BackdropTitle extends AnimatedWidget {
const _BackdropTitle({
Key key,
Animation<double> listenable,
Key? key,
required Animation<double> listenable,
this.onPress,
@required this.frontTitle,
@required this.backTitle,
}) : assert(frontTitle != null),
assert(backTitle != null),
super(key: key, listenable: listenable);
required this.frontTitle,
required this.backTitle,
}) : super(key: key, listenable: listenable);
final void Function() onPress;
final void Function()? onPress;
final Widget frontTitle;
final Widget backTitle;
@@ -131,7 +128,7 @@ class _BackdropTitle extends AnimatedWidget {
);
return DefaultTextStyle(
style: Theme.of(context).primaryTextTheme.headline6,
style: Theme.of(context).primaryTextTheme.headline6!,
softWrap: false,
overflow: TextOverflow.ellipsis,
child: Row(children: <Widget>[
@@ -201,16 +198,12 @@ class _BackdropTitle extends AnimatedWidget {
/// front or back layer is showing.
class Backdrop extends StatefulWidget {
const Backdrop({
@required this.frontLayer,
@required this.backLayer,
@required this.frontTitle,
@required this.backTitle,
@required this.controller,
}) : assert(frontLayer != null),
assert(backLayer != null),
assert(frontTitle != null),
assert(backTitle != null),
assert(controller != null);
required this.frontLayer,
required this.backLayer,
required this.frontTitle,
required this.backTitle,
required this.controller,
});
final Widget frontLayer;
final Widget backLayer;
@@ -224,8 +217,8 @@ class Backdrop extends StatefulWidget {
class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin {
final GlobalKey _backdropKey = GlobalKey(debugLabel: 'Backdrop');
AnimationController _controller;
Animation<RelativeRect> _layerAnimation;
AnimationController? _controller;
late Animation<RelativeRect> _layerAnimation;
@override
void initState() {
@@ -235,19 +228,19 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
@override
void dispose() {
_controller.dispose();
_controller!.dispose();
super.dispose();
}
bool get _frontLayerVisible {
final AnimationStatus status = _controller.status;
final AnimationStatus status = _controller!.status;
return status == AnimationStatus.completed || status == AnimationStatus.forward;
}
void _toggleBackdropLayerVisibility() {
// Call setState here to update layerAnimation if that's necessary
setState(() {
_frontLayerVisible ? _controller.reverse() : _controller.forward();
_frontLayerVisible ? _controller!.reverse() : _controller!.forward();
});
}
@@ -267,7 +260,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
firstWeight = _kPeakVelocityTime;
secondWeight = 1.0 - _kPeakVelocityTime;
animation = CurvedAnimation(
parent: _controller.view,
parent: _controller!.view,
curve: const Interval(0.0, 0.78),
);
} else {
@@ -276,7 +269,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
secondCurve = _kAccelerateCurve.flipped;
firstWeight = 1.0 - _kPeakVelocityTime;
secondWeight = _kPeakVelocityTime;
animation = _controller.view;
animation = _controller!.view;
}
return TweenSequence<RelativeRect>(
@@ -351,7 +344,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
elevation: 0.0,
titleSpacing: 0.0,
title: _BackdropTitle(
listenable: _controller.view,
listenable: _controller!.view,
onPress: _toggleBackdropLayerVisibility,
frontTitle: widget.frontTitle,
backTitle: widget.backTitle,

View File

@@ -11,22 +11,22 @@ import 'package:flutter_gallery/demo/shrine/model/product.dart';
class CategoryMenuPage extends StatelessWidget {
const CategoryMenuPage({
Key key,
Key? key,
this.onCategoryTap,
}) : super(key: key);
final VoidCallback onCategoryTap;
final VoidCallback? onCategoryTap;
Widget _buildCategory(Category category, BuildContext context) {
final String categoryString = category.toString().replaceAll('Category.', '').toUpperCase();
final ThemeData theme = Theme.of(context);
return ScopedModelDescendant<AppStateModel>(
builder: (BuildContext context, Widget child, AppStateModel model) =>
builder: (BuildContext context, Widget? child, AppStateModel model) =>
GestureDetector(
onTap: () {
model.setCategory(category);
if (onCategoryTap != null) {
onCategoryTap();
onCategoryTap!();
}
},
child: model.selectedCategory == category
@@ -50,7 +50,7 @@ class CategoryMenuPage extends StatelessWidget {
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Text(
categoryString,
style: theme.textTheme.bodyText1.copyWith(
style: theme.textTheme.bodyText1!.copyWith(
color: kShrineBrown900.withAlpha(153)
),
textAlign: TextAlign.center,

View File

@@ -4,7 +4,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:meta/meta.dart';
import 'package:scoped_model/scoped_model.dart';
import 'package:flutter_gallery/demo/shrine/colors.dart';
@@ -26,19 +25,16 @@ const double _kCornerRadius = 24.0;
const double _kWidthForCartIcon = 64.0;
class ExpandingBottomSheet extends StatefulWidget {
const ExpandingBottomSheet({Key key, @required this.hideController})
: assert(hideController != null),
super(key: key);
const ExpandingBottomSheet({Key? key, required this.hideController})
: super(key: key);
final AnimationController hideController;
@override
_ExpandingBottomSheetState createState() => _ExpandingBottomSheetState();
static _ExpandingBottomSheetState of(BuildContext context, {bool isNullOk = false}) {
assert(isNullOk != null);
assert(context != null);
final _ExpandingBottomSheetState result = context.findAncestorStateOfType<_ExpandingBottomSheetState>();
static _ExpandingBottomSheetState? of(BuildContext context, {bool isNullOk = false}) {
final _ExpandingBottomSheetState? result = context.findAncestorStateOfType<_ExpandingBottomSheetState>();
if (isNullOk || result != null) {
return result;
}
@@ -53,11 +49,11 @@ class ExpandingBottomSheet extends StatefulWidget {
// curve formula. It's quintic, not cubic. But it _can_ be expressed as one
// curve followed by another, which we do here.
Animation<T> _getEmphasizedEasingAnimation<T>({
@required T begin,
@required T peak,
@required T end,
@required bool isForward,
@required Animation<double> parent,
required T begin,
required T peak,
required T end,
required bool isForward,
required Animation<double> parent,
}) {
Curve firstCurve;
Curve secondCurve;
@@ -98,7 +94,7 @@ Animation<T> _getEmphasizedEasingAnimation<T>({
// Calculates the value where two double Animations should be joined. Used by
// callers of _getEmphasisedEasing<double>().
double _getPeakPoint({double begin, double end}) {
double _getPeakPoint({required double begin, required double end}) {
return begin + (end - begin) * _kPeakVelocityProgress;
}
@@ -111,15 +107,15 @@ class _ExpandingBottomSheetState extends State<ExpandingBottomSheet> with Ticker
double _width = _kWidthForCartIcon;
// Controller for the opening and closing of the ExpandingBottomSheet
AnimationController _controller;
late AnimationController _controller;
// Animations for the opening and closing of the ExpandingBottomSheet
Animation<double> _widthAnimation;
Animation<double> _heightAnimation;
Animation<double> _thumbnailOpacityAnimation;
Animation<double> _cartOpacityAnimation;
Animation<double> _shapeAnimation;
Animation<Offset> _slideAnimation;
late Animation<double> _widthAnimation;
late Animation<double> _heightAnimation;
late Animation<double> _thumbnailOpacityAnimation;
late Animation<double> _cartOpacityAnimation;
late Animation<double> _shapeAnimation;
late Animation<Offset> _slideAnimation;
@override
void initState() {
@@ -308,7 +304,7 @@ class _ExpandingBottomSheetState extends State<ExpandingBottomSheet> with Ticker
);
}
Widget _buildCart(BuildContext context, Widget child) {
Widget _buildCart(BuildContext context, Widget? child) {
// numProducts is the number of different products in the cart (does not
// include multiples of the same product).
final AppStateModel model = ScopedModel.of<AppStateModel>(context);
@@ -349,7 +345,7 @@ class _ExpandingBottomSheetState extends State<ExpandingBottomSheet> with Ticker
}
// Builder for the hide and reveal animation when the backdrop opens and closes
Widget _buildSlideAnimation(BuildContext context, Widget child) {
Widget _buildSlideAnimation(BuildContext context, Widget? child) {
_slideAnimation = _getEmphasizedEasingAnimation(
begin: const Offset(1.0, 0.0),
peak: const Offset(_kPeakVelocityProgress, 0.0),
@@ -393,7 +389,7 @@ class _ExpandingBottomSheetState extends State<ExpandingBottomSheet> with Ticker
behavior: HitTestBehavior.opaque,
onTap: open,
child: ScopedModelDescendant<AppStateModel>(
builder: (BuildContext context, Widget child, AppStateModel model) {
builder: (BuildContext context, Widget? child, AppStateModel model) {
return AnimatedBuilder(
builder: _buildCart,
animation: _controller,
@@ -417,10 +413,10 @@ class _ProductThumbnailRowState extends State<ProductThumbnailRow> {
// _list represents what's currently on screen. If _internalList updates,
// it will need to be updated to match it.
_ListModel _list;
late _ListModel _list;
// _internalList represents the list as it is updated by the AppStateModel.
List<int> _internalList;
late List<int> _internalList;
@override
void initState() {
@@ -436,7 +432,6 @@ class _ProductThumbnailRowState extends State<ProductThumbnailRow> {
Product _productWithId(int productId) {
final AppStateModel model = ScopedModel.of<AppStateModel>(context);
final Product product = model.getProductById(productId);
assert(product != null);
return product;
}
@@ -510,7 +505,7 @@ class _ProductThumbnailRowState extends State<ProductThumbnailRow> {
Widget build(BuildContext context) {
_updateLists();
return ScopedModelDescendant<AppStateModel>(
builder: (BuildContext context, Widget child, AppStateModel model) => _buildAnimatedList(),
builder: (BuildContext context, Widget? child, AppStateModel model) => _buildAnimatedList(),
);
}
}
@@ -529,7 +524,7 @@ class ExtraProductsNumber extends StatelessWidget {
final int numProducts = products.length;
if (numProducts > 3) {
for (int i = 3; i < numProducts; i++) {
overflow += productMap[products[i]];
overflow += productMap[products[i]]!;
}
}
return overflow;
@@ -553,7 +548,7 @@ class ExtraProductsNumber extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ScopedModelDescendant<AppStateModel>(
builder: (BuildContext builder, Widget child, AppStateModel model) => _buildOverflow(model, context),
builder: (BuildContext builder, Widget? child, AppStateModel model) => _buildOverflow(model, context),
);
}
}
@@ -594,18 +589,16 @@ class ProductThumbnail extends StatelessWidget {
// _ListModel manipulates an internal list and an AnimatedList
class _ListModel {
_ListModel({
@required this.listKey,
@required this.removedItemBuilder,
Iterable<int> initialItems,
}) : assert(listKey != null),
assert(removedItemBuilder != null),
_items = initialItems?.toList() ?? <int>[];
required this.listKey,
required this.removedItemBuilder,
Iterable<int>? initialItems,
}) : _items = initialItems?.toList() ?? <int>[];
final GlobalKey<AnimatedListState> listKey;
final Widget Function(int item, BuildContext context, Animation<double> animation) removedItemBuilder;
final List<int> _items;
AnimatedListState get _animatedList => listKey.currentState;
AnimatedListState? get _animatedList => listKey.currentState;
void add(int product) {
_insert(_items.length, product);
@@ -613,7 +606,7 @@ class _ListModel {
void _insert(int index, int item) {
_items.insert(index, item);
_animatedList.insertItem(index, duration: const Duration(milliseconds: 225));
_animatedList!.insertItem(index, duration: const Duration(milliseconds: 225));
}
void remove(int product) {
@@ -625,11 +618,9 @@ class _ListModel {
void _removeAt(int index) {
final int removedItem = _items.removeAt(index);
if (removedItem != null) {
_animatedList.removeItem(index, (BuildContext context, Animation<double> animation) {
return removedItemBuilder(removedItem, context, animation);
});
}
_animatedList!.removeItem(index, (BuildContext context, Animation<double> animation) {
return removedItemBuilder(removedItem, context, animation);
});
}
int get length => _items.length;

View File

@@ -19,7 +19,7 @@ class ProductPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ScopedModelDescendant<AppStateModel>(
builder: (BuildContext context, Widget child, AppStateModel model) {
builder: (BuildContext context, Widget? child, AppStateModel model) {
return AsymmetricView(products: model.getProducts());
});
}
@@ -29,17 +29,18 @@ class HomePage extends StatelessWidget {
const HomePage({
this.expandingBottomSheet,
this.backdrop,
Key key,
Key? key,
}) : super(key: key);
final ExpandingBottomSheet expandingBottomSheet;
final Backdrop backdrop;
final ExpandingBottomSheet? expandingBottomSheet;
final Backdrop? backdrop;
@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
backdrop,
if (backdrop != null)
backdrop!,
Align(child: expandingBottomSheet, alignment: Alignment.bottomRight),
],
);

View File

@@ -35,7 +35,7 @@ class _LoginPageState extends State<LoginPage> {
// The login screen is immediately displayed on top of the Shrine
// home screen using onGenerateRoute and so rootNavigator must be
// set to true in order to get out of Shrine completely.
Navigator.of(context, rootNavigator: true).pop();
Navigator.of(context, rootNavigator: true)!.pop();
},
),
),
@@ -95,7 +95,7 @@ class _LoginPageState extends State<LoginPage> {
// the Shrine home screen using onGenerateRoute and so
// rootNavigator must be set to true in order to get out
// of Shrine completely.
Navigator.of(context, rootNavigator: true).pop();
Navigator.of(context, rootNavigator: true)!.pop();
},
child: const Text('CANCEL'),
),
@@ -123,15 +123,15 @@ class _LoginPageState extends State<LoginPage> {
}
class PrimaryColorOverride extends StatelessWidget {
const PrimaryColorOverride({Key key, this.color, this.child}) : super(key: key);
const PrimaryColorOverride({Key? key, this.color, this.child}) : super(key: key);
final Color color;
final Widget child;
final Color? color;
final Widget? child;
@override
Widget build(BuildContext context) {
return Theme(
child: child,
child: child!,
data: Theme.of(context).copyWith(primaryColor: color),
);
}

View File

@@ -12,7 +12,7 @@ double _shippingCostPerItem = 7.0;
class AppStateModel extends Model {
// All the available products.
List<Product> _availableProducts;
List<Product>? _availableProducts;
// The currently selected category of products.
Category _selectedCategory = Category.all;
@@ -30,7 +30,7 @@ class AppStateModel extends Model {
// Totaled prices of the items in the cart.
double get subtotalCost {
return _productsInCart.keys
.map((int id) => _availableProducts[id].price * _productsInCart[id])
.map((int id) => _availableProducts![id].price * _productsInCart[id]!)
.fold(0.0, (double sum, int e) => sum + e);
}
@@ -52,9 +52,9 @@ class AppStateModel extends Model {
}
if (_selectedCategory == Category.all) {
return List<Product>.from(_availableProducts);
return List<Product>.from(_availableProducts!);
} else {
return _availableProducts
return _availableProducts!
.where((Product p) => p.category == _selectedCategory)
.toList();
}
@@ -62,10 +62,11 @@ class AppStateModel extends Model {
// Adds a product to the cart.
void addProductToCart(int productId) {
if (!_productsInCart.containsKey(productId)) {
final int? value = _productsInCart[productId];
if (value == null) {
_productsInCart[productId] = 1;
} else {
_productsInCart[productId]++;
_productsInCart[productId] = value+1;
}
notifyListeners();
@@ -73,11 +74,13 @@ class AppStateModel extends Model {
// Removes an item from the cart.
void removeItemFromCart(int productId) {
if (_productsInCart.containsKey(productId)) {
final int? value = _productsInCart[productId];
if (value != null) {
if (_productsInCart[productId] == 1) {
_productsInCart.remove(productId);
} else {
_productsInCart[productId]--;
_productsInCart[productId] = value - 1;
}
}
@@ -86,7 +89,7 @@ class AppStateModel extends Model {
// Returns the Product instance matching the provided id.
Product getProductById(int id) {
return _availableProducts.firstWhere((Product p) => p.id == id);
return _availableProducts!.firstWhere((Product p) => p.id == id);
}
// Removes everything from the cart.

View File

@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
enum Category {
all,
accessories,
@@ -13,16 +11,12 @@ enum Category {
class Product {
const Product({
@required this.category,
@required this.id,
@required this.isFeatured,
@required this.name,
@required this.price,
}) : assert(category != null),
assert(id != null),
assert(isFeatured != null),
assert(name != null),
assert(price != null);
required this.category,
required this.id,
required this.isFeatured,
required this.name,
required this.price,
});
final Category category;
final int id;

View File

@@ -41,7 +41,7 @@ class _ShoppingCartPageState extends State<ShoppingCartPage> {
body: SafeArea(
child: Container(
child: ScopedModelDescendant<AppStateModel>(
builder: (BuildContext context, Widget child, AppStateModel model) {
builder: (BuildContext context, Widget? child, AppStateModel model) {
return Stack(
children: <Widget>[
ListView(
@@ -52,12 +52,12 @@ class _ShoppingCartPageState extends State<ShoppingCartPage> {
width: _leftColumnWidth,
child: IconButton(
icon: const Icon(Icons.keyboard_arrow_down),
onPressed: () => ExpandingBottomSheet.of(context).close(),
onPressed: () => ExpandingBottomSheet.of(context)!.close(),
),
),
Text(
'CART',
style: localTheme.textTheme.subtitle1.copyWith(fontWeight: FontWeight.w600),
style: localTheme.textTheme.subtitle1!.copyWith(fontWeight: FontWeight.w600),
),
const SizedBox(width: 16.0),
Text('${model.totalCartQuantity} ITEMS'),
@@ -88,7 +88,7 @@ class _ShoppingCartPageState extends State<ShoppingCartPage> {
),
onPressed: () {
model.clearCart();
ExpandingBottomSheet.of(context).close();
ExpandingBottomSheet.of(context)!.close();
},
),
),
@@ -105,12 +105,12 @@ class _ShoppingCartPageState extends State<ShoppingCartPage> {
class ShoppingCartSummary extends StatelessWidget {
const ShoppingCartSummary({this.model});
final AppStateModel model;
final AppStateModel? model;
@override
Widget build(BuildContext context) {
final TextStyle smallAmountStyle = Theme.of(context).textTheme.bodyText2.copyWith(color: kShrineBrown600);
final TextStyle largeAmountStyle = Theme.of(context).textTheme.headline4;
final TextStyle smallAmountStyle = Theme.of(context).textTheme.bodyText2!.copyWith(color: kShrineBrown600);
final TextStyle? largeAmountStyle = Theme.of(context).textTheme.headline4;
final NumberFormat formatter = NumberFormat.simpleCurrency(
decimalDigits: 2,
locale: Localizations.localeOf(context).toString(),
@@ -131,7 +131,7 @@ class ShoppingCartSummary extends StatelessWidget {
child: Text('TOTAL'),
),
Text(
formatter.format(model.totalCost),
formatter.format(model!.totalCost),
style: largeAmountStyle,
),
],
@@ -143,7 +143,7 @@ class ShoppingCartSummary extends StatelessWidget {
child: Text('Subtotal:'),
),
Text(
formatter.format(model.subtotalCost),
formatter.format(model!.subtotalCost),
style: smallAmountStyle,
),
],
@@ -155,7 +155,7 @@ class ShoppingCartSummary extends StatelessWidget {
child: Text('Shipping:'),
),
Text(
formatter.format(model.shippingCost),
formatter.format(model!.shippingCost),
style: smallAmountStyle,
),
],
@@ -167,7 +167,7 @@ class ShoppingCartSummary extends StatelessWidget {
child: Text('Tax:'),
),
Text(
formatter.format(model.tax),
formatter.format(model!.tax),
style: smallAmountStyle,
),
],
@@ -183,14 +183,14 @@ class ShoppingCartSummary extends StatelessWidget {
class ShoppingCartRow extends StatelessWidget {
const ShoppingCartRow({
@required this.product,
@required this.quantity,
required this.product,
required this.quantity,
this.onPressed,
});
final Product product;
final int quantity;
final VoidCallback onPressed;
final int? quantity;
final VoidCallback? onPressed;
@override
Widget build(BuildContext context) {
@@ -243,7 +243,7 @@ class ShoppingCartRow extends StatelessWidget {
),
Text(
product.name,
style: localTheme.textTheme.subtitle1.copyWith(fontWeight: FontWeight.w600),
style: localTheme.textTheme.subtitle1!.copyWith(fontWeight: FontWeight.w600),
),
],
),

View File

@@ -8,12 +8,12 @@ import 'package:flutter_gallery/demo/shrine/model/product.dart';
import 'package:flutter_gallery/demo/shrine/supplemental/product_columns.dart';
class AsymmetricView extends StatelessWidget {
const AsymmetricView({Key key, this.products}) : super(key: key);
const AsymmetricView({Key? key, this.products}) : super(key: key);
final List<Product> products;
final List<Product>? products;
List<Container> _buildColumns(BuildContext context) {
if (products == null || products.isEmpty) {
if (products == null || products!.isEmpty) {
return const <Container>[];
}
@@ -25,23 +25,23 @@ class AsymmetricView extends StatelessWidget {
// some kinda awkward math so we use _evenCasesIndex and _oddCasesIndex as
// helpers for creating the index of the product list that will correspond
// to the index of the list of columns.
return List<Container>.generate(_listItemCount(products.length), (int index) {
return List<Container>.generate(_listItemCount(products!.length), (int index) {
double width = .59 * MediaQuery.of(context).size.width;
Widget column;
if (index.isEven) {
/// Even cases
final int bottom = _evenCasesIndex(index);
column = TwoProductCardColumn(
bottom: products[bottom],
top: products.length - 1 >= bottom + 1
? products[bottom + 1]
bottom: products![bottom],
top: products!.length - 1 >= bottom + 1
? products![bottom + 1]
: null,
);
width += 32.0;
} else {
/// Odd cases
column = OneProductCardColumn(
product: products[_oddCasesIndex(index)],
product: products![_oddCasesIndex(index)],
);
}
return Container(

View File

@@ -21,10 +21,10 @@ class CutCornersBorder extends OutlineInputBorder {
@override
CutCornersBorder copyWith({
BorderSide borderSide,
BorderRadius borderRadius,
double gapPadding,
double cut,
BorderSide? borderSide,
BorderRadius? borderRadius,
double? gapPadding,
double? cut,
}) {
return CutCornersBorder(
borderSide: borderSide ?? this.borderSide,
@@ -37,11 +37,11 @@ class CutCornersBorder extends OutlineInputBorder {
final double cut;
@override
ShapeBorder lerpFrom(ShapeBorder a, double t) {
ShapeBorder? lerpFrom(ShapeBorder? a, double t) {
if (a is CutCornersBorder) {
final CutCornersBorder outline = a;
return CutCornersBorder(
borderRadius: BorderRadius.lerp(outline.borderRadius, borderRadius, t),
borderRadius: BorderRadius.lerp(outline.borderRadius, borderRadius, t)!,
borderSide: BorderSide.lerp(outline.borderSide, borderSide, t),
cut: cut,
gapPadding: outline.gapPadding,
@@ -51,11 +51,11 @@ class CutCornersBorder extends OutlineInputBorder {
}
@override
ShapeBorder lerpTo(ShapeBorder b, double t) {
ShapeBorder? lerpTo(ShapeBorder? b, double t) {
if (b is CutCornersBorder) {
final CutCornersBorder outline = b;
return CutCornersBorder(
borderRadius: BorderRadius.lerp(borderRadius, outline.borderRadius, t),
borderRadius: BorderRadius.lerp(borderRadius, outline.borderRadius, t)!,
borderSide: BorderSide.lerp(borderSide, outline.borderSide, t),
cut: cut,
gapPadding: outline.gapPadding,
@@ -64,10 +64,10 @@ class CutCornersBorder extends OutlineInputBorder {
return super.lerpTo(b, t);
}
Path _notchedCornerPath(Rect center, [double start = 0.0, double extent = 0.0]) {
Path _notchedCornerPath(Rect center, [double start = 0.0, double? extent = 0.0]) {
final Path path = Path();
if (start > 0.0 || extent > 0.0) {
path.relativeMoveTo(extent + start, center.top);
if (start > 0.0 || extent! > 0.0) {
path.relativeMoveTo(extent! + start, center.top);
_notchedSidesAndBottom(center, path);
path..lineTo(center.left + cut, center.top)..lineTo(start, center.top);
} else {
@@ -93,12 +93,11 @@ class CutCornersBorder extends OutlineInputBorder {
void paint(
Canvas canvas,
Rect rect, {
double gapStart,
double? gapStart,
double gapExtent = 0.0,
double gapPercentage = 0.0,
TextDirection textDirection,
TextDirection? textDirection,
}) {
assert(gapExtent != null);
assert(gapPercentage >= 0.0 && gapPercentage <= 1.0);
final Paint paint = borderSide.toPaint();
@@ -106,10 +105,10 @@ class CutCornersBorder extends OutlineInputBorder {
if (gapStart == null || gapExtent <= 0.0 || gapPercentage == 0.0) {
canvas.drawPath(_notchedCornerPath(outer.middleRect), paint);
} else {
final double extent = lerpDouble(0.0, gapExtent + gapPadding * 2.0, gapPercentage);
final double? extent = lerpDouble(0.0, gapExtent + gapPadding * 2.0, gapPercentage);
switch (textDirection) {
case TextDirection.rtl: {
final Path path = _notchedCornerPath(outer.middleRect, gapStart + gapPadding - extent, extent);
final Path path = _notchedCornerPath(outer.middleRect, gapStart + gapPadding - extent!, extent);
canvas.drawPath(path, paint);
break;
}
@@ -118,6 +117,8 @@ class CutCornersBorder extends OutlineInputBorder {
canvas.drawPath(path, paint);
break;
}
default:
break;
}
}
}

View File

@@ -11,10 +11,10 @@ import 'package:flutter_gallery/demo/shrine/model/product.dart';
class ProductCard extends StatelessWidget {
const ProductCard({ this.imageAspectRatio = 33 / 49, this.product })
: assert(imageAspectRatio == null || imageAspectRatio > 0);
: assert(imageAspectRatio > 0);
final double imageAspectRatio;
final Product product;
final Product? product;
static const double kTextBoxHeight = 65.0;
@@ -28,16 +28,16 @@ class ProductCard extends StatelessWidget {
final ThemeData theme = Theme.of(context);
final Image imageWidget = Image.asset(
product.assetName,
package: product.assetPackage,
product!.assetName,
package: product!.assetPackage,
fit: BoxFit.cover,
);
return ScopedModelDescendant<AppStateModel>(
builder: (BuildContext context, Widget child, AppStateModel model) {
builder: (BuildContext context, Widget? child, AppStateModel model) {
return GestureDetector(
onTap: () {
model.addProductToCart(product.id);
model.addProductToCart(product!.id);
},
child: child,
);
@@ -60,7 +60,7 @@ class ProductCard extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Text(
product == null ? '' : product.name,
product == null ? '' : product!.name,
style: theme.textTheme.button,
softWrap: false,
overflow: TextOverflow.ellipsis,
@@ -68,7 +68,7 @@ class ProductCard extends StatelessWidget {
),
const SizedBox(height: 4.0),
Text(
product == null ? '' : formatter.format(product.price),
product == null ? '' : formatter.format(product!.price),
style: theme.textTheme.caption,
),
],

View File

@@ -9,11 +9,11 @@ import 'package:flutter_gallery/demo/shrine/supplemental/product_card.dart';
class TwoProductCardColumn extends StatelessWidget {
const TwoProductCardColumn({
@required this.bottom,
required this.bottom,
this.top,
}) : assert(bottom != null);
});
final Product bottom, top;
final Product? bottom, top;
@override
Widget build(BuildContext context) {
@@ -59,7 +59,7 @@ class TwoProductCardColumn extends StatelessWidget {
class OneProductCardColumn extends StatelessWidget {
const OneProductCardColumn({this.product});
final Product product;
final Product? product;
@override
Widget build(BuildContext context) {

View File

@@ -6,7 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gallery/demo/shrine/app.dart';
class ShrineDemo extends StatelessWidget {
const ShrineDemo({ Key key }) : super(key: key);
const ShrineDemo({ Key? key }) : super(key: key);
static const String routeName = '/shrine'; // Used by the Gallery app.

View File

@@ -9,7 +9,7 @@ import 'transformations_demo_edit_board_point.dart';
import 'transformations_demo_gesture_transformable.dart';
class TransformationsDemo extends StatefulWidget {
const TransformationsDemo({ Key key }) : super(key: key);
const TransformationsDemo({ Key? key }) : super(key: key);
static const String routeName = '/transformations';
@@ -107,7 +107,7 @@ class _TransformationsDemoState extends State<TransformationsDemo> {
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context)!.pop();
},
),
],
@@ -139,10 +139,10 @@ class _TransformationsDemoState extends State<TransformationsDemo> {
height: 150,
padding: const EdgeInsets.all(12.0),
child: EditBoardPoint(
boardPoint: _board.selected,
boardPoint: _board.selected!,
onColorSelection: (Color color) {
setState(() {
_board = _board.copyWithBoardPointColor(_board.selected, color);
_board = _board.copyWithBoardPointColor(_board.selected!, color);
Navigator.pop(context);
});
},
@@ -157,7 +157,7 @@ class _TransformationsDemoState extends State<TransformationsDemo> {
void _onTapUp(TapUpDetails details) {
final Offset scenePoint = details.globalPosition;
final BoardPoint boardPoint = _board.pointToBoardPoint(scenePoint);
final BoardPoint? boardPoint = _board.pointToBoardPoint(scenePoint);
setState(() {
_board = _board.copyWithSelected(boardPoint);
});
@@ -171,19 +171,19 @@ class BoardPainter extends CustomPainter {
this.board,
});
final Board board;
final Board? board;
@override
void paint(Canvas canvas, Size size) {
void drawBoardPoint(BoardPoint boardPoint) {
final Color color = boardPoint.color.withOpacity(
board.selected == boardPoint ? 0.2 : 1.0,
void drawBoardPoint(BoardPoint? boardPoint) {
final Color color = boardPoint!.color.withOpacity(
board!.selected == boardPoint ? 0.2 : 1.0,
);
final Vertices vertices = board.getVerticesForBoardPoint(boardPoint, color);
final Vertices vertices = board!.getVerticesForBoardPoint(boardPoint, color);
canvas.drawVertices(vertices, BlendMode.color, Paint());
}
board.forEach(drawBoardPoint);
board!.forEach(drawBoardPoint);
}
// We should repaint whenever the board changes, such as board.selected.

View File

@@ -11,13 +11,13 @@ import 'package:vector_math/vector_math_64.dart' show Vector3;
// The entire state of the hex board and abstraction to get information about
// it. Iterable so that all BoardPoints on the board can be iterated over.
@immutable
class Board extends Object with IterableMixin<BoardPoint> {
class Board extends Object with IterableMixin<BoardPoint?> {
Board({
@required this.boardRadius,
@required this.hexagonRadius,
@required this.hexagonMargin,
required this.boardRadius,
required this.hexagonRadius,
required this.hexagonMargin,
this.selected,
List<BoardPoint> boardPoints,
List<BoardPoint>? boardPoints,
}) : assert(boardRadius > 0),
assert(hexagonRadius > 0),
assert(hexagonMargin >= 0) {
@@ -43,7 +43,7 @@ class Board extends Object with IterableMixin<BoardPoint> {
_boardPoints.addAll(boardPoints);
} else {
// Generate boardPoints for a fresh board.
BoardPoint boardPoint = _getNextBoardPoint(null);
BoardPoint? boardPoint = _getNextBoardPoint(null);
while (boardPoint != null) {
_boardPoints.add(boardPoint);
boardPoint = _getNextBoardPoint(boardPoint);
@@ -55,11 +55,11 @@ class Board extends Object with IterableMixin<BoardPoint> {
final double hexagonRadius; // Pixel radius of a hexagon (center to vertex).
final double hexagonMargin; // Margin between hexagons.
final List<Offset> positionsForHexagonAtOrigin = <Offset>[];
final BoardPoint selected;
final BoardPoint? selected;
final List<BoardPoint> _boardPoints = <BoardPoint>[];
@override
Iterator<BoardPoint> get iterator => _BoardIterator(_boardPoints);
Iterator<BoardPoint?> get iterator => _BoardIterator(_boardPoints);
// For a given q axial coordinate, get the range of possible r values
// See the definition of BoardPoint for more information about hex grids and
@@ -81,7 +81,7 @@ class Board extends Object with IterableMixin<BoardPoint> {
// Get the BoardPoint that comes after the given BoardPoint. If given null,
// returns the origin BoardPoint. If given BoardPoint is the last, returns
// null.
BoardPoint _getNextBoardPoint (BoardPoint boardPoint) {
BoardPoint? _getNextBoardPoint (BoardPoint? boardPoint) {
// If before the first element.
if (boardPoint == null) {
return BoardPoint(-boardRadius, 0);
@@ -121,7 +121,7 @@ class Board extends Object with IterableMixin<BoardPoint> {
// Return the q,r BoardPoint for a point in the scene, where the origin is in
// the center of the board in both coordinate systems. If no BoardPoint at the
// location, return null.
BoardPoint pointToBoardPoint(Offset point) {
BoardPoint? pointToBoardPoint(Offset point) {
final BoardPoint boardPoint = BoardPoint(
((sqrt(3) / 3 * point.dx - 1 / 3 * point.dy) / hexagonRadius).round(),
((2 / 3 * point.dy) / hexagonRadius).round(),
@@ -160,7 +160,7 @@ class Board extends Object with IterableMixin<BoardPoint> {
}
// Return a new board with the given BoardPoint selected.
Board copyWithSelected(BoardPoint boardPoint) {
Board copyWithSelected(BoardPoint? boardPoint) {
if (selected == boardPoint) {
return this;
}
@@ -187,7 +187,7 @@ class Board extends Object with IterableMixin<BoardPoint> {
final List<BoardPoint> nextBoardPoints = List<BoardPoint>.from(_boardPoints);
nextBoardPoints[boardPointIndex] = nextBoardPoint;
final BoardPoint selectedBoardPoint = boardPoint == selected
final BoardPoint? selectedBoardPoint = boardPoint == selected
? nextBoardPoint
: selected;
return Board(
@@ -200,29 +200,30 @@ class Board extends Object with IterableMixin<BoardPoint> {
}
}
class _BoardIterator extends Iterator<BoardPoint> {
class _BoardIterator extends Iterator<BoardPoint?> {
_BoardIterator(this.boardPoints);
final List<BoardPoint> boardPoints;
int currentIndex;
int? currentIndex;
@override
BoardPoint current;
BoardPoint? current;
@override
bool moveNext() {
if (currentIndex == null) {
final int? index = currentIndex;
if (index == null) {
currentIndex = 0;
} else {
currentIndex++;
currentIndex = index + 1;
}
if (currentIndex >= boardPoints.length) {
if (currentIndex! >= boardPoints.length) {
current = null;
return false;
}
current = boardPoints[currentIndex];
current = boardPoints[currentIndex!];
return true;
}
}
@@ -231,9 +232,7 @@ class _BoardIterator extends Iterator<BoardPoint> {
@immutable
class _Range {
const _Range(this.min, this.max)
: assert(min != null),
assert(max != null),
assert(min <= max);
: assert(min <= max);
final int min;
final int max;

View File

@@ -8,15 +8,14 @@ import 'package:flutter/material.dart';
@immutable
class ColorPicker extends StatelessWidget {
const ColorPicker({
@required this.colors,
@required this.selectedColor,
required this.colors,
required this.selectedColor,
this.onColorSelection,
}) : assert(colors != null),
assert(selectedColor != null);
});
final Set<Color> colors;
final Color selectedColor;
final ValueChanged<Color> onColorSelection;
final ValueChanged<Color>? onColorSelection;
@override
Widget build (BuildContext context) {
@@ -28,7 +27,7 @@ class ColorPicker extends StatelessWidget {
selected: color == selectedColor,
onTap: () {
if (onColorSelection != null) {
onColorSelection(color);
onColorSelection!(color);
}
},
);
@@ -41,15 +40,14 @@ class ColorPicker extends StatelessWidget {
@immutable
class _ColorPickerSwatch extends StatelessWidget {
const _ColorPickerSwatch({
@required this.color,
@required this.selected,
required this.color,
required this.selected,
this.onTap,
}) : assert(color != null),
assert(selected != null);
});
final Color color;
final bool selected;
final Function onTap;
final Function? onTap;
@override
Widget build (BuildContext context) {
@@ -61,7 +59,7 @@ class _ColorPickerSwatch extends StatelessWidget {
fillColor: color,
onPressed: () {
if (onTap != null) {
onTap();
onTap!();
}
},
child: !selected ? null : const Icon(

View File

@@ -10,14 +10,13 @@ import 'transformations_demo_color_picker.dart';
@immutable
class EditBoardPoint extends StatelessWidget {
const EditBoardPoint({
Key key,
@required this.boardPoint,
Key? key,
required this.boardPoint,
this.onColorSelection,
}) : assert(boardPoint != null),
super(key: key);
}) : super(key: key);
final BoardPoint boardPoint;
final ValueChanged<Color> onColorSelection;
final ValueChanged<Color>? onColorSelection;
@override
Widget build (BuildContext context) {

View File

@@ -14,14 +14,14 @@ import 'transformations_demo_inertial_motion.dart';
@immutable
class GestureTransformable extends StatefulWidget {
const GestureTransformable({
Key key,
Key? key,
// The child to perform the transformations on.
@required this.child,
required this.child,
// The desired visible size of the widget and the area that is receptive to
// gestures. If a widget that's as big as possible is desired, then wrap
// this in a LayoutBuilder and pass
// `Size(constraints.maxWidth, constraints.maxHeight)`.
@required this.size,
required this.size,
// The scale will be clamped to between these values. A maxScale of null has
// no bounds. minScale must be greater than zero.
this.maxScale = 2.5,
@@ -71,14 +71,7 @@ class GestureTransformable extends StatefulWidget {
this.onScaleStart,
this.onScaleUpdate,
this.onScaleEnd,
}) : assert(child != null),
assert(size != null),
assert(minScale != null),
assert(minScale > 0),
assert(disableTranslation != null),
assert(disableScale != null),
assert(disableRotation != null),
assert(reset != null),
}) : assert(minScale > 0),
assert(
!reset || onResetEnd != null,
'Must implement onResetEnd to use reset.',
@@ -88,41 +81,41 @@ class GestureTransformable extends StatefulWidget {
final Widget child;
final Size size;
final bool reset;
final GestureTapDownCallback onTapDown;
final GestureTapUpCallback onTapUp;
final GestureTapCallback onTap;
final GestureTapCancelCallback onTapCancel;
final GestureTapCallback onDoubleTap;
final GestureLongPressCallback onLongPress;
final GestureLongPressUpCallback onLongPressUp;
final GestureDragDownCallback onVerticalDragDown;
final GestureDragStartCallback onVerticalDragStart;
final GestureDragUpdateCallback onVerticalDragUpdate;
final GestureDragEndCallback onVerticalDragEnd;
final GestureDragCancelCallback onVerticalDragCancel;
final GestureDragDownCallback onHorizontalDragDown;
final GestureDragStartCallback onHorizontalDragStart;
final GestureDragUpdateCallback onHorizontalDragUpdate;
final GestureDragEndCallback onHorizontalDragEnd;
final GestureDragCancelCallback onHorizontalDragCancel;
final GestureDragDownCallback onPanDown;
final GestureDragStartCallback onPanStart;
final GestureDragUpdateCallback onPanUpdate;
final GestureDragEndCallback onPanEnd;
final GestureDragCancelCallback onPanCancel;
final VoidCallback onResetEnd;
final GestureScaleStartCallback onScaleStart;
final GestureScaleUpdateCallback onScaleUpdate;
final GestureScaleEndCallback onScaleEnd;
final GestureTapDownCallback? onTapDown;
final GestureTapUpCallback? onTapUp;
final GestureTapCallback? onTap;
final GestureTapCancelCallback? onTapCancel;
final GestureTapCallback? onDoubleTap;
final GestureLongPressCallback? onLongPress;
final GestureLongPressUpCallback? onLongPressUp;
final GestureDragDownCallback? onVerticalDragDown;
final GestureDragStartCallback? onVerticalDragStart;
final GestureDragUpdateCallback? onVerticalDragUpdate;
final GestureDragEndCallback? onVerticalDragEnd;
final GestureDragCancelCallback? onVerticalDragCancel;
final GestureDragDownCallback? onHorizontalDragDown;
final GestureDragStartCallback? onHorizontalDragStart;
final GestureDragUpdateCallback? onHorizontalDragUpdate;
final GestureDragEndCallback? onHorizontalDragEnd;
final GestureDragCancelCallback? onHorizontalDragCancel;
final GestureDragDownCallback? onPanDown;
final GestureDragStartCallback? onPanStart;
final GestureDragUpdateCallback? onPanUpdate;
final GestureDragEndCallback? onPanEnd;
final GestureDragCancelCallback? onPanCancel;
final VoidCallback? onResetEnd;
final GestureScaleStartCallback? onScaleStart;
final GestureScaleUpdateCallback? onScaleUpdate;
final GestureScaleEndCallback? onScaleEnd;
final double maxScale;
final double minScale;
final Rect boundaryRect;
final Rect? boundaryRect;
final bool disableTranslation;
final bool disableScale;
final bool disableRotation;
final Offset initialTranslation;
final double initialScale;
final double initialRotation;
final Offset? initialTranslation;
final double? initialScale;
final double? initialRotation;
@override _GestureTransformableState createState() => _GestureTransformableState();
}
@@ -137,20 +130,20 @@ enum _GestureType {
// This is public only for access from a unit test.
class _GestureTransformableState extends State<GestureTransformable> with TickerProviderStateMixin {
Animation<Offset> _animation;
AnimationController _controller;
Animation<Matrix4> _animationReset;
AnimationController _controllerReset;
Animation<Offset>? _animation;
late AnimationController _controller;
Animation<Matrix4>? _animationReset;
late AnimationController _controllerReset;
// The translation that will be applied to the scene (not viewport).
// A positive x offset moves the scene right, viewport left.
// A positive y offset moves the scene down, viewport up.
Offset _translateFromScene; // Point where a single translation began.
double _scaleStart; // Scale value at start of scaling gesture.
double _rotationStart = 0.0; // Rotation at start of rotation gesture.
Rect _boundaryRect;
Offset? _translateFromScene; // Point where a single translation began.
double? _scaleStart; // Scale value at start of scaling gesture.
double? _rotationStart = 0.0; // Rotation at start of rotation gesture.
late Rect _boundaryRect;
Matrix4 _transform = Matrix4.identity();
double _currentRotation = 0.0;
_GestureType gestureType;
_GestureType? gestureType;
// The transformation matrix that gives the initial home position.
Matrix4 get _initialTransform {
@@ -183,7 +176,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
// Get the offset of the current widget from the global screen coordinates.
// TODO(justinmc): Protect against calling this during first build.
static Offset getOffset(BuildContext context) {
final RenderBox renderObject = context.findRenderObject() as RenderBox;
final RenderBox renderObject = context.findRenderObject()! as RenderBox;
return renderObject.localToGlobal(Offset.zero);
}
@@ -220,12 +213,12 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
return GestureDetector(
behavior: HitTestBehavior.opaque, // Necessary when translating off screen
onTapDown: widget.onTapDown == null ? null : (TapDownDetails details) {
widget.onTapDown(TapDownDetails(
widget.onTapDown!(TapDownDetails(
globalPosition: fromViewport(details.globalPosition - getOffset(context), _transform),
));
},
onTapUp: widget.onTapUp == null ? null : (TapUpDetails details) {
widget.onTapUp(TapUpDetails(
widget.onTapUp!(TapUpDetails(
kind: details.kind,
globalPosition: fromViewport(details.globalPosition - getOffset(context), _transform),
));
@@ -236,51 +229,51 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
onLongPress: widget.onLongPress,
onLongPressUp: widget.onLongPressUp,
onVerticalDragDown: widget.onVerticalDragDown == null ? null : (DragDownDetails details) {
widget.onVerticalDragDown(DragDownDetails(
widget.onVerticalDragDown!(DragDownDetails(
globalPosition: fromViewport(details.globalPosition - getOffset(context), _transform),
));
},
onVerticalDragStart: widget.onVerticalDragStart == null ? null : (DragStartDetails details) {
widget.onVerticalDragStart(DragStartDetails(
widget.onVerticalDragStart!(DragStartDetails(
globalPosition: fromViewport(details.globalPosition - getOffset(context), _transform),
));
},
onVerticalDragUpdate: widget.onVerticalDragUpdate == null ? null : (DragUpdateDetails details) {
widget.onVerticalDragUpdate(DragUpdateDetails(
widget.onVerticalDragUpdate!(DragUpdateDetails(
globalPosition: fromViewport(details.globalPosition - getOffset(context), _transform),
));
},
onVerticalDragEnd: widget.onVerticalDragEnd,
onVerticalDragCancel: widget.onVerticalDragCancel,
onHorizontalDragDown: widget.onHorizontalDragDown == null ? null : (DragDownDetails details) {
widget.onHorizontalDragDown(DragDownDetails(
widget.onHorizontalDragDown!(DragDownDetails(
globalPosition: fromViewport(details.globalPosition - getOffset(context), _transform),
));
},
onHorizontalDragStart: widget.onHorizontalDragStart == null ? null : (DragStartDetails details) {
widget.onHorizontalDragStart(DragStartDetails(
widget.onHorizontalDragStart!(DragStartDetails(
globalPosition: fromViewport(details.globalPosition - getOffset(context), _transform),
));
},
onHorizontalDragUpdate: widget.onHorizontalDragUpdate == null ? null : (DragUpdateDetails details) {
widget.onHorizontalDragUpdate(DragUpdateDetails(
widget.onHorizontalDragUpdate!(DragUpdateDetails(
globalPosition: fromViewport(details.globalPosition - getOffset(context), _transform),
));
},
onHorizontalDragEnd: widget.onHorizontalDragEnd,
onHorizontalDragCancel: widget.onHorizontalDragCancel,
onPanDown: widget.onPanDown == null ? null : (DragDownDetails details) {
widget.onPanDown(DragDownDetails(
widget.onPanDown!(DragDownDetails(
globalPosition: fromViewport(details.globalPosition - getOffset(context), _transform),
));
},
onPanStart: widget.onPanStart == null ? null : (DragStartDetails details) {
widget.onPanStart(DragStartDetails(
widget.onPanStart!(DragStartDetails(
globalPosition: fromViewport(details.globalPosition - getOffset(context), _transform),
));
},
onPanUpdate: widget.onPanUpdate == null ? null : (DragUpdateDetails details) {
widget.onPanUpdate(DragUpdateDetails(
widget.onPanUpdate!(DragUpdateDetails(
globalPosition: fromViewport(details.globalPosition - getOffset(context), _transform),
));
},
@@ -305,7 +298,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
// Return a new matrix representing the given matrix after applying the given
// translation.
Matrix4 matrixTranslate(Matrix4 matrix, Offset translation) {
Matrix4 matrixTranslate(Matrix4 matrix, Offset? translation) {
if (widget.disableTranslation || translation == Offset.zero) {
return matrix;
}
@@ -328,7 +321,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
-scale * viewportBoundaries.top,
);
final Matrix4 nextMatrix = matrix.clone()..translate(
translation.dx,
translation!.dx,
translation.dy,
);
final Vector3 nextTranslationVector = nextMatrix.getTranslation();
@@ -350,7 +343,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
// Return a new matrix representing the given matrix after applying the given
// scale transform.
Matrix4 matrixScale(Matrix4 matrix, double scale) {
Matrix4 matrixScale(Matrix4 matrix, double? scale) {
if (widget.disableScale || scale == 1) {
return matrix;
}
@@ -374,11 +367,11 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
// Don't allow a scale that results in an overall scale beyond min/max
// scale.
final double currentScale = _transform.getMaxScaleOnAxis();
final double totalScale = currentScale * scale;
final double totalScale = currentScale * scale!;
final double clampedTotalScale = totalScale.clamp(
widget.minScale,
widget.maxScale,
) as double;
);
final double clampedScale = clampedTotalScale / currentScale;
return matrix..scale(clampedScale);
}
@@ -386,21 +379,21 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
// Return a new matrix representing the given matrix after applying the given
// rotation transform.
// Rotating the scene cannot cause the viewport to view beyond _boundaryRect.
Matrix4 matrixRotate(Matrix4 matrix, double rotation, Offset focalPoint) {
Matrix4 matrixRotate(Matrix4 matrix, double? rotation, Offset focalPoint) {
if (widget.disableRotation || rotation == 0) {
return matrix;
}
final Offset focalPointScene = fromViewport(focalPoint, matrix);
return matrix
..translate(focalPointScene.dx, focalPointScene.dy)
..rotateZ(-rotation)
..rotateZ(-rotation!)
..translate(-focalPointScene.dx, -focalPointScene.dy);
}
// Handle the start of a gesture of _GestureType.
void _onScaleStart(ScaleStartDetails details) {
if (widget.onScaleStart != null) {
widget.onScaleStart(details);
widget.onScaleStart!(details);
}
if (_controller.isAnimating) {
@@ -425,7 +418,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
void _onScaleUpdate(ScaleUpdateDetails details) {
double scale = _transform.getMaxScaleOnAxis();
if (widget.onScaleUpdate != null) {
widget.onScaleUpdate(ScaleUpdateDetails(
widget.onScaleUpdate!(ScaleUpdateDetails(
focalPoint: fromViewport(details.focalPoint, _transform),
scale: details.scale,
rotation: details.rotation,
@@ -453,7 +446,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
// details.scale gives us the amount to change the scale as of the
// start of this gesture, so calculate the amount to scale as of the
// previous call to _onScaleUpdate.
final double desiredScale = _scaleStart * details.scale;
final double desiredScale = _scaleStart! * details.scale;
final double scaleChange = desiredScale / scale;
_transform = matrixScale(_transform, scaleChange);
scale = _transform.getMaxScaleOnAxis();
@@ -468,13 +461,13 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
);
_transform = matrixTranslate(_transform, focalPointSceneNext - focalPointScene);
} else if (gestureType == _GestureType.rotate && details.rotation != 0.0) {
final double desiredRotation = _rotationStart + details.rotation;
final double desiredRotation = _rotationStart! + details.rotation;
_transform = matrixRotate(_transform, _currentRotation - desiredRotation, details.focalPoint);
_currentRotation = desiredRotation;
} else if (_translateFromScene != null && details.scale == 1.0) {
// Translate so that the same point in the scene is underneath the
// focal point before and after the movement.
final Offset translationChange = focalPointScene - _translateFromScene;
final Offset translationChange = focalPointScene - _translateFromScene!;
_transform = matrixTranslate(_transform, translationChange);
_translateFromScene = fromViewport(details.focalPoint, _transform);
}
@@ -484,7 +477,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
// Handle the end of a gesture of _GestureType.
void _onScaleEnd(ScaleEndDetails details) {
if (widget.onScaleEnd != null) {
widget.onScaleEnd(details);
widget.onScaleEnd!(details);
}
setState(() {
_scaleStart = null;
@@ -510,7 +503,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
end: inertialMotion.finalPosition,
).animate(_controller);
_controller.duration = Duration(milliseconds: inertialMotion.duration.toInt());
_animation.addListener(_onAnimate);
_animation!.addListener(_onAnimate);
_controller.fling();
}
@@ -522,7 +515,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
final Vector3 translationVector = _transform.getTranslation();
final Offset translation = Offset(translationVector.x, translationVector.y);
final Offset translationScene = fromViewport(translation, _transform);
final Offset animationScene = fromViewport(_animation.value, _transform);
final Offset animationScene = fromViewport(_animation!.value, _transform);
final Offset translationChangeScene = animationScene - translationScene;
_transform = matrixTranslate(_transform, translationChangeScene);
});
@@ -536,13 +529,13 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
// Handle reset to home transform animation.
void _onAnimateReset() {
setState(() {
_transform = _animationReset.value;
_transform = _animationReset!.value;
});
if (!_controllerReset.isAnimating) {
_animationReset?.removeListener(_onAnimateReset);
_animationReset = null;
_controllerReset.reset();
widget.onResetEnd();
widget.onResetEnd!();
}
}
@@ -554,7 +547,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
end: _initialTransform,
).animate(_controllerReset);
_controllerReset.duration = const Duration(milliseconds: 400);
_animationReset.addListener(_onAnimateReset);
_animationReset!.addListener(_onAnimateReset);
_controllerReset.forward();
}
@@ -564,7 +557,7 @@ class _GestureTransformableState extends State<GestureTransformable> with Ticker
_animationReset?.removeListener(_onAnimateReset);
_animationReset = null;
_controllerReset.reset();
widget.onResetEnd();
widget.onResetEnd!();
}
@override

View File

@@ -60,7 +60,7 @@ class InertialMotion {
// Solve the equation of motion to find the position at a given point in time
// in one dimension.
double _getPosition({double r0, double v0, int t, double a}) {
double _getPosition({required double r0, required double v0, required int t, required double a}) {
// Stop movement when it would otherwise reverse direction.
final double stopTime = (v0 / a).abs();
if (t > stopTime) {

View File

@@ -6,14 +6,11 @@ import 'package:flutter/material.dart';
class TextStyleItem extends StatelessWidget {
const TextStyleItem({
Key key,
@required this.name,
@required this.style,
@required this.text,
}) : assert(name != null),
assert(style != null),
assert(text != null),
super(key: key);
Key? key,
required this.name,
required this.style,
required this.text,
}) : super(key: key);
final String name;
final TextStyle style;
@@ -22,7 +19,7 @@ class TextStyleItem extends StatelessWidget {
@override
Widget build(BuildContext context) {
final ThemeData theme = Theme.of(context);
final TextStyle nameStyle = theme.textTheme.caption.copyWith(color: theme.textTheme.caption.color);
final TextStyle nameStyle = theme.textTheme.caption!.copyWith(color: theme.textTheme.caption!.color);
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 16.0),
child: Row(
@@ -49,17 +46,17 @@ class TypographyDemo extends StatelessWidget {
final TextTheme textTheme = Theme.of(context).textTheme;
final List<Widget> styleItems = <Widget>[
if (MediaQuery.of(context).size.width > 500.0)
TextStyleItem(name: 'Headline 1', style: textTheme.headline1, text: 'Light 112sp'),
TextStyleItem(name: 'Headline 2', style: textTheme.headline2, text: 'Regular 56sp'),
TextStyleItem(name: 'Headline 3', style: textTheme.headline3, text: 'Regular 45sp'),
TextStyleItem(name: 'Headline 4', style: textTheme.headline4, text: 'Regular 34sp'),
TextStyleItem(name: 'Headline 5', style: textTheme.headline5, text: 'Regular 24sp'),
TextStyleItem(name: 'Headline 6', style: textTheme.headline6, text: 'Medium 20sp'),
TextStyleItem(name: 'Subtitle 1', style: textTheme.subtitle1, text: 'Regular 16sp'),
TextStyleItem(name: 'Body 1', style: textTheme.bodyText1, text: 'Medium 14sp'),
TextStyleItem(name: 'Body 2', style: textTheme.bodyText2, text: 'Regular 14sp'),
TextStyleItem(name: 'Caption', style: textTheme.caption, text: 'Regular 12sp'),
TextStyleItem(name: 'Button', style: textTheme.button, text: 'MEDIUM (ALL CAPS) 14sp'),
TextStyleItem(name: 'Headline 1', style: textTheme.headline1!, text: 'Light 112sp'),
TextStyleItem(name: 'Headline 2', style: textTheme.headline2!, text: 'Regular 56sp'),
TextStyleItem(name: 'Headline 3', style: textTheme.headline3!, text: 'Regular 45sp'),
TextStyleItem(name: 'Headline 4', style: textTheme.headline4!, text: 'Regular 34sp'),
TextStyleItem(name: 'Headline 5', style: textTheme.headline5!, text: 'Regular 24sp'),
TextStyleItem(name: 'Headline 6', style: textTheme.headline6!, text: 'Medium 20sp'),
TextStyleItem(name: 'Subtitle 1', style: textTheme.subtitle1!, text: 'Regular 16sp'),
TextStyleItem(name: 'Body 1', style: textTheme.bodyText1!, text: 'Medium 14sp'),
TextStyleItem(name: 'Body 2', style: textTheme.bodyText2!, text: 'Regular 14sp'),
TextStyleItem(name: 'Caption', style: textTheme.caption!, text: 'Regular 12sp'),
TextStyleItem(name: 'Button', style: textTheme.button!, text: 'MEDIUM (ALL CAPS) 14sp'),
];
return Scaffold(

View File

@@ -11,11 +11,11 @@ import 'package:video_player/video_player.dart';
import 'package:device_info/device_info.dart';
class VideoCard extends StatelessWidget {
const VideoCard({ Key key, this.controller, this.title, this.subtitle }) : super(key: key);
const VideoCard({ Key? key, this.controller, this.title, this.subtitle }) : super(key: key);
final VideoPlayerController controller;
final String title;
final String subtitle;
final VideoPlayerController? controller;
final String? title;
final String? subtitle;
Widget _buildInlineVideo() {
return Padding(
@@ -24,7 +24,7 @@ class VideoCard extends StatelessWidget {
child: AspectRatio(
aspectRatio: 3 / 2,
child: Hero(
tag: controller,
tag: controller!,
child: VideoPlayerLoading(controller),
),
),
@@ -35,13 +35,13 @@ class VideoCard extends StatelessWidget {
Widget _buildFullScreenVideo() {
return Scaffold(
appBar: AppBar(
title: Text(title),
title: Text(title!),
),
body: Center(
child: AspectRatio(
aspectRatio: 3 / 2,
child: Hero(
tag: controller,
tag: controller!,
child: VideoPlayPause(controller),
),
),
@@ -66,11 +66,11 @@ class VideoCard extends StatelessWidget {
);
route.completed.then((void value) {
controller.setVolume(0.0);
controller!.setVolume(0.0);
});
controller.setVolume(1.0);
Navigator.of(context).push(route);
controller!.setVolume(1.0);
Navigator.of(context)!.push(route);
}
return SafeArea(
@@ -79,7 +79,7 @@ class VideoCard extends StatelessWidget {
child: Card(
child: Column(
children: <Widget>[
ListTile(title: Text(title), subtitle: Text(subtitle)),
ListTile(title: Text(title!), subtitle: Text(subtitle!)),
GestureDetector(
onTap: pushFullScreenWidget,
child: _buildInlineVideo(),
@@ -94,24 +94,24 @@ class VideoCard extends StatelessWidget {
class VideoPlayerLoading extends StatefulWidget {
const VideoPlayerLoading(this.controller);
final VideoPlayerController controller;
final VideoPlayerController? controller;
@override
_VideoPlayerLoadingState createState() => _VideoPlayerLoadingState();
}
class _VideoPlayerLoadingState extends State<VideoPlayerLoading> {
bool _initialized;
bool? _initialized;
@override
void initState() {
super.initState();
_initialized = widget.controller.value.isInitialized;
widget.controller.addListener(() {
_initialized = widget.controller!.value.isInitialized;
widget.controller!.addListener(() {
if (!mounted) {
return;
}
final bool controllerInitialized = widget.controller.value.isInitialized;
final bool controllerInitialized = widget.controller!.value.isInitialized;
if (_initialized != controllerInitialized) {
setState(() {
_initialized = controllerInitialized;
@@ -122,12 +122,12 @@ class _VideoPlayerLoadingState extends State<VideoPlayerLoading> {
@override
Widget build(BuildContext context) {
if (_initialized) {
return VideoPlayer(widget.controller);
if (_initialized!) {
return VideoPlayer(widget.controller!);
}
return Stack(
children: <Widget>[
VideoPlayer(widget.controller),
VideoPlayer(widget.controller!),
const Center(child: CircularProgressIndicator()),
],
fit: StackFit.expand,
@@ -138,7 +138,7 @@ class _VideoPlayerLoadingState extends State<VideoPlayerLoading> {
class VideoPlayPause extends StatefulWidget {
const VideoPlayPause(this.controller);
final VideoPlayerController controller;
final VideoPlayerController? controller;
@override
State createState() => _VideoPlayPauseState();
@@ -152,20 +152,20 @@ class _VideoPlayPauseState extends State<VideoPlayPause> {
};
}
FadeAnimation imageFadeAnimation;
VoidCallback listener;
FadeAnimation? imageFadeAnimation;
late VoidCallback listener;
VideoPlayerController get controller => widget.controller;
VideoPlayerController? get controller => widget.controller;
@override
void initState() {
super.initState();
controller.addListener(listener);
controller!.addListener(listener);
}
@override
void deactivate() {
controller.removeListener(listener);
controller!.removeListener(listener);
super.deactivate();
}
@@ -178,19 +178,19 @@ class _VideoPlayPauseState extends State<VideoPlayPause> {
GestureDetector(
child: VideoPlayerLoading(controller),
onTap: () {
if (!controller.value.isInitialized) {
if (!controller!.value.isInitialized) {
return;
}
if (controller.value.isPlaying) {
if (controller!.value.isPlaying) {
imageFadeAnimation = const FadeAnimation(
child: Icon(Icons.pause, size: 100.0),
);
controller.pause();
controller!.pause();
} else {
imageFadeAnimation = const FadeAnimation(
child: Icon(Icons.play_arrow, size: 100.0),
);
controller.play();
controller!.play();
}
},
),
@@ -206,7 +206,7 @@ class FadeAnimation extends StatefulWidget {
this.duration = const Duration(milliseconds: 500),
});
final Widget child;
final Widget? child;
final Duration duration;
@override
@@ -214,7 +214,7 @@ class FadeAnimation extends StatefulWidget {
}
class _FadeAnimationState extends State<FadeAnimation> with SingleTickerProviderStateMixin {
AnimationController animationController;
late AnimationController animationController;
@override
void initState() {
@@ -268,15 +268,15 @@ class ConnectivityOverlay extends StatefulWidget {
this.connectedCompleter,
});
final Widget child;
final Completer<void> connectedCompleter;
final Widget? child;
final Completer<void>? connectedCompleter;
@override
_ConnectivityOverlayState createState() => _ConnectivityOverlayState();
}
class _ConnectivityOverlayState extends State<ConnectivityOverlay> {
StreamSubscription<ConnectivityResult> connectivitySubscription;
StreamSubscription<ConnectivityResult>? connectivitySubscription;
bool connected = true;
static const SnackBar errorSnackBar = SnackBar(
@@ -308,8 +308,8 @@ class _ConnectivityOverlayState extends State<ConnectivityOverlay> {
// Assume connectivity
// TODO(ditman): Remove this shortcut when `connectivity` support for web
// lands, https://github.com/flutter/flutter/issues/46735
if (!widget.connectedCompleter.isCompleted) {
widget.connectedCompleter.complete(null);
if (!widget.connectedCompleter!.isCompleted) {
widget.connectedCompleter!.complete();
}
return;
}
@@ -321,8 +321,8 @@ class _ConnectivityOverlayState extends State<ConnectivityOverlay> {
if (connectivityResult == ConnectivityResult.none) {
ScaffoldMessenger.of(context).showSnackBar(errorSnackBar);
} else {
if (!widget.connectedCompleter.isCompleted) {
widget.connectedCompleter.complete(null);
if (!widget.connectedCompleter!.isCompleted) {
widget.connectedCompleter!.complete();
}
}
},
@@ -336,11 +336,11 @@ class _ConnectivityOverlayState extends State<ConnectivityOverlay> {
}
@override
Widget build(BuildContext context) => widget.child;
Widget build(BuildContext context) => widget.child!;
}
class VideoDemo extends StatefulWidget {
const VideoDemo({ Key key }) : super(key: key);
const VideoDemo({ Key? key }) : super(key: key);
static const String routeName = '/video';
@@ -389,7 +389,7 @@ class _VideoDemoState extends State<VideoDemo> with SingleTickerProviderStateMix
initController(butterflyController, 'butterfly');
initController(beeController, 'bee');
isIOSSimulator().then<void>((bool result) {
isIOSSimulator().then((bool result) {
isSupported = !result;
});
}

View File

@@ -23,19 +23,19 @@ class _LinkTextSpan extends TextSpan {
// manage the recognizer from outside the TextSpan, e.g. in the State of a
// stateful widget that then hands the recognizer to the TextSpan.
_LinkTextSpan({ TextStyle style, String url, String text }) : super(
_LinkTextSpan({ TextStyle? style, String? url, String? text }) : super(
style: style,
text: text ?? url,
recognizer: TapGestureRecognizer()..onTap = () {
launch(url, forceSafariVC: false);
launch(url!, forceSafariVC: false);
}
);
}
void showGalleryAboutDialog(BuildContext context) {
final ThemeData themeData = Theme.of(context);
final TextStyle aboutTextStyle = themeData.textTheme.bodyText1;
final TextStyle linkStyle = themeData.textTheme.bodyText1.copyWith(color: themeData.accentColor);
final TextStyle? aboutTextStyle = themeData.textTheme.bodyText1;
final TextStyle linkStyle = themeData.textTheme.bodyText1!.copyWith(color: themeData.accentColor);
showAboutDialog(
context: context,

View File

@@ -22,7 +22,7 @@ import 'updater.dart';
class GalleryApp extends StatefulWidget {
const GalleryApp({
Key key,
Key? key,
this.updateUrlFetcher,
this.enablePerformanceOverlay = true,
this.enableRasterCacheImagesCheckerboard = true,
@@ -31,11 +31,11 @@ class GalleryApp extends StatefulWidget {
this.testMode = false,
}) : super(key: key);
final UpdateUrlFetcher updateUrlFetcher;
final UpdateUrlFetcher? updateUrlFetcher;
final bool enablePerformanceOverlay;
final bool enableRasterCacheImagesCheckerboard;
final bool enableOffscreenLayersCheckerboard;
final VoidCallback onSendFeedback;
final VoidCallback? onSendFeedback;
final bool testMode;
@override
@@ -43,9 +43,9 @@ class GalleryApp extends StatefulWidget {
}
class _GalleryAppState extends State<GalleryApp> {
GalleryOptions _options;
Timer _timeDilationTimer;
AppStateModel model;
GalleryOptions? _options;
Timer? _timeDilationTimer;
late AppStateModel model;
Map<String, WidgetBuilder> _buildRoutes() {
// For a different example of how to set up an application routing table
@@ -71,7 +71,7 @@ class _GalleryAppState extends State<GalleryApp> {
@override
void reassemble() {
_options = _options.copyWith(platform: defaultTargetPlatform);
_options = _options!.copyWith(platform: defaultTargetPlatform);
super.reassemble();
}
@@ -84,7 +84,7 @@ class _GalleryAppState extends State<GalleryApp> {
void _handleOptionsChanged(GalleryOptions newOptions) {
setState(() {
if (_options.timeDilation != newOptions.timeDilation) {
if (_options!.timeDilation != newOptions.timeDilation) {
_timeDilationTimer?.cancel();
_timeDilationTimer = null;
if (newOptions.timeDilation > 1.0) {
@@ -108,7 +108,7 @@ class _GalleryAppState extends State<GalleryApp> {
builder: (BuildContext context) {
return MediaQuery(
data: MediaQuery.of(context).copyWith(
textScaleFactor: _options.textScaleFactor.scale,
textScaleFactor: _options!.textScaleFactor!.scale,
),
child: child,
);
@@ -131,7 +131,7 @@ class _GalleryAppState extends State<GalleryApp> {
if (widget.updateUrlFetcher != null) {
home = Updater(
updateUrlFetcher: widget.updateUrlFetcher,
updateUrlFetcher: widget.updateUrlFetcher!,
child: home,
);
}
@@ -139,18 +139,18 @@ class _GalleryAppState extends State<GalleryApp> {
return ScopedModel<AppStateModel>(
model: model,
child: MaterialApp(
theme: kLightGalleryTheme.copyWith(platform: _options.platform, visualDensity: _options.visualDensity.visualDensity),
darkTheme: kDarkGalleryTheme.copyWith(platform: _options.platform, visualDensity: _options.visualDensity.visualDensity),
themeMode: _options.themeMode,
theme: kLightGalleryTheme.copyWith(platform: _options!.platform, visualDensity: _options!.visualDensity!.visualDensity),
darkTheme: kDarkGalleryTheme.copyWith(platform: _options!.platform, visualDensity: _options!.visualDensity!.visualDensity),
themeMode: _options!.themeMode,
title: 'Flutter Gallery',
color: Colors.grey,
showPerformanceOverlay: _options.showPerformanceOverlay,
checkerboardOffscreenLayers: _options.showOffscreenLayersCheckerboard,
checkerboardRasterCacheImages: _options.showRasterCacheImagesCheckerboard,
showPerformanceOverlay: _options!.showPerformanceOverlay,
checkerboardOffscreenLayers: _options!.showOffscreenLayersCheckerboard,
checkerboardRasterCacheImages: _options!.showRasterCacheImagesCheckerboard,
routes: _buildRoutes(),
builder: (BuildContext context, Widget child) {
builder: (BuildContext context, Widget? child) {
return Directionality(
textDirection: _options.textDirection,
textDirection: _options!.textDirection,
child: _applyTextScaleFactor(
// Specifically use a blank Cupertino theme here and do not transfer
// over the Material primary color etc except the brightness to
@@ -160,7 +160,7 @@ class _GalleryAppState extends State<GalleryApp> {
data: CupertinoThemeData(
brightness: Theme.of(context).brightness,
),
child: child,
child: child!,
);
}),
),

View File

@@ -26,37 +26,37 @@ final Animatable<BorderRadius> _kFrontHeadingBevelRadius = BorderRadiusTween(
class _TappableWhileStatusIs extends StatefulWidget {
const _TappableWhileStatusIs(
this.status, {
Key key,
Key? key,
this.controller,
this.child,
}) : super(key: key);
final AnimationController controller;
final AnimationController? controller;
final AnimationStatus status;
final Widget child;
final Widget? child;
@override
_TappableWhileStatusIsState createState() => _TappableWhileStatusIsState();
}
class _TappableWhileStatusIsState extends State<_TappableWhileStatusIs> {
bool _active;
bool? _active;
@override
void initState() {
super.initState();
widget.controller.addStatusListener(_handleStatusChange);
_active = widget.controller.status == widget.status;
widget.controller!.addStatusListener(_handleStatusChange);
_active = widget.controller!.status == widget.status;
}
@override
void dispose() {
widget.controller.removeStatusListener(_handleStatusChange);
widget.controller!.removeStatusListener(_handleStatusChange);
super.dispose();
}
void _handleStatusChange(AnimationStatus status) {
final bool value = widget.controller.status == widget.status;
final bool value = widget.controller!.status == widget.status;
if (_active != value) {
setState(() {
_active = value;
@@ -67,11 +67,11 @@ class _TappableWhileStatusIsState extends State<_TappableWhileStatusIs> {
@override
Widget build(BuildContext context) {
Widget child = AbsorbPointer(
absorbing: !_active,
absorbing: !_active!,
child: widget.child,
);
if (!_active) {
if (!_active!) {
child = FocusScope(
canRequestFocus: false,
debugLabel: '$_TappableWhileStatusIs',
@@ -84,16 +84,16 @@ class _TappableWhileStatusIsState extends State<_TappableWhileStatusIs> {
class _CrossFadeTransition extends AnimatedWidget {
const _CrossFadeTransition({
Key key,
Key? key,
this.alignment = Alignment.center,
Animation<double> progress,
required Animation<double> progress,
this.child0,
this.child1,
}) : super(key: key, listenable: progress);
final AlignmentGeometry alignment;
final Widget child0;
final Widget child1;
final Widget? child0;
final Widget? child1;
@override
Widget build(BuildContext context) {
@@ -135,15 +135,15 @@ class _CrossFadeTransition extends AnimatedWidget {
class _BackAppBar extends StatelessWidget {
const _BackAppBar({
Key key,
Key? key,
this.leading = const SizedBox(width: 56.0),
@required this.title,
required this.title,
this.trailing,
}) : assert(leading != null), assert(title != null), super(key: key);
}) : super(key: key);
final Widget leading;
final Widget title;
final Widget trailing;
final Widget? trailing;
@override
Widget build(BuildContext context) {
@@ -151,7 +151,7 @@ class _BackAppBar extends StatelessWidget {
return IconTheme.merge(
data: theme.primaryIconTheme,
child: DefaultTextStyle(
style: theme.primaryTextTheme.headline6,
style: theme.primaryTextTheme.headline6!,
child: SizedBox(
height: _kBackAppBarHeight,
child: Row(
@@ -188,12 +188,12 @@ class Backdrop extends StatefulWidget {
this.backLayer,
});
final Widget frontAction;
final Widget frontTitle;
final Widget frontLayer;
final Widget frontHeading;
final Widget backTitle;
final Widget backLayer;
final Widget? frontAction;
final Widget? frontTitle;
final Widget? frontLayer;
final Widget? frontHeading;
final Widget? backTitle;
final Widget? backLayer;
@override
_BackdropState createState() => _BackdropState();
@@ -201,8 +201,8 @@ class Backdrop extends StatefulWidget {
class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin {
final GlobalKey _backdropKey = GlobalKey(debugLabel: 'Backdrop');
AnimationController _controller;
Animation<double> _frontOpacity;
AnimationController? _controller;
late Animation<double> _frontOpacity;
static final Animatable<double> _frontOpacityTween = Tween<double>(begin: 0.2, end: 1.0)
.chain(CurveTween(curve: const Interval(0.0, 0.4, curve: Curves.easeInOut)));
@@ -215,7 +215,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
value: 1.0,
vsync: this,
);
_controller.addStatusListener((AnimationStatus status) {
_controller!.addStatusListener((AnimationStatus status) {
setState(() {
// This is intentionally left empty. The state change itself takes
// place inside the AnimationController, so there's nothing to update.
@@ -223,47 +223,47 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
// state from the AnimationController.
});
});
_frontOpacity = _controller.drive(_frontOpacityTween);
_frontOpacity = _controller!.drive(_frontOpacityTween);
}
@override
void dispose() {
_controller.dispose();
_controller!.dispose();
super.dispose();
}
double get _backdropHeight {
// Warning: this can be safely called from the event handlers but it may
// not be called at build time.
final RenderBox renderBox = _backdropKey.currentContext.findRenderObject() as RenderBox;
final RenderBox renderBox = _backdropKey.currentContext!.findRenderObject()! as RenderBox;
return math.max(0.0, renderBox.size.height - _kBackAppBarHeight - _kFrontClosedHeight);
}
void _handleDragUpdate(DragUpdateDetails details) {
_controller.value -= details.primaryDelta / (_backdropHeight ?? details.primaryDelta);
_controller!.value -= details.primaryDelta! / _backdropHeight;
}
void _handleDragEnd(DragEndDetails details) {
if (_controller.isAnimating || _controller.status == AnimationStatus.completed)
if (_controller!.isAnimating || _controller!.status == AnimationStatus.completed)
return;
final double flingVelocity = details.velocity.pixelsPerSecond.dy / _backdropHeight;
if (flingVelocity < 0.0)
_controller.fling(velocity: math.max(2.0, -flingVelocity));
_controller!.fling(velocity: math.max(2.0, -flingVelocity));
else if (flingVelocity > 0.0)
_controller.fling(velocity: math.min(-2.0, -flingVelocity));
_controller!.fling(velocity: math.min(-2.0, -flingVelocity));
else
_controller.fling(velocity: _controller.value < 0.5 ? -2.0 : 2.0);
_controller!.fling(velocity: _controller!.value < 0.5 ? -2.0 : 2.0);
}
void _toggleFrontLayer() {
final AnimationStatus status = _controller.status;
final AnimationStatus status = _controller!.status;
final bool isOpen = status == AnimationStatus.completed || status == AnimationStatus.forward;
_controller.fling(velocity: isOpen ? -2.0 : 2.0);
_controller!.fling(velocity: isOpen ? -2.0 : 2.0);
}
Widget _buildStack(BuildContext context, BoxConstraints constraints) {
final Animation<RelativeRect> frontRelativeRect = _controller.drive(RelativeRectTween(
final Animation<RelativeRect> frontRelativeRect = _controller!.drive(RelativeRectTween(
begin: RelativeRect.fromLTRB(0.0, constraints.biggest.height - _kFrontClosedHeight, 0.0, 0.0),
end: const RelativeRect.fromLTRB(0.0, _kBackAppBarHeight, 0.0, 0.0),
));
@@ -275,9 +275,9 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
_BackAppBar(
leading: widget.frontAction,
leading: widget.frontAction!,
title: _CrossFadeTransition(
progress: _controller,
progress: _controller!,
alignment: AlignmentDirectional.centerStart,
child0: Semantics(namesRoute: true, child: widget.frontTitle),
child1: Semantics(namesRoute: true, child: widget.backTitle),
@@ -287,7 +287,7 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
tooltip: 'Toggle options page',
icon: AnimatedIcon(
icon: AnimatedIcons.close_menu,
progress: _controller,
progress: _controller!,
),
),
),
@@ -296,8 +296,8 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
AnimationStatus.dismissed,
controller: _controller,
child: Visibility(
child: widget.backLayer,
visible: _controller.status != AnimationStatus.completed,
child: widget.backLayer!,
visible: _controller!.status != AnimationStatus.completed,
maintainState: true,
),
),
@@ -308,14 +308,14 @@ class _BackdropState extends State<Backdrop> with SingleTickerProviderStateMixin
PositionedTransition(
rect: frontRelativeRect,
child: AnimatedBuilder(
animation: _controller,
builder: (BuildContext context, Widget child) {
animation: _controller!,
builder: (BuildContext context, Widget? child) {
return PhysicalShape(
elevation: 12.0,
color: Theme.of(context).canvasColor,
clipper: ShapeBorderClipper(
shape: BeveledRectangleBorder(
borderRadius: _kFrontHeadingBevelRadius.transform(_controller.value),
borderRadius: _kFrontHeadingBevelRadius.transform(_controller!.value),
),
),
clipBehavior: Clip.antiAlias,

View File

@@ -20,11 +20,11 @@ class ComponentDemoTabData {
this.documentationUrl,
});
final Widget demoWidget;
final String exampleCodeTag;
final String description;
final String tabName;
final String documentationUrl;
final Widget? demoWidget;
final String? exampleCodeTag;
final String? description;
final String? tabName;
final String? documentationUrl;
@override
bool operator==(Object other) {
@@ -49,14 +49,14 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
this.showExampleCodeAction = true,
});
final List<ComponentDemoTabData> demos;
final String title;
final List<Widget> actions;
final List<ComponentDemoTabData>? demos;
final String? title;
final List<Widget>? actions;
final bool isScrollable;
final bool showExampleCodeAction;
void _showExampleCode(BuildContext context) {
final String tag = demos[DefaultTabController.of(context).index].exampleCodeTag;
final String? tag = demos![DefaultTabController.of(context)!.index].exampleCodeTag;
if (tag != null) {
Navigator.push(context, MaterialPageRoute<FullScreenCodeDialog>(
builder: (BuildContext context) => FullScreenCodeDialog(exampleCodeTag: tag)
@@ -65,7 +65,7 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
}
Future<void> _showApiDocumentation(BuildContext context) async {
final String url = demos[DefaultTabController.of(context).index].documentationUrl;
final String? url = demos![DefaultTabController.of(context)!.index].documentationUrl;
if (url == null)
return;
@@ -92,10 +92,10 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: demos.length,
length: demos!.length,
child: Scaffold(
appBar: AppBar(
title: Text(title),
title: Text(title!),
actions: <Widget>[
...?actions,
Builder(
@@ -119,11 +119,11 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
],
bottom: TabBar(
isScrollable: isScrollable,
tabs: demos.map<Widget>((ComponentDemoTabData data) => Tab(text: data.tabName)).toList(),
tabs: demos!.map<Widget>((ComponentDemoTabData data) => Tab(text: data.tabName)).toList(),
),
),
body: TabBarView(
children: demos.map<Widget>((ComponentDemoTabData demo) {
children: demos!.map<Widget>((ComponentDemoTabData demo) {
return SafeArea(
top: false,
bottom: false,
@@ -131,11 +131,11 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
children: <Widget>[
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(demo.description,
child: Text(demo.description!,
style: Theme.of(context).textTheme.subtitle1,
),
),
Expanded(child: demo.demoWidget),
Expanded(child: demo.demoWidget!),
],
),
);
@@ -149,7 +149,7 @@ class TabbedComponentDemoScaffold extends StatelessWidget {
class FullScreenCodeDialog extends StatefulWidget {
const FullScreenCodeDialog({ this.exampleCodeTag });
final String exampleCodeTag;
final String? exampleCodeTag;
@override
FullScreenCodeDialogState createState() => FullScreenCodeDialogState();
@@ -157,11 +157,11 @@ class FullScreenCodeDialog extends StatefulWidget {
class FullScreenCodeDialogState extends State<FullScreenCodeDialog> {
String _exampleCode;
String? _exampleCode;
@override
void didChangeDependencies() {
getExampleCode(widget.exampleCodeTag, DefaultAssetBundle.of(context)).then<void>((String code) {
getExampleCode(widget.exampleCodeTag, DefaultAssetBundle.of(context)).then((String? code) {
if (mounted) {
setState(() {
_exampleCode = code ?? 'Example code not found';
@@ -215,7 +215,7 @@ class FullScreenCodeDialogState extends State<FullScreenCodeDialog> {
}
class MaterialDemoDocumentationButton extends StatelessWidget {
MaterialDemoDocumentationButton(String routeName, { Key key })
MaterialDemoDocumentationButton(String routeName, { Key? key })
: documentationUrl = kDemoDocumentationUrl[routeName],
assert(
kDemoDocumentationUrl[routeName] != null,
@@ -223,20 +223,20 @@ class MaterialDemoDocumentationButton extends StatelessWidget {
),
super(key: key);
final String documentationUrl;
final String? documentationUrl;
@override
Widget build(BuildContext context) {
return IconButton(
icon: const Icon(Icons.library_books),
tooltip: 'API documentation',
onPressed: () => launch(documentationUrl, forceWebView: true),
onPressed: () => launch(documentationUrl!, forceWebView: true),
);
}
}
class CupertinoDemoDocumentationButton extends StatelessWidget {
CupertinoDemoDocumentationButton(String routeName, { Key key })
CupertinoDemoDocumentationButton(String routeName, { Key? key })
: documentationUrl = kDemoDocumentationUrl[routeName],
assert(
kDemoDocumentationUrl[routeName] != null,
@@ -244,7 +244,7 @@ class CupertinoDemoDocumentationButton extends StatelessWidget {
),
super(key: key);
final String documentationUrl;
final String? documentationUrl;
@override
Widget build(BuildContext context) {
@@ -254,7 +254,7 @@ class CupertinoDemoDocumentationButton extends StatelessWidget {
label: 'API documentation',
child: const Icon(CupertinoIcons.book),
),
onPressed: () => launch(documentationUrl, forceWebView: true),
onPressed: () => launch(documentationUrl!, forceWebView: true),
);
}
}

View File

@@ -10,8 +10,8 @@ import 'icons.dart';
@immutable
class GalleryDemoCategory {
const GalleryDemoCategory._({
@required this.name,
@required this.icon,
required this.name,
required this.icon,
});
final String name;
@@ -64,25 +64,22 @@ const GalleryDemoCategory _kMedia = GalleryDemoCategory._(
class GalleryDemo {
const GalleryDemo({
@required this.title,
@required this.icon,
required this.title,
required this.icon,
this.subtitle,
@required this.category,
@required this.routeName,
required this.category,
required this.routeName,
this.documentationUrl,
@required this.buildRoute,
}) : assert(title != null),
assert(category != null),
assert(routeName != null),
assert(buildRoute != null);
required this.buildRoute,
});
final String title;
final IconData icon;
final String subtitle;
final String? subtitle;
final GalleryDemoCategory category;
final String routeName;
final WidgetBuilder buildRoute;
final String documentationUrl;
final String? documentationUrl;
@override
String toString() {
@@ -581,7 +578,7 @@ final Map<GalleryDemoCategory, List<GalleryDemo>> kGalleryCategoryToDemos =
},
);
final Map<String, String> kDemoDocumentationUrl = <String, String>{
final Map<String, String?> kDemoDocumentationUrl = <String, String?>{
for (final GalleryDemo demo in kAllGalleryDemos)
if (demo.documentationUrl != null) demo.routeName: demo.documentationUrl,
};

View File

@@ -9,7 +9,7 @@ import 'package:flutter/material.dart';
class ButtonsDemo {
void setState(VoidCallback callback) { }
BuildContext context;
late BuildContext context;
void buttons() {
@@ -90,12 +90,12 @@ const TextButton(
// START buttons_dropdown
// Member variable holding value.
String dropdownValue;
String? dropdownValue;
// Dropdown button with string values.
DropdownButton<String>(
value: dropdownValue,
onChanged: (String newValue) {
onChanged: (String? newValue) {
// null indicates the user didn't select a
// new value.
setState(() {
@@ -116,7 +116,7 @@ DropdownButton<String>(
// START buttons_icon
// Member variable holding toggle value.
bool value;
late bool value;
// Toggleable icon button.
IconButton(
@@ -152,12 +152,12 @@ class SelectionControls {
// START selectioncontrols_checkbox
// Member variable holding the checkbox's value.
bool checkboxValue = false;
bool? checkboxValue = false;
// Create a checkbox.
Checkbox(
value: checkboxValue,
onChanged: (bool value) {
onChanged: (bool? value) {
setState(() {
checkboxValue = value;
});
@@ -168,7 +168,7 @@ Checkbox(
Checkbox(
tristate: true,
value: checkboxValue,
onChanged: (bool value) {
onChanged: (bool? value) {
setState(() {
checkboxValue = value;
});
@@ -184,10 +184,10 @@ const Checkbox(value: false, onChanged: null);
// START selectioncontrols_radio
// Member variable holding value.
int radioValue = 0;
int? radioValue = 0;
// Method setting value.
void handleRadioValueChanged(int value) {
void handleRadioValueChanged(int? value) {
setState(() {
radioValue = value;
});

View File

@@ -7,23 +7,22 @@ import 'package:flutter/services.dart';
const String _kStartTag = '// START ';
const String _kEndTag = '// END';
Map<String, String> _exampleCode;
Map<String?, String>? _exampleCode;
Future<String> getExampleCode(String tag, AssetBundle bundle) async {
Future<String?> getExampleCode(String? tag, AssetBundle bundle) async {
if (_exampleCode == null)
await _parseExampleCode(bundle);
return _exampleCode[tag];
return _exampleCode![tag];
}
Future<void> _parseExampleCode(AssetBundle bundle) async {
final String code = await bundle.loadString('lib/gallery/example_code.dart') ??
'// lib/gallery/example_code.dart not found\n';
_exampleCode = <String, String>{};
final String code = await bundle.loadString('lib/gallery/example_code.dart');
_exampleCode = <String?, String>{};
final List<String> lines = code.split('\n');
List<String> codeBlock;
String codeTag;
List<String>? codeBlock;
String? codeTag;
for (final String line in lines) {
if (codeBlock == null) {
@@ -39,7 +38,7 @@ Future<void> _parseExampleCode(AssetBundle bundle) async {
// Inside a block.
if (line.startsWith(_kEndTag)) {
// Add the block.
_exampleCode[codeTag] = codeBlock.join('\n');
_exampleCode![codeTag] = codeBlock.join('\n');
codeBlock = null;
codeTag = null;
} else {

View File

@@ -18,7 +18,7 @@ const double _kDemoItemHeight = 64.0;
const Duration _kFrontLayerSwitchDuration = Duration(milliseconds: 300);
class _FlutterLogo extends StatelessWidget {
const _FlutterLogo({ Key key }) : super(key: key);
const _FlutterLogo({ Key? key }) : super(key: key);
@override
Widget build(BuildContext context) {
@@ -41,13 +41,13 @@ class _FlutterLogo extends StatelessWidget {
class _CategoryItem extends StatelessWidget {
const _CategoryItem({
Key key,
Key? key,
this.category,
this.onTap,
}) : super (key: key);
final GalleryDemoCategory category;
final VoidCallback onTap;
final GalleryDemoCategory? category;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
@@ -70,7 +70,7 @@ class _CategoryItem extends StatelessWidget {
Padding(
padding: const EdgeInsets.all(6.0),
child: Icon(
category.icon,
category!.icon,
size: 60.0,
color: isDark ? Colors.white : _kFlutterBlue,
),
@@ -80,9 +80,9 @@ class _CategoryItem extends StatelessWidget {
height: 48.0,
alignment: Alignment.center,
child: Text(
category.name,
category!.name,
textAlign: TextAlign.center,
style: theme.textTheme.subtitle1.copyWith(
style: theme.textTheme.subtitle1!.copyWith(
fontFamily: 'GoogleSans',
color: isDark ? Colors.white : _kFlutterBlue,
),
@@ -97,18 +97,18 @@ class _CategoryItem extends StatelessWidget {
class _CategoriesPage extends StatelessWidget {
const _CategoriesPage({
Key key,
Key? key,
this.categories,
this.onCategoryTap,
}) : super(key: key);
final Iterable<GalleryDemoCategory> categories;
final ValueChanged<GalleryDemoCategory> onCategoryTap;
final Iterable<GalleryDemoCategory>? categories;
final ValueChanged<GalleryDemoCategory>? onCategoryTap;
@override
Widget build(BuildContext context) {
const double aspectRatio = 160.0 / 180.0;
final List<GalleryDemoCategory> categoriesList = categories.toList();
final List<GalleryDemoCategory> categoriesList = categories!.toList();
final int columnCount = (MediaQuery.of(context).orientation == Orientation.portrait) ? 2 : 3;
return Semantics(
@@ -122,7 +122,7 @@ class _CategoriesPage extends StatelessWidget {
builder: (BuildContext context, BoxConstraints constraints) {
final double columnWidth = constraints.biggest.width / columnCount.toDouble();
final double rowHeight = math.min(225.0, columnWidth * aspectRatio);
final int rowCount = (categories.length + columnCount - 1) ~/ columnCount;
final int rowCount = (categories!.length + columnCount - 1) ~/ columnCount;
// This repaint boundary prevents the inner contents of the front layer
// from repainting when the backdrop toggle triggers a repaint on the
@@ -133,7 +133,7 @@ class _CategoriesPage extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: List<Widget>.generate(rowCount, (int rowIndex) {
final int columnCountForRow = rowIndex == rowCount - 1
? categories.length - columnCount * math.max<int>(0, rowCount - 1)
? categories!.length - columnCount * math.max<int>(0, rowCount - 1)
: columnCount;
return Row(
@@ -147,7 +147,7 @@ class _CategoriesPage extends StatelessWidget {
child: _CategoryItem(
category: category,
onTap: () {
onCategoryTap(category);
onCategoryTap!(category);
},
),
);
@@ -164,17 +164,17 @@ class _CategoriesPage extends StatelessWidget {
}
class _DemoItem extends StatelessWidget {
const _DemoItem({ Key key, this.demo }) : super(key: key);
const _DemoItem({ Key? key, this.demo }) : super(key: key);
final GalleryDemo demo;
final GalleryDemo? demo;
void _launchDemo(BuildContext context) {
if (demo.routeName != null) {
if (demo != null) {
Timeline.instantSync('Start Transition', arguments: <String, String>{
'from': '/',
'to': demo.routeName,
'to': demo!.routeName,
});
Navigator.pushNamed(context, demo.routeName);
Navigator.pushNamed(context, demo!.routeName);
}
}
@@ -199,7 +199,7 @@ class _DemoItem extends StatelessWidget {
height: 56.0,
alignment: Alignment.center,
child: Icon(
demo.icon,
demo!.icon,
size: 24.0,
color: isDark ? Colors.white : _kFlutterBlue,
),
@@ -210,15 +210,15 @@ class _DemoItem extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Text(
demo.title,
style: theme.textTheme.subtitle1.copyWith(
demo!.title,
style: theme.textTheme.subtitle1!.copyWith(
color: isDark ? Colors.white : const Color(0xFF202124),
),
),
if (demo.subtitle != null)
if (demo!.subtitle != null)
Text(
demo.subtitle,
style: theme.textTheme.bodyText2.copyWith(
demo!.subtitle!,
style: theme.textTheme.bodyText2!.copyWith(
color: isDark ? Colors.white : const Color(0xFF60646B)
),
),
@@ -236,7 +236,7 @@ class _DemoItem extends StatelessWidget {
class _DemosPage extends StatelessWidget {
const _DemosPage(this.category);
final GalleryDemoCategory category;
final GalleryDemoCategory? category;
@override
Widget build(BuildContext context) {
@@ -248,13 +248,13 @@ class _DemosPage extends StatelessWidget {
child: Semantics(
scopesRoute: true,
namesRoute: true,
label: category.name,
label: category!.name,
explicitChildNodes: true,
child: ListView(
dragStartBehavior: DragStartBehavior.down,
key: PageStorageKey<String>(category.name),
key: PageStorageKey<String>(category!.name),
padding: EdgeInsets.only(top: 8.0, bottom: windowBottomPadding),
children: kGalleryCategoryToDemos[category].map<Widget>((GalleryDemo demo) {
children: kGalleryCategoryToDemos[category!]!.map<Widget>((GalleryDemo demo) {
return _DemoItem(demo: demo);
}).toList(),
),
@@ -265,12 +265,12 @@ class _DemosPage extends StatelessWidget {
class GalleryHome extends StatefulWidget {
const GalleryHome({
Key key,
Key? key,
this.testMode = false,
this.optionsPage,
}) : super(key: key);
final Widget optionsPage;
final Widget? optionsPage;
final bool testMode;
// In checked mode our MaterialApp will show the default "debug" banner.
@@ -283,10 +283,10 @@ class GalleryHome extends StatefulWidget {
class _GalleryHomeState extends State<GalleryHome> with SingleTickerProviderStateMixin {
static final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
AnimationController _controller;
GalleryDemoCategory _category;
late AnimationController _controller;
GalleryDemoCategory? _category;
static Widget _topHomeLayout(Widget currentChild, List<Widget> previousChildren) {
static Widget _topHomeLayout(Widget? currentChild, List<Widget> previousChildren) {
return Stack(
children: <Widget>[
...previousChildren,
@@ -357,7 +357,7 @@ class _GalleryHomeState extends State<GalleryHome> with SingleTickerProviderStat
duration: _kFrontLayerSwitchDuration,
child: _category == null
? const Text('Flutter gallery')
: Text(_category.name),
: Text(_category!.name),
),
frontHeading: widget.testMode ? null : Container(height: 24.0),
frontLayer: AnimatedSwitcher(

View File

@@ -21,26 +21,26 @@ class GalleryOptions {
this.showPerformanceOverlay = false,
});
final ThemeMode themeMode;
final GalleryTextScaleValue textScaleFactor;
final GalleryVisualDensityValue visualDensity;
final ThemeMode? themeMode;
final GalleryTextScaleValue? textScaleFactor;
final GalleryVisualDensityValue? visualDensity;
final TextDirection textDirection;
final double timeDilation;
final TargetPlatform platform;
final TargetPlatform? platform;
final bool showPerformanceOverlay;
final bool showRasterCacheImagesCheckerboard;
final bool showOffscreenLayersCheckerboard;
GalleryOptions copyWith({
ThemeMode themeMode,
GalleryTextScaleValue textScaleFactor,
GalleryVisualDensityValue visualDensity,
TextDirection textDirection,
double timeDilation,
TargetPlatform platform,
bool showPerformanceOverlay,
bool showRasterCacheImagesCheckerboard,
bool showOffscreenLayersCheckerboard,
ThemeMode? themeMode,
GalleryTextScaleValue? textScaleFactor,
GalleryVisualDensityValue? visualDensity,
TextDirection? textDirection,
double? timeDilation,
TargetPlatform? platform,
bool? showPerformanceOverlay,
bool? showRasterCacheImagesCheckerboard,
bool? showOffscreenLayersCheckerboard,
}) {
return GalleryOptions(
themeMode: themeMode ?? this.themeMode,
@@ -93,9 +93,9 @@ const double _kItemHeight = 48.0;
const EdgeInsetsDirectional _kItemPadding = EdgeInsetsDirectional.only(start: 56.0);
class _OptionsItem extends StatelessWidget {
const _OptionsItem({ Key key, this.child }) : super(key: key);
const _OptionsItem({ Key? key, this.child }) : super(key: key);
final Widget child;
final Widget? child;
@override
Widget build(BuildContext context) {
@@ -112,7 +112,7 @@ class _OptionsItem extends StatelessWidget {
overflow: TextOverflow.fade,
child: IconTheme(
data: Theme.of(context).primaryIconTheme,
child: child,
child: child!,
),
),
),
@@ -127,7 +127,7 @@ class _BooleanItem extends StatelessWidget {
final bool value;
final ValueChanged<bool> onChanged;
// [switchKey] is used for accessing the switch from driver tests.
final Key switchKey;
final Key? switchKey;
@override
Widget build(BuildContext context) {
@@ -153,7 +153,7 @@ class _ActionItem extends StatelessWidget {
const _ActionItem(this.text, this.onTap);
final String text;
final VoidCallback onTap;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
@@ -167,10 +167,10 @@ class _ActionItem extends StatelessWidget {
}
class _TextButton extends StatelessWidget {
const _TextButton({ Key key, this.onPressed, this.child }) : super(key: key);
const _TextButton({ Key? key, this.onPressed, this.child }) : super(key: key);
final VoidCallback onPressed;
final Widget child;
final VoidCallback? onPressed;
final Widget? child;
@override
Widget build(BuildContext context) {
@@ -182,7 +182,7 @@ class _TextButton extends StatelessWidget {
padding: EdgeInsets.zero,
),
onPressed: onPressed,
child: child,
child: child!,
);
}
}
@@ -197,7 +197,7 @@ class _Heading extends StatelessWidget {
final ThemeData theme = Theme.of(context);
return _OptionsItem(
child: DefaultTextStyle(
style: theme.textTheme.headline6.copyWith(
style: theme.textTheme.headline6!.copyWith(
fontFamily: 'GoogleSans',
color: theme.colorScheme.onPrimary,
fontWeight: FontWeight.w700,
@@ -214,8 +214,8 @@ class _Heading extends StatelessWidget {
class _ThemeModeItem extends StatelessWidget {
const _ThemeModeItem(this.options, this.onOptionsChanged);
final GalleryOptions options;
final ValueChanged<GalleryOptions> onOptionsChanged;
final GalleryOptions? options;
final ValueChanged<GalleryOptions>? onOptionsChanged;
static final Map<ThemeMode, String> modeLabels = <ThemeMode, String>{
ThemeMode.system: 'System Default',
@@ -234,7 +234,7 @@ class _ThemeModeItem extends StatelessWidget {
children: <Widget>[
const Text('Theme'),
Text(
modeLabels[options.themeMode],
modeLabels[options!.themeMode!]!,
style: Theme.of(context).primaryTextTheme.bodyText2,
),
],
@@ -243,18 +243,18 @@ class _ThemeModeItem extends StatelessWidget {
PopupMenuButton<ThemeMode>(
padding: const EdgeInsetsDirectional.only(end: 16.0),
icon: const Icon(Icons.arrow_drop_down),
initialValue: options.themeMode,
initialValue: options!.themeMode,
itemBuilder: (BuildContext context) {
return ThemeMode.values.map<PopupMenuItem<ThemeMode>>((ThemeMode mode) {
return PopupMenuItem<ThemeMode>(
value: mode,
child: Text(modeLabels[mode]),
child: Text(modeLabels[mode]!),
);
}).toList();
},
onSelected: (ThemeMode mode) {
onOptionsChanged(
options.copyWith(themeMode: mode),
onOptionsChanged!(
options!.copyWith(themeMode: mode),
);
},
),
@@ -267,8 +267,8 @@ class _ThemeModeItem extends StatelessWidget {
class _TextScaleFactorItem extends StatelessWidget {
const _TextScaleFactorItem(this.options, this.onOptionsChanged);
final GalleryOptions options;
final ValueChanged<GalleryOptions> onOptionsChanged;
final GalleryOptions? options;
final ValueChanged<GalleryOptions>? onOptionsChanged;
@override
Widget build(BuildContext context) {
@@ -281,7 +281,7 @@ class _TextScaleFactorItem extends StatelessWidget {
children: <Widget>[
const Text('Text size'),
Text(
options.textScaleFactor.label,
options!.textScaleFactor!.label,
style: Theme.of(context).primaryTextTheme.bodyText2,
),
],
@@ -299,8 +299,8 @@ class _TextScaleFactorItem extends StatelessWidget {
}).toList();
},
onSelected: (GalleryTextScaleValue scaleValue) {
onOptionsChanged(
options.copyWith(textScaleFactor: scaleValue),
onOptionsChanged!(
options!.copyWith(textScaleFactor: scaleValue),
);
},
),
@@ -313,8 +313,8 @@ class _TextScaleFactorItem extends StatelessWidget {
class _VisualDensityItem extends StatelessWidget {
const _VisualDensityItem(this.options, this.onOptionsChanged);
final GalleryOptions options;
final ValueChanged<GalleryOptions> onOptionsChanged;
final GalleryOptions? options;
final ValueChanged<GalleryOptions>? onOptionsChanged;
@override
Widget build(BuildContext context) {
@@ -327,7 +327,7 @@ class _VisualDensityItem extends StatelessWidget {
children: <Widget>[
const Text('Visual density'),
Text(
options.visualDensity.label,
options!.visualDensity!.label,
style: Theme.of(context).primaryTextTheme.bodyText2,
),
],
@@ -345,8 +345,8 @@ class _VisualDensityItem extends StatelessWidget {
}).toList();
},
onSelected: (GalleryVisualDensityValue densityValue) {
onOptionsChanged(
options.copyWith(visualDensity: densityValue),
onOptionsChanged!(
options!.copyWith(visualDensity: densityValue),
);
},
),
@@ -359,17 +359,17 @@ class _VisualDensityItem extends StatelessWidget {
class _TextDirectionItem extends StatelessWidget {
const _TextDirectionItem(this.options, this.onOptionsChanged);
final GalleryOptions options;
final ValueChanged<GalleryOptions> onOptionsChanged;
final GalleryOptions? options;
final ValueChanged<GalleryOptions>? onOptionsChanged;
@override
Widget build(BuildContext context) {
return _BooleanItem(
'Force RTL',
options.textDirection == TextDirection.rtl,
options!.textDirection == TextDirection.rtl,
(bool value) {
onOptionsChanged(
options.copyWith(
onOptionsChanged!(
options!.copyWith(
textDirection: value ? TextDirection.rtl : TextDirection.ltr,
),
);
@@ -382,17 +382,17 @@ class _TextDirectionItem extends StatelessWidget {
class _TimeDilationItem extends StatelessWidget {
const _TimeDilationItem(this.options, this.onOptionsChanged);
final GalleryOptions options;
final ValueChanged<GalleryOptions> onOptionsChanged;
final GalleryOptions? options;
final ValueChanged<GalleryOptions>? onOptionsChanged;
@override
Widget build(BuildContext context) {
return _BooleanItem(
'Slow motion',
options.timeDilation != 1.0,
options!.timeDilation != 1.0,
(bool value) {
onOptionsChanged(
options.copyWith(
onOptionsChanged!(
options!.copyWith(
timeDilation: value ? 20.0 : 1.0,
),
);
@@ -405,10 +405,10 @@ class _TimeDilationItem extends StatelessWidget {
class _PlatformItem extends StatelessWidget {
const _PlatformItem(this.options, this.onOptionsChanged);
final GalleryOptions options;
final ValueChanged<GalleryOptions> onOptionsChanged;
final GalleryOptions? options;
final ValueChanged<GalleryOptions>? onOptionsChanged;
String _platformLabel(TargetPlatform platform) {
String? _platformLabel(TargetPlatform? platform) {
switch(platform) {
case TargetPlatform.android:
return 'Mountain View';
@@ -422,9 +422,10 @@ class _PlatformItem extends StatelessWidget {
return 'Material Desktop (macOS)';
case TargetPlatform.windows:
return 'Material Desktop (Windows)';
default:
assert(false);
return null;
}
assert(false);
return null;
}
@override
@@ -438,7 +439,7 @@ class _PlatformItem extends StatelessWidget {
children: <Widget>[
const Text('Platform mechanics'),
Text(
_platformLabel(options.platform),
_platformLabel(options!.platform)!,
style: Theme.of(context).primaryTextTheme.bodyText2,
),
],
@@ -451,13 +452,13 @@ class _PlatformItem extends StatelessWidget {
return TargetPlatform.values.map((TargetPlatform platform) {
return PopupMenuItem<TargetPlatform>(
value: platform,
child: Text(_platformLabel(platform)),
child: Text(_platformLabel(platform)!),
);
}).toList();
},
onSelected: (TargetPlatform platform) {
onOptionsChanged(
options.copyWith(platform: platform),
onOptionsChanged!(
options!.copyWith(platform: platform),
);
},
),
@@ -469,51 +470,46 @@ class _PlatformItem extends StatelessWidget {
class GalleryOptionsPage extends StatelessWidget {
const GalleryOptionsPage({
Key key,
Key? key,
this.options,
this.onOptionsChanged,
this.onSendFeedback,
}) : super(key: key);
final GalleryOptions options;
final ValueChanged<GalleryOptions> onOptionsChanged;
final VoidCallback onSendFeedback;
final GalleryOptions? options;
final ValueChanged<GalleryOptions>? onOptionsChanged;
final VoidCallback? onSendFeedback;
List<Widget> _enabledDiagnosticItems() {
// Boolean showFoo options with a value of null: don't display
// the showFoo option at all.
if (options.showOffscreenLayersCheckerboard == null &&
options.showRasterCacheImagesCheckerboard == null &&
options.showPerformanceOverlay == null)
if (options == null)
return const <Widget>[];
return <Widget>[
const Divider(),
const _Heading('Diagnostics'),
if (options.showOffscreenLayersCheckerboard != null)
_BooleanItem(
'Highlight offscreen layers',
options.showOffscreenLayersCheckerboard,
(bool value) {
onOptionsChanged(options.copyWith(showOffscreenLayersCheckerboard: value));
},
),
if (options.showRasterCacheImagesCheckerboard != null)
_BooleanItem(
'Highlight raster cache images',
options.showRasterCacheImagesCheckerboard,
(bool value) {
onOptionsChanged(options.copyWith(showRasterCacheImagesCheckerboard: value));
},
),
if (options.showPerformanceOverlay != null)
_BooleanItem(
'Show performance overlay',
options.showPerformanceOverlay,
(bool value) {
onOptionsChanged(options.copyWith(showPerformanceOverlay: value));
},
),
_BooleanItem(
'Highlight offscreen layers',
options!.showOffscreenLayersCheckerboard,
(bool value) {
onOptionsChanged!(options!.copyWith(showOffscreenLayersCheckerboard: value));
},
),
_BooleanItem(
'Highlight raster cache images',
options!.showRasterCacheImagesCheckerboard,
(bool value) {
onOptionsChanged!(options!.copyWith(showRasterCacheImagesCheckerboard: value));
},
),
_BooleanItem(
'Show performance overlay',
options!.showPerformanceOverlay,
(bool value) {
onOptionsChanged!(options!.copyWith(showPerformanceOverlay: value));
},
),
];
}
@@ -522,7 +518,7 @@ class GalleryOptionsPage extends StatelessWidget {
final ThemeData theme = Theme.of(context);
return DefaultTextStyle(
style: theme.primaryTextTheme.subtitle1,
style: theme.primaryTextTheme.subtitle1!,
child: ListView(
padding: const EdgeInsets.only(bottom: 124.0),
children: <Widget>[

View File

@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';
class GalleryTextScaleValue {
const GalleryTextScaleValue(this.scale, this.label);
final double scale;
final double? scale;
final String label;
@override

View File

@@ -43,14 +43,14 @@ class SyntaxHighlighterStyle {
);
}
final TextStyle baseStyle;
final TextStyle numberStyle;
final TextStyle commentStyle;
final TextStyle keywordStyle;
final TextStyle stringStyle;
final TextStyle punctuationStyle;
final TextStyle classStyle;
final TextStyle constantStyle;
final TextStyle? baseStyle;
final TextStyle? numberStyle;
final TextStyle? commentStyle;
final TextStyle? keywordStyle;
final TextStyle? stringStyle;
final TextStyle? punctuationStyle;
final TextStyle? classStyle;
final TextStyle? constantStyle;
}
abstract class SyntaxHighlighter {
@@ -63,7 +63,7 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
_style ??= SyntaxHighlighterStyle.darkThemeStyle();
}
SyntaxHighlighterStyle _style;
SyntaxHighlighterStyle? _style;
static const List<String> _keywords = <String>[
'abstract', 'as', 'assert', 'async', 'await', 'break', 'case', 'catch',
@@ -79,15 +79,15 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
'int', 'double', 'num', 'bool',
];
String _src;
StringScanner _scanner;
String? _src;
late StringScanner _scanner;
List<_HighlightSpan> _spans;
late List<_HighlightSpan> _spans;
@override
TextSpan format(String src) {
TextSpan format(String? src) {
_src = src;
_scanner = StringScanner(_src);
_scanner = StringScanner(_src!);
if (_generateSpans()) {
// Successfully parsed the code
@@ -96,20 +96,20 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
for (final _HighlightSpan span in _spans) {
if (currentPosition != span.start)
formattedText.add(TextSpan(text: _src.substring(currentPosition, span.start)));
formattedText.add(TextSpan(text: _src!.substring(currentPosition, span.start)));
formattedText.add(TextSpan(style: span.textStyle(_style), text: span.textForSpan(_src)));
formattedText.add(TextSpan(style: span.textStyle(_style), text: span.textForSpan(_src!)));
currentPosition = span.end;
}
if (currentPosition != _src.length)
formattedText.add(TextSpan(text: _src.substring(currentPosition, _src.length)));
if (currentPosition != _src!.length)
formattedText.add(TextSpan(text: _src!.substring(currentPosition, _src!.length)));
return TextSpan(style: _style.baseStyle, children: formattedText);
return TextSpan(style: _style!.baseStyle, children: formattedText);
} else {
// Parsing failed, return with only basic formatting
return TextSpan(style: _style.baseStyle, text: src);
return TextSpan(style: _style!.baseStyle, text: src);
}
}
@@ -124,23 +124,23 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
if (_scanner.scan(RegExp(r'/\*(.|\n)*\*/'))) {
_spans.add(_HighlightSpan(
_HighlightType.comment,
_scanner.lastMatch.start,
_scanner.lastMatch.end,
_scanner.lastMatch!.start,
_scanner.lastMatch!.end,
));
continue;
}
// Line comments
if (_scanner.scan('//')) {
final int startComment = _scanner.lastMatch.start;
final int startComment = _scanner.lastMatch!.start;
bool eof = false;
int endComment;
if (_scanner.scan(RegExp(r'.*\n'))) {
endComment = _scanner.lastMatch.end - 1;
endComment = _scanner.lastMatch!.end - 1;
} else {
eof = true;
endComment = _src.length;
endComment = _src!.length;
}
_spans.add(_HighlightSpan(
@@ -159,8 +159,8 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
if (_scanner.scan(RegExp(r'r".*"'))) {
_spans.add(_HighlightSpan(
_HighlightType.string,
_scanner.lastMatch.start,
_scanner.lastMatch.end,
_scanner.lastMatch!.start,
_scanner.lastMatch!.end,
));
continue;
}
@@ -169,8 +169,8 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
if (_scanner.scan(RegExp(r"r'.*'"))) {
_spans.add(_HighlightSpan(
_HighlightType.string,
_scanner.lastMatch.start,
_scanner.lastMatch.end,
_scanner.lastMatch!.start,
_scanner.lastMatch!.end,
));
continue;
}
@@ -179,8 +179,8 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
if (_scanner.scan(RegExp(r'"""(?:[^"\\]|\\(.|\n))*"""'))) {
_spans.add(_HighlightSpan(
_HighlightType.string,
_scanner.lastMatch.start,
_scanner.lastMatch.end,
_scanner.lastMatch!.start,
_scanner.lastMatch!.end,
));
continue;
}
@@ -189,8 +189,8 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
if (_scanner.scan(RegExp(r"'''(?:[^'\\]|\\(.|\n))*'''"))) {
_spans.add(_HighlightSpan(
_HighlightType.string,
_scanner.lastMatch.start,
_scanner.lastMatch.end,
_scanner.lastMatch!.start,
_scanner.lastMatch!.end,
));
continue;
}
@@ -199,8 +199,8 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
if (_scanner.scan(RegExp(r'"(?:[^"\\]|\\.)*"'))) {
_spans.add(_HighlightSpan(
_HighlightType.string,
_scanner.lastMatch.start,
_scanner.lastMatch.end,
_scanner.lastMatch!.start,
_scanner.lastMatch!.end,
));
continue;
}
@@ -209,8 +209,8 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
if (_scanner.scan(RegExp(r"'(?:[^'\\]|\\.)*'"))) {
_spans.add(_HighlightSpan(
_HighlightType.string,
_scanner.lastMatch.start,
_scanner.lastMatch.end,
_scanner.lastMatch!.start,
_scanner.lastMatch!.end,
));
continue;
}
@@ -219,8 +219,8 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
if (_scanner.scan(RegExp(r'\d+\.\d+'))) {
_spans.add(_HighlightSpan(
_HighlightType.number,
_scanner.lastMatch.start,
_scanner.lastMatch.end,
_scanner.lastMatch!.start,
_scanner.lastMatch!.end,
));
continue;
}
@@ -229,8 +229,8 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
if (_scanner.scan(RegExp(r'\d+'))) {
_spans.add(_HighlightSpan(
_HighlightType.number,
_scanner.lastMatch.start,
_scanner.lastMatch.end)
_scanner.lastMatch!.start,
_scanner.lastMatch!.end)
);
continue;
}
@@ -239,8 +239,8 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
if (_scanner.scan(RegExp(r'[\[\]{}().!=<>&\|\?\+\-\*/%\^~;:,]'))) {
_spans.add(_HighlightSpan(
_HighlightType.punctuation,
_scanner.lastMatch.start,
_scanner.lastMatch.end,
_scanner.lastMatch!.start,
_scanner.lastMatch!.end,
));
continue;
}
@@ -249,17 +249,17 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
if (_scanner.scan(RegExp(r'@\w+'))) {
_spans.add(_HighlightSpan(
_HighlightType.keyword,
_scanner.lastMatch.start,
_scanner.lastMatch.end,
_scanner.lastMatch!.start,
_scanner.lastMatch!.end,
));
continue;
}
// Words
if (_scanner.scan(RegExp(r'\w+'))) {
_HighlightType type;
_HighlightType? type;
String word = _scanner.lastMatch[0];
String word = _scanner.lastMatch![0]!;
if (word.startsWith('_'))
word = word.substring(1);
@@ -275,8 +275,8 @@ class DartSyntaxHighlighter extends SyntaxHighlighter {
if (type != null) {
_spans.add(_HighlightSpan(
type,
_scanner.lastMatch.start,
_scanner.lastMatch.end,
_scanner.lastMatch!.start,
_scanner.lastMatch!.end,
));
}
}
@@ -335,22 +335,22 @@ class _HighlightSpan {
return src.substring(start, end);
}
TextStyle textStyle(SyntaxHighlighterStyle style) {
TextStyle? textStyle(SyntaxHighlighterStyle? style) {
if (type == _HighlightType.number)
return style.numberStyle;
return style!.numberStyle;
else if (type == _HighlightType.comment)
return style.commentStyle;
return style!.commentStyle;
else if (type == _HighlightType.keyword)
return style.keywordStyle;
return style!.keywordStyle;
else if (type == _HighlightType.string)
return style.stringStyle;
return style!.stringStyle;
else if (type == _HighlightType.punctuation)
return style.punctuationStyle;
return style!.punctuationStyle;
else if (type == _HighlightType.klass)
return style.classStyle;
return style!.classStyle;
else if (type == _HighlightType.constant)
return style.constantStyle;
return style!.constantStyle;
else
return style.baseStyle;
return style!.baseStyle;
}
}

View File

@@ -9,7 +9,7 @@ final ThemeData kDarkGalleryTheme = _buildDarkTheme();
TextTheme _buildTextTheme(TextTheme base) {
return base.copyWith(
headline6: base.headline6.copyWith(
headline6: base.headline6!.copyWith(
fontFamily: 'GoogleSans',
),
);

View File

@@ -9,12 +9,11 @@ import 'package:url_launcher/url_launcher.dart';
typedef UpdateUrlFetcher = Future<String> Function();
class Updater extends StatefulWidget {
const Updater({ @required this.updateUrlFetcher, this.child, Key key })
: assert(updateUrlFetcher != null),
super(key: key);
const Updater({ required this.updateUrlFetcher, this.child, Key? key })
: super(key: key);
final UpdateUrlFetcher updateUrlFetcher;
final Widget child;
final Widget? child;
@override
State createState() => UpdaterState();
@@ -27,27 +26,25 @@ class UpdaterState extends State<Updater> {
_checkForUpdates();
}
static DateTime _lastUpdateCheck;
static DateTime? _lastUpdateCheck;
Future<void> _checkForUpdates() async {
// Only prompt once a day
if (_lastUpdateCheck != null &&
DateTime.now().difference(_lastUpdateCheck) < const Duration(days: 1)) {
DateTime.now().difference(_lastUpdateCheck!) < const Duration(days: 1)) {
return; // We already checked for updates recently
}
_lastUpdateCheck = DateTime.now();
final String updateUrl = await widget.updateUrlFetcher();
if (updateUrl != null) {
final bool wantsUpdate = await showDialog<bool>(context: context, builder: _buildDialog);
if (wantsUpdate != null && wantsUpdate)
launch(updateUrl);
}
final bool? wantsUpdate = await showDialog<bool>(context: context, builder: _buildDialog);
if (wantsUpdate != null && wantsUpdate)
launch(updateUrl);
}
Widget _buildDialog(BuildContext context) {
final ThemeData theme = Theme.of(context);
final TextStyle dialogTextStyle =
theme.textTheme.subtitle1.copyWith(color: theme.textTheme.caption.color);
theme.textTheme.subtitle1!.copyWith(color: theme.textTheme.caption!.color);
return AlertDialog(
title: const Text('Update Flutter Gallery?'),
content: Text('A newer version is available.', style: dialogTextStyle),
@@ -69,5 +66,5 @@ class UpdaterState extends State<Updater> {
}
@override
Widget build(BuildContext context) => widget.child;
Widget build(BuildContext context) => widget.child!;
}

View File

@@ -2,20 +2,23 @@ name: flutter_gallery
environment:
# The pub client defaults to an <2.0.0 sdk constraint which we need to explicitly overwrite.
sdk: ">=2.2.2 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
dependencies:
flutter:
sdk: flutter
collection: 1.15.0-nullsafety.5
device_info: 2.0.0-nullsafety.1
intl: 0.16.1
intl: 0.17.0-nullsafety.2
connectivity: 3.0.0-nullsafety.1
string_scanner: 1.1.0-nullsafety.3
url_launcher: 6.0.0-nullsafety.1
cupertino_icons: 1.0.0
video_player: 2.0.0-nullsafety.2
scoped_model: 1.1.0
scoped_model:
git:
url: https://github.com/kevmoo/scoped_model.git
ref: null_safety
shrine_images: 1.1.2
# Also update dev/benchmarks/complex_layout/pubspec.yaml
@@ -24,6 +27,7 @@ dependencies:
characters: 1.1.0-nullsafety.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
charcode: 1.2.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
clock: 1.1.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
connectivity_macos: 0.1.0+7 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
connectivity_platform_interface: 2.0.0-nullsafety.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
device_info_platform_interface: 2.0.0-nullsafety.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -60,7 +64,6 @@ dev_dependencies:
async: 2.5.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
boolean_selector: 2.1.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
cli_util: 0.2.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
clock: 1.1.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
convert: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
coverage: 0.14.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
crypto: 2.1.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -273,4 +276,4 @@ flutter:
- asset: packages/flutter_gallery_assets/fonts/merriweather/Merriweather-Regular.ttf
- asset: packages/flutter_gallery_assets/fonts/merriweather/Merriweather-Light.ttf
# PUBSPEC CHECKSUM: b589
# PUBSPEC CHECKSUM: 7977

View File

@@ -10,80 +10,80 @@ import 'package:test_api/test_api.dart' hide TypeMatcher, isInstanceOf;
void main() {
test('Test order of operations: 12 + 3 * 4 = 24', () {
CalcExpression expression = CalcExpression.empty();
expression = expression.appendDigit(1);
expression = expression.appendDigit(2);
expression = expression.appendOperation(Operation.Addition);
expression = expression.appendDigit(3);
expression = expression.appendOperation(Operation.Multiplication);
expression = expression.appendDigit(4);
expression = expression.computeResult();
expression = expression.appendDigit(1)!;
expression = expression.appendDigit(2)!;
expression = expression.appendOperation(Operation.Addition)!;
expression = expression.appendDigit(3)!;
expression = expression.appendOperation(Operation.Multiplication)!;
expression = expression.appendDigit(4)!;
expression = expression.computeResult()!;
expect(expression.state, equals(ExpressionState.Result));
expect(expression.toString(), equals('24'));
});
test('Test floating point 0.1 + 0.2 = 0.3', () {
CalcExpression expression = CalcExpression.empty();
expression = expression.appendDigit(0);
expression = expression.appendPoint();
expression = expression.appendDigit(1);
expression = expression.appendOperation(Operation.Addition);
expression = expression.appendDigit(0);
expression = expression.appendPoint();
expression = expression.appendDigit(2);
expression = expression.computeResult();
expression = expression.appendDigit(0)!;
expression = expression.appendPoint()!;
expression = expression.appendDigit(1)!;
expression = expression.appendOperation(Operation.Addition)!;
expression = expression.appendDigit(0)!;
expression = expression.appendPoint()!;
expression = expression.appendDigit(2)!;
expression = expression.computeResult()!;
expect(expression.state, equals(ExpressionState.Result));
expect(expression.toString(), equals('0.3'));
});
test('Test floating point 1.0/10.0 = 0.1', () {
CalcExpression expression = CalcExpression.empty();
expression = expression.appendDigit(1);
expression = expression.appendPoint();
expression = expression.appendDigit(0);
expression = expression.appendOperation(Operation.Division);
expression = expression.appendDigit(1);
expression = expression.appendDigit(0);
expression = expression.appendPoint();
expression = expression.appendDigit(0);
expression = expression.computeResult();
expression = expression.appendDigit(1)!;
expression = expression.appendPoint()!;
expression = expression.appendDigit(0)!;
expression = expression.appendOperation(Operation.Division)!;
expression = expression.appendDigit(1)!;
expression = expression.appendDigit(0)!;
expression = expression.appendPoint()!;
expression = expression.appendDigit(0)!;
expression = expression.computeResult()!;
expect(expression.state, equals(ExpressionState.Result));
expect(expression.toString(), equals('0.1'));
});
test('Test 1/0 = Infinity', () {
CalcExpression expression = CalcExpression.empty();
expression = expression.appendDigit(1);
expression = expression.appendOperation(Operation.Division);
expression = expression.appendDigit(0);
expression = expression.computeResult();
expression = expression.appendDigit(1)!;
expression = expression.appendOperation(Operation.Division)!;
expression = expression.appendDigit(0)!;
expression = expression.computeResult()!;
expect(expression.state, equals(ExpressionState.Result));
expect(expression.toString(), equals('Infinity'));
});
test('Test use result in next calculation: 1 + 1 = 2 + 1 = 3 + 1 = 4', () {
CalcExpression expression = CalcExpression.empty();
expression = expression.appendDigit(1);
expression = expression.appendOperation(Operation.Addition);
expression = expression.appendDigit(1);
expression = expression.computeResult();
expression = expression.appendOperation(Operation.Addition);
expression = expression.appendDigit(1);
expression = expression.computeResult();
expression = expression.appendOperation(Operation.Addition);
expression = expression.appendDigit(1);
expression = expression.computeResult();
expression = expression.appendDigit(1)!;
expression = expression.appendOperation(Operation.Addition)!;
expression = expression.appendDigit(1)!;
expression = expression.computeResult()!;
expression = expression.appendOperation(Operation.Addition)!;
expression = expression.appendDigit(1)!;
expression = expression.computeResult()!;
expression = expression.appendOperation(Operation.Addition)!;
expression = expression.appendDigit(1)!;
expression = expression.computeResult()!;
expect(expression.state, equals(ExpressionState.Result));
expect(expression.toString(), equals('4'));
});
test('Test minus -3 - -2 = -1', () {
CalcExpression expression = CalcExpression.empty();
expression = expression.appendMinus();
expression = expression.appendDigit(3);
expression = expression.appendMinus();
expression = expression.appendMinus();
expression = expression.appendDigit(2);
expression = expression.computeResult();
expression = expression.appendMinus()!;
expression = expression.appendDigit(3)!;
expression = expression.appendMinus()!;
expression = expression.appendMinus()!;
expression = expression.appendDigit(2)!;
expression = expression.computeResult()!;
expect(expression.state, equals(ExpressionState.Result));
expect(expression.toString(), equals('-1'));
});

View File

@@ -37,5 +37,7 @@ void main() {
find.byType(CupertinoNavigationDemo),
matchesGoldenFile('cupertino_navigation_demo.screen.2.png'),
);
});
},
// TODO(egarciad): https://github.com/flutter/flutter/issues/69994
skip: true);
}

View File

@@ -32,8 +32,8 @@ void main() {
// Verify theme settings
MaterialApp app = find.byType(MaterialApp).evaluate().first.widget as MaterialApp;
expect(app.theme.brightness, equals(Brightness.light));
expect(app.darkTheme.brightness, equals(Brightness.dark));
expect(app.theme!.brightness, equals(Brightness.light));
expect(app.darkTheme!.brightness, equals(Brightness.dark));
// Switch to the dark theme: first menu button, choose 'Dark'
await tester.tap(find.byIcon(Icons.arrow_drop_down).first);
@@ -63,7 +63,7 @@ void main() {
expect(app.themeMode, ThemeMode.system);
// Verify density settings
expect(app.theme.visualDensity, equals(const VisualDensity()));
expect(app.theme!.visualDensity, equals(const VisualDensity()));
// Popup the density menu: third menu button, choose 'Compact'
await tester.tap(find.byIcon(Icons.arrow_drop_down).at(2));
@@ -71,7 +71,7 @@ void main() {
await tester.tap(find.text('Compact'));
await tester.pumpAndSettle();
app = find.byType(MaterialApp).evaluate().first.widget as MaterialApp;
expect(app.theme.visualDensity, equals(VisualDensity.compact));
expect(app.theme!.visualDensity, equals(VisualDensity.compact));
await tester.tap(find.byIcon(Icons.arrow_drop_down).at(2));
await tester.pumpAndSettle();
@@ -81,10 +81,10 @@ void main() {
));
await tester.pumpAndSettle();
app = find.byType(MaterialApp).evaluate().first.widget as MaterialApp;
expect(app.theme.visualDensity, equals(const VisualDensity()));
expect(app.theme!.visualDensity, equals(const VisualDensity()));
// Verify platform settings
expect(app.theme.platform, equals(TargetPlatform.android));
expect(app.theme!.platform, equals(TargetPlatform.android));
// Popup the platform menu: fourth menu button, choose 'Cupertino'
await tester.tap(find.byIcon(Icons.arrow_drop_down).at(3));
@@ -92,7 +92,7 @@ void main() {
await tester.tap(find.text('Cupertino').at(1));
await tester.pumpAndSettle();
app = find.byType(MaterialApp).evaluate().first.widget as MaterialApp;
expect(app.theme.platform, equals(TargetPlatform.iOS));
expect(app.theme!.platform, equals(TargetPlatform.iOS));
// Verify the font scale.
final Size origTextSize = tester.getSize(find.text('Text size'));

View File

@@ -12,13 +12,13 @@ void main() {
test('Flutter gallery example code parser test', () async {
final TestAssetBundle bundle = TestAssetBundle();
final String codeSnippet0 = await getExampleCode('test_0', bundle);
final String? codeSnippet0 = await getExampleCode('test_0', bundle);
expect(codeSnippet0, 'test 0 0\ntest 0 1');
final String codeSnippet1 = await getExampleCode('test_1', bundle);
final String? codeSnippet1 = await getExampleCode('test_1', bundle);
expect(codeSnippet1, 'test 1 0\ntest 1 1');
final String codeSnippet3 = await getExampleCode('test_2_windows_breaks', bundle);
final String? codeSnippet3 = await getExampleCode('test_2_windows_breaks', bundle);
expect(codeSnippet3, 'windows test 2 0\nwindows test 2 1');
});
}
@@ -41,13 +41,15 @@ test 1 1
class TestAssetBundle extends AssetBundle {
@override
Future<ByteData> load(String key) async => null;
Future<ByteData> load(String key) async {
return ByteData.sublistView(Uint8List(0));
}
@override
Future<String> loadString(String key, { bool cache = true }) async {
if (key == 'lib/gallery/example_code.dart')
return testCodeFile;
return null;
return '';
}
@override

View File

@@ -60,11 +60,11 @@ Future<void> main() async {
print('Starting app...');
runApp(const GalleryApp(testMode: true));
final _LiveWidgetController controller = _LiveWidgetController(WidgetsBinding.instance);
final _LiveWidgetController controller = _LiveWidgetController(WidgetsBinding.instance!);
for (final GalleryDemoCategory category in kAllGalleryDemoCategories) {
print('Tapping "${category.name}" section...');
await controller.tap(find.text(category.name));
for (final GalleryDemo demo in kGalleryCategoryToDemos[category]) {
for (final GalleryDemo demo in kGalleryCategoryToDemos[category]!) {
final Finder demoItem = find.text(demo.title);
print('Scrolling to "${demo.title}"...');
await controller.scrollIntoView(demoItem, alignment: 0.5);
@@ -110,10 +110,10 @@ class _LiveWidgetController extends LiveWidgetController {
bool frameSync = true;
/// Waits until at the end of a frame the provided [condition] is [true].
Future<void> _waitUntilFrame(bool condition(), [Completer<void> completer]) {
Future<void> _waitUntilFrame(bool condition(), [Completer<void>? completer]) {
completer ??= Completer<void>();
if (!condition()) {
SchedulerBinding.instance.addPostFrameCallback((Duration timestamp) {
SchedulerBinding.instance!.addPostFrameCallback((Duration timestamp) {
_waitUntilFrame(condition, completer);
});
} else {
@@ -133,11 +133,11 @@ class _LiveWidgetController extends LiveWidgetController {
}
@override
Future<void> tap(Finder finder, { int pointer, int buttons = kPrimaryButton }) async {
Future<void> tap(Finder finder, { int? pointer, int buttons = kPrimaryButton }) async {
await super.tap(await _waitForElement(finder), pointer: pointer, buttons: buttons);
}
Future<void> scrollIntoView(Finder finder, {double alignment}) async {
Future<void> scrollIntoView(Finder finder, {required double alignment}) async {
final Finder target = await _waitForElement(finder);
await Scrollable.ensureVisible(target.evaluate().single, duration: const Duration(milliseconds: 100), alignment: alignment);
}

View File

@@ -77,9 +77,9 @@ Future<void> smokeDemo(WidgetTester tester, GalleryDemo demo) async {
// Verify that the dumps are pretty.
final String routeName = demo.routeName;
verifyToStringOutput('debugDumpApp', routeName, WidgetsBinding.instance.renderViewElement.toStringDeep());
verifyToStringOutput('debugDumpRenderTree', routeName, RendererBinding.instance?.renderView?.toStringDeep());
verifyToStringOutput('debugDumpLayerTree', routeName, RendererBinding.instance?.renderView?.debugLayer?.toStringDeep());
verifyToStringOutput('debugDumpApp', routeName, WidgetsBinding.instance!.renderViewElement!.toStringDeep());
verifyToStringOutput('debugDumpRenderTree', routeName, RendererBinding.instance?.renderView.toStringDeep() ?? '');
verifyToStringOutput('debugDumpLayerTree', routeName, RendererBinding.instance?.renderView.debugLayer?.toStringDeep() ?? '');
// Scroll the demo around a bit more.
await tester.flingFrom(const Offset(400.0, 300.0), const Offset(0.0, 400.0), 1000.0);
@@ -161,7 +161,7 @@ Future<void> smokeGallery(WidgetTester tester) async {
await Scrollable.ensureVisible(tester.element(find.text(category.name)), alignment: 0.5);
await tester.tap(find.text(category.name));
await tester.pumpAndSettle();
for (final GalleryDemo demo in kGalleryCategoryToDemos[category]) {
for (final GalleryDemo demo in kGalleryCategoryToDemos[category]!) {
await Scrollable.ensureVisible(tester.element(find.text(demo.title)), alignment: 0.0);
await smokeDemo(tester, demo);
tester.binding.debugAssertNoTransientCallbacks('A transient callback was still active after running $demo');
@@ -179,8 +179,8 @@ void main() {
testWidgets('Flutter Gallery app smoke test', smokeGallery);
testWidgets('Flutter Gallery app smoke test with semantics', (WidgetTester tester) async {
RendererBinding.instance.setSemanticsEnabled(true);
RendererBinding.instance!.setSemanticsEnabled(true);
await smokeGallery(tester);
RendererBinding.instance.setSemanticsEnabled(false);
RendererBinding.instance!.setSemanticsEnabled(false);
});
}

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
// @dart = 2.9
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
// @dart = 2.9
import 'package:flutter_driver/flutter_driver.dart';
import 'package:test/test.dart' hide TypeMatcher, isInstanceOf;

View File

@@ -47,7 +47,7 @@ class _MessageHandler {
}
void main() {
enableFlutterDriverExtension(handler: _MessageHandler());
enableFlutterDriverExtension(handler: _MessageHandler().call);
// As in lib/main.dart: overriding https://github.com/flutter/flutter/issues/13736
// for better visual effect at the cost of performance.
runApp(const GalleryApp(testMode: true));

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
// @dart = 2.9
import 'package:integration_test/integration_test_driver.dart' as driver;
Future<void> main() => driver.integrationDriver(

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
// @dart = 2.9
import 'transitions_perf_test.dart' as transitions_perf_test;
void main([List<String> args = const <String>[]]) => transitions_perf_test.main(

View File

@@ -3,6 +3,7 @@
// found in the LICENSE file.
// @dart = 2.9
import 'dart:convert' show JsonEncoder, json;
import 'package:file/file.dart';

View File

@@ -11,12 +11,13 @@ dependencies:
flutter_tools:
path: '../../packages/flutter_tools'
http: 0.12.2
intl: 0.16.1
intl: 0.17.0-nullsafety.2
meta: 1.3.0-nullsafety.6
path: 1.8.0-nullsafety.3
process: 4.0.0-nullsafety.4
charcode: 1.2.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
clock: 1.1.0-nullsafety.3 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
collection: 1.15.0-nullsafety.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
convert: 2.1.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
crypto: 2.1.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -70,4 +71,4 @@ dev_dependencies:
webkit_inspection_protocol: 0.7.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
yaml: 2.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
# PUBSPEC CHECKSUM: 52ad
# PUBSPEC CHECKSUM: 27b7

View File

@@ -66,7 +66,7 @@ dependencies:
protobuf: 1.1.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pub_semver: 1.4.4 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
pubspec_parse: 0.1.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
quiver: 2.1.4+1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
quiver: 2.1.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
scratch_space: 0.0.4+2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
shelf: 0.7.5 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
shelf_packages_handler: 2.0.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade"
@@ -93,4 +93,4 @@ dartdoc:
# Exclude this package from the hosted API docs.
nodoc: true
# PUBSPEC CHECKSUM: a6fe
# PUBSPEC CHECKSUM: 3ea3

Some files were not shown because too many files have changed in this diff Show More