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