Unverified Commit 19078b1a authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

migrate cupertino to nullsafety (#66493)

parent 48ce83a8
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
/// Flutter widgets implementing the current iOS design language.
///
/// To use, import `package:flutter/cupertino.dart`.
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/widgets.dart';
import 'colors.dart';
......@@ -22,11 +20,11 @@ import 'theme.dart';
class CupertinoPageScaffold extends StatefulWidget {
/// Creates a layout for pages with a navigation bar at the top.
const CupertinoPageScaffold({
Key key,
Key? key,
this.navigationBar,
this.backgroundColor,
this.resizeToAvoidBottomInset = true,
@required this.child,
required this.child,
}) : assert(child != null),
assert(resizeToAvoidBottomInset != null),
super(key: key);
......@@ -48,7 +46,7 @@ class CupertinoPageScaffold extends StatefulWidget {
/// in many ways, such as querying [MediaQuery.textScaleFactorOf] against
/// [CupertinoApp]'s [BuildContext].
// TODO(xster): document its page transition animation when ready
final ObstructingPreferredSizeWidget navigationBar;
final ObstructingPreferredSizeWidget? navigationBar;
/// Widget to show in the main content area.
///
......@@ -61,7 +59,7 @@ class CupertinoPageScaffold extends StatefulWidget {
/// The color of the widget that underlies the entire scaffold.
///
/// By default uses [CupertinoTheme]'s `scaffoldBackgroundColor` when null.
final Color backgroundColor;
final Color? backgroundColor;
/// Whether the [child] should size itself to avoid the window's bottom inset.
///
......@@ -95,12 +93,12 @@ class _CupertinoPageScaffoldState extends State<CupertinoPageScaffold> {
Widget build(BuildContext context) {
Widget paddedContent = widget.child;
final MediaQueryData existingMediaQuery = MediaQuery.of(context);
final MediaQueryData existingMediaQuery = MediaQuery.of(context)!;
if (widget.navigationBar != null) {
// TODO(xster): Use real size after partial layout instead of preferred size.
// https://github.com/flutter/flutter/issues/12912
final double topPadding =
widget.navigationBar.preferredSize.height + existingMediaQuery.padding.top;
widget.navigationBar!.preferredSize.height + existingMediaQuery.padding.top;
// Propagate bottom padding and include viewInsets if appropriate
final double bottomPadding = widget.resizeToAvoidBottomInset
......@@ -113,7 +111,7 @@ class _CupertinoPageScaffoldState extends State<CupertinoPageScaffold> {
? existingMediaQuery.viewInsets.copyWith(bottom: 0.0)
: existingMediaQuery.viewInsets;
final bool fullObstruction = widget.navigationBar.shouldFullyObstruct(context);
final bool fullObstruction = widget.navigationBar!.shouldFullyObstruct(context);
// If navigation bar is opaquely obstructing, directly shift the main content
// down. If translucent, let main content draw behind navigation bar but hint the
......@@ -176,7 +174,7 @@ class _CupertinoPageScaffoldState extends State<CupertinoPageScaffold> {
right: 0.0,
child: MediaQuery(
data: existingMediaQuery.copyWith(textScaleFactor: 1),
child: widget.navigationBar,
child: widget.navigationBar!,
),
),
// Add a touch handler the size of the status bar on top of all contents
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'bottom_tab_bar.dart';
......@@ -207,9 +205,9 @@ class CupertinoTabScaffold extends StatefulWidget {
///
/// The [tabBar] and [tabBuilder] arguments must not be null.
CupertinoTabScaffold({
Key key,
@required this.tabBar,
@required this.tabBuilder,
Key? key,
required this.tabBar,
required this.tabBuilder,
this.controller,
this.backgroundColor,
this.resizeToAvoidBottomInset = true,
......@@ -258,7 +256,7 @@ class CupertinoTabScaffold extends StatefulWidget {
/// index value.
///
/// Defaults to null.
final CupertinoTabController controller;
final CupertinoTabController? controller;
/// An [IndexedWidgetBuilder] that's called when tabs become active.
///
......@@ -280,7 +278,7 @@ class CupertinoTabScaffold extends StatefulWidget {
/// The color of the widget that underlies the entire scaffold.
///
/// By default uses [CupertinoTheme]'s `scaffoldBackgroundColor` when null.
final Color backgroundColor;
final Color? backgroundColor;
/// Whether the body should size itself to avoid the window's bottom inset.
///
......@@ -296,7 +294,7 @@ class CupertinoTabScaffold extends StatefulWidget {
}
class _CupertinoTabScaffoldState extends State<CupertinoTabScaffold> {
CupertinoTabController _controller;
CupertinoTabController? _controller;
@override
void initState() {
......@@ -317,7 +315,7 @@ class _CupertinoTabScaffoldState extends State<CupertinoTabScaffold> {
if (shouldDisposeOldController) {
_controller?.dispose();
} else if (_controller?._isDisposed == false) {
_controller.removeListener(_onCurrentIndexChange);
_controller!.removeListener(_onCurrentIndexChange);
}
newController.addListener(_onCurrentIndexChange);
......@@ -326,8 +324,8 @@ class _CupertinoTabScaffoldState extends State<CupertinoTabScaffold> {
void _onCurrentIndexChange() {
assert(
_controller.index >= 0 && _controller.index < widget.tabBar.items.length,
"The $runtimeType's current index ${_controller.index} is "
_controller!.index >= 0 && _controller!.index < widget.tabBar.items.length,
"The $runtimeType's current index ${_controller!.index} is "
'out of bounds for the tab bar with ${widget.tabBar.items.length} tabs'
);
......@@ -341,20 +339,20 @@ class _CupertinoTabScaffoldState extends State<CupertinoTabScaffold> {
super.didUpdateWidget(oldWidget);
if (widget.controller != oldWidget.controller) {
_updateTabController(shouldDisposeOldController: oldWidget.controller == null);
} else if (_controller.index >= widget.tabBar.items.length) {
} else if (_controller!.index >= widget.tabBar.items.length) {
// If a new [tabBar] with less than (_controller.index + 1) items is provided,
// clamp the current index.
_controller.index = widget.tabBar.items.length - 1;
_controller!.index = widget.tabBar.items.length - 1;
}
}
@override
Widget build(BuildContext context) {
final MediaQueryData existingMediaQuery = MediaQuery.of(context);
MediaQueryData newMediaQuery = MediaQuery.of(context);
final MediaQueryData existingMediaQuery = MediaQuery.of(context)!;
MediaQueryData newMediaQuery = MediaQuery.of(context)!;
Widget content = _TabSwitchingView(
currentTabIndex: _controller.index,
currentTabIndex: _controller!.index,
tabCount: widget.tabBar.items.length,
tabBuilder: widget.tabBuilder,
);
......@@ -417,12 +415,11 @@ class _CupertinoTabScaffoldState extends State<CupertinoTabScaffold> {
// our own listener to update the [_controller.currentIndex] on top of a possibly user
// provided callback.
child: widget.tabBar.copyWith(
currentIndex: _controller.index,
currentIndex: _controller!.index,
onTap: (int newIndex) {
_controller.index = newIndex;
_controller!.index = newIndex;
// Chain the user's original callback.
if (widget.tabBar.onTap != null)
widget.tabBar.onTap(newIndex);
widget.tabBar.onTap?.call(newIndex);
},
),
),
......@@ -438,7 +435,7 @@ class _CupertinoTabScaffoldState extends State<CupertinoTabScaffold> {
if (widget.controller == null) {
_controller?.dispose();
} else if (_controller?._isDisposed == false) {
_controller.removeListener(_onCurrentIndexChange);
_controller!.removeListener(_onCurrentIndexChange);
}
super.dispose();
......@@ -449,9 +446,9 @@ class _CupertinoTabScaffoldState extends State<CupertinoTabScaffold> {
/// at a time and on stage. Off stage tabs' animations are stopped.
class _TabSwitchingView extends StatefulWidget {
const _TabSwitchingView({
@required this.currentTabIndex,
@required this.tabCount,
@required this.tabBuilder,
required this.currentTabIndex,
required this.tabCount,
required this.tabBuilder,
}) : assert(currentTabIndex != null),
assert(tabCount != null && tabCount > 0),
assert(tabBuilder != null);
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/widgets.dart';
import 'app.dart' show CupertinoApp;
......@@ -43,7 +41,7 @@ import 'route.dart';
class CupertinoTabView extends StatefulWidget {
/// Creates the content area for a tab in a [CupertinoTabScaffold].
const CupertinoTabView({
Key key,
Key? key,
this.builder,
this.navigatorKey,
this.defaultTitle,
......@@ -68,7 +66,7 @@ class CupertinoTabView extends StatefulWidget {
/// * Calling [State.setState] on a descendant [StatefulWidget]'s [State]
/// * Modifying an [InheritedWidget] that a descendant registered itself
/// as a dependent to.
final WidgetBuilder builder;
final WidgetBuilder? builder;
/// A key to use when building this widget's [Navigator].
///
......@@ -81,10 +79,10 @@ class CupertinoTabView extends StatefulWidget {
/// tab's state in the process; in that case, the [navigatorObservers]
/// must also be changed, since the previous observers will be attached to the
/// previous navigator.
final GlobalKey<NavigatorState> navigatorKey;
final GlobalKey<NavigatorState>? navigatorKey;
/// The title of the default route.
final String defaultTitle;
final String? defaultTitle;
/// This tab view's routing table.
///
......@@ -105,12 +103,12 @@ class CupertinoTabView extends StatefulWidget {
///
/// This routing table is not shared with any routing tables of ancestor or
/// descendant [Navigator]s.
final Map<String, WidgetBuilder> routes;
final Map<String, WidgetBuilder>? routes;
/// The route generator callback used when the tab view is navigated to a named route.
///
/// This is used if [routes] does not contain the requested route.
final RouteFactory onGenerateRoute;
final RouteFactory? onGenerateRoute;
/// Called when [onGenerateRoute] also fails to generate a route.
///
......@@ -120,7 +118,7 @@ class CupertinoTabView extends StatefulWidget {
///
/// The default implementation pushes a route that displays an ugly error
/// message.
final RouteFactory onUnknownRoute;
final RouteFactory? onUnknownRoute;
/// The list of observers for the [Navigator] created in this tab view.
///
......@@ -134,8 +132,8 @@ class CupertinoTabView extends StatefulWidget {
}
class _CupertinoTabViewState extends State<CupertinoTabView> {
HeroController _heroController;
List<NavigatorObserver> _navigatorObservers;
late HeroController _heroController;
late List<NavigatorObserver> _navigatorObservers;
@override
void initState() {
......@@ -169,15 +167,15 @@ class _CupertinoTabViewState extends State<CupertinoTabView> {
);
}
Route<dynamic> _onGenerateRoute(RouteSettings settings) {
final String name = settings.name;
WidgetBuilder routeBuilder;
String title;
Route<dynamic>? _onGenerateRoute(RouteSettings settings) {
final String? name = settings.name;
WidgetBuilder? routeBuilder;
String? title;
if (name == Navigator.defaultRouteName && widget.builder != null) {
routeBuilder = widget.builder;
routeBuilder = widget.builder!;
title = widget.defaultTitle;
} else if (widget.routes != null) {
routeBuilder = widget.routes[name];
routeBuilder = widget.routes![name];
}
if (routeBuilder != null) {
return CupertinoPageRoute<dynamic>(
......@@ -187,11 +185,11 @@ class _CupertinoTabViewState extends State<CupertinoTabView> {
);
}
if (widget.onGenerateRoute != null)
return widget.onGenerateRoute(settings);
return widget.onGenerateRoute!(settings);
return null;
}
Route<dynamic> _onUnknownRoute(RouteSettings settings) {
Route<dynamic>? _onUnknownRoute(RouteSettings settings) {
assert(() {
if (widget.onUnknownRoute == null) {
throw FlutterError(
......@@ -208,7 +206,7 @@ class _CupertinoTabViewState extends State<CupertinoTabView> {
}
return true;
}());
final Route<dynamic> result = widget.onUnknownRoute(settings);
final Route<dynamic>? result = widget.onUnknownRoute!(settings);
assert(() {
if (result == null) {
throw FlutterError(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment