mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Migrate more doc samples (#72392)
This commit is contained in:
parent
0dc80621eb
commit
a665dd1cab
@ -11,8 +11,7 @@ import 'framework.dart';
|
||||
import 'image.dart';
|
||||
|
||||
// Examples can assume:
|
||||
// // @dart = 2.9
|
||||
// BuildContext context;
|
||||
// late BuildContext context;
|
||||
|
||||
/// A widget that paints a [Decoration] either before or after its child paints.
|
||||
///
|
||||
@ -219,7 +218,7 @@ class DecoratedBox extends SingleChildRenderObjectWidget {
|
||||
/// ```dart
|
||||
/// Container(
|
||||
/// constraints: BoxConstraints.expand(
|
||||
/// height: Theme.of(context).textTheme.headline4.fontSize * 1.1 + 200.0,
|
||||
/// height: Theme.of(context).textTheme.headline4!.fontSize! * 1.1 + 200.0,
|
||||
/// ),
|
||||
/// padding: const EdgeInsets.all(8.0),
|
||||
/// color: Colors.blue[600],
|
||||
@ -227,7 +226,7 @@ class DecoratedBox extends SingleChildRenderObjectWidget {
|
||||
/// child: Text('Hello World',
|
||||
/// style: Theme.of(context)
|
||||
/// .textTheme
|
||||
/// .headline4
|
||||
/// .headline4!
|
||||
/// .copyWith(color: Colors.white)),
|
||||
/// transform: Matrix4.rotationZ(0.1),
|
||||
/// )
|
||||
|
@ -14,8 +14,7 @@ import 'implicit_animations.dart';
|
||||
import 'transitions.dart';
|
||||
|
||||
// Examples can assume:
|
||||
// // @dart = 2.9
|
||||
// Uint8List bytes;
|
||||
// late Uint8List bytes;
|
||||
|
||||
/// An image that shows a [placeholder] image while the target [image] is
|
||||
/// loading, then fades in the new image when it loads.
|
||||
|
@ -30,12 +30,11 @@ export 'package:flutter/foundation.dart' show Key, LocalKey, ValueKey;
|
||||
export 'package:flutter/rendering.dart' show RenderObject, RenderBox, debugDumpRenderTree, debugDumpLayerTree;
|
||||
|
||||
// Examples can assume:
|
||||
// // @dart = 2.9
|
||||
// BuildContext context;
|
||||
// late BuildContext context;
|
||||
// void setState(VoidCallback fn) { }
|
||||
// abstract class RenderFrogJar extends RenderObject { }
|
||||
// abstract class FrogJar extends RenderObjectWidget { }
|
||||
// abstract class FrogJarParentData extends ParentData { Size size; }
|
||||
// abstract class FrogJarParentData extends ParentData { late Size size; }
|
||||
|
||||
// KEYS
|
||||
|
||||
@ -624,7 +623,7 @@ abstract class Widget extends DiagnosticableTree {
|
||||
///
|
||||
/// ```dart
|
||||
/// class GreenFrog extends StatelessWidget {
|
||||
/// const GreenFrog({ Key key }) : super(key: key);
|
||||
/// const GreenFrog({ Key? key }) : super(key: key);
|
||||
///
|
||||
/// @override
|
||||
/// Widget build(BuildContext context) {
|
||||
@ -642,13 +641,13 @@ abstract class Widget extends DiagnosticableTree {
|
||||
/// ```dart
|
||||
/// class Frog extends StatelessWidget {
|
||||
/// const Frog({
|
||||
/// Key key,
|
||||
/// Key? key,
|
||||
/// this.color = const Color(0xFF2DBD3A),
|
||||
/// this.child,
|
||||
/// }) : super(key: key);
|
||||
///
|
||||
/// final Color color;
|
||||
/// final Widget child;
|
||||
/// final Widget? child;
|
||||
///
|
||||
/// @override
|
||||
/// Widget build(BuildContext context) {
|
||||
@ -841,7 +840,7 @@ abstract class StatelessWidget extends Widget {
|
||||
///
|
||||
/// ```dart
|
||||
/// class YellowBird extends StatefulWidget {
|
||||
/// const YellowBird({ Key key }) : super(key: key);
|
||||
/// const YellowBird({ Key? key }) : super(key: key);
|
||||
///
|
||||
/// @override
|
||||
/// _YellowBirdState createState() => _YellowBirdState();
|
||||
@ -864,13 +863,13 @@ abstract class StatelessWidget extends Widget {
|
||||
/// ```dart
|
||||
/// class Bird extends StatefulWidget {
|
||||
/// const Bird({
|
||||
/// Key key,
|
||||
/// Key? key,
|
||||
/// this.color = const Color(0xFFFFE306),
|
||||
/// this.child,
|
||||
/// }) : super(key: key);
|
||||
///
|
||||
/// final Color color;
|
||||
/// final Widget child;
|
||||
/// final Widget? child;
|
||||
///
|
||||
/// _BirdState createState() => _BirdState();
|
||||
/// }
|
||||
@ -1531,21 +1530,19 @@ abstract class ProxyWidget extends Widget {
|
||||
/// ```dart
|
||||
/// class FrogSize extends ParentDataWidget<FrogJarParentData> {
|
||||
/// FrogSize({
|
||||
/// Key key,
|
||||
/// @required this.size,
|
||||
/// @required Widget child,
|
||||
/// }) : assert(child != null),
|
||||
/// assert(size != null),
|
||||
/// super(key: key, child: child);
|
||||
/// Key? key,
|
||||
/// required this.size,
|
||||
/// required Widget child,
|
||||
/// }) : super(key: key, child: child);
|
||||
///
|
||||
/// final Size size;
|
||||
///
|
||||
/// @override
|
||||
/// void applyParentData(RenderObject renderObject) {
|
||||
/// final FrogJarParentData parentData = renderObject.parentData;
|
||||
/// final FrogJarParentData parentData = renderObject.parentData! as FrogJarParentData;
|
||||
/// if (parentData.size != size) {
|
||||
/// parentData.size = size;
|
||||
/// final RenderFrogJar targetParent = renderObject.parent;
|
||||
/// final RenderFrogJar targetParent = renderObject.parent! as RenderFrogJar;
|
||||
/// targetParent.markNeedsLayout();
|
||||
/// }
|
||||
/// }
|
||||
@ -1684,17 +1681,17 @@ abstract class ParentDataWidget<T extends ParentData> extends ProxyWidget {
|
||||
/// ```dart
|
||||
/// class FrogColor extends InheritedWidget {
|
||||
/// const FrogColor({
|
||||
/// Key key,
|
||||
/// @required this.color,
|
||||
/// @required Widget child,
|
||||
/// }) : assert(color != null),
|
||||
/// assert(child != null),
|
||||
/// super(key: key, child: child);
|
||||
/// Key? key,
|
||||
/// required this.color,
|
||||
/// required Widget child,
|
||||
/// }) : super(key: key, child: child);
|
||||
///
|
||||
/// final Color color;
|
||||
///
|
||||
/// static FrogColor of(BuildContext context) {
|
||||
/// return context.dependOnInheritedWidgetOfExactType<FrogColor>();
|
||||
/// final FrogColor? result = context.dependOnInheritedWidgetOfExactType<FrogColor>();
|
||||
/// assert(result != null, 'No FrogColor found in context');
|
||||
/// return result!;
|
||||
/// }
|
||||
///
|
||||
/// @override
|
||||
@ -2420,7 +2417,7 @@ abstract class BuildContext {
|
||||
/// {@tool snippet}
|
||||
///
|
||||
/// ```dart
|
||||
/// ScrollableState scrollable = context.findAncestorStateOfType<ScrollableState>();
|
||||
/// ScrollableState? scrollable = context.findAncestorStateOfType<ScrollableState>();
|
||||
/// ```
|
||||
/// {@end-tool}
|
||||
T? findAncestorStateOfType<T extends State>();
|
||||
@ -4436,7 +4433,7 @@ typedef ErrorWidgetBuilder = Widget Function(FlutterErrorDetails details);
|
||||
///
|
||||
/// It is possible to override this widget.
|
||||
///
|
||||
/// {@tool sample --template=freeform_no_null_safety}
|
||||
/// {@tool sample --template=freeform}
|
||||
/// ```dart
|
||||
/// import 'package:flutter/material.dart';
|
||||
///
|
||||
|
@ -27,9 +27,6 @@ import 'sliver.dart';
|
||||
import 'sliver_fill.dart';
|
||||
import 'viewport.dart';
|
||||
|
||||
// Examples can assume:
|
||||
// // @dart = 2.9
|
||||
|
||||
/// A controller for [PageView].
|
||||
///
|
||||
/// A page controller lets you manipulate which page is visible in a [PageView].
|
||||
@ -49,19 +46,13 @@ import 'viewport.dart';
|
||||
///
|
||||
/// ```dart
|
||||
/// class MyPageView extends StatefulWidget {
|
||||
/// MyPageView({Key key}) : super(key: key);
|
||||
/// MyPageView({Key? key}) : super(key: key);
|
||||
///
|
||||
/// _MyPageViewState createState() => _MyPageViewState();
|
||||
/// }
|
||||
///
|
||||
/// class _MyPageViewState extends State<MyPageView> {
|
||||
/// PageController _pageController;
|
||||
///
|
||||
/// @override
|
||||
/// void initState() {
|
||||
/// super.initState();
|
||||
/// _pageController = PageController();
|
||||
/// }
|
||||
/// PageController _pageController = PageController();
|
||||
///
|
||||
/// @override
|
||||
/// void dispose() {
|
||||
@ -725,7 +716,7 @@ class PageView extends StatefulWidget {
|
||||
/// },
|
||||
/// childCount: items.length,
|
||||
/// findChildIndexCallback: (Key key) {
|
||||
/// final ValueKey valueKey = key;
|
||||
/// final ValueKey<String> valueKey = key as ValueKey<String>;
|
||||
/// final String data = valueKey.value;
|
||||
/// return items.indexOf(data);
|
||||
/// }
|
||||
@ -748,7 +739,7 @@ class PageView extends StatefulWidget {
|
||||
/// }
|
||||
///
|
||||
/// class KeepAlive extends StatefulWidget {
|
||||
/// const KeepAlive({Key key, this.data}) : super(key: key);
|
||||
/// const KeepAlive({Key? key, required this.data}) : super(key: key);
|
||||
///
|
||||
/// final String data;
|
||||
///
|
||||
|
@ -17,12 +17,15 @@ import 'scroll_simulation.dart';
|
||||
export 'package:flutter/physics.dart' show Simulation, ScrollSpringSimulation, Tolerance;
|
||||
|
||||
// Examples can assume:
|
||||
// // @dart = 2.9
|
||||
// class FooScrollPhysics extends ScrollPhysics {
|
||||
// const FooScrollPhysics({ ScrollPhysics parent }): super(parent: parent);
|
||||
// const FooScrollPhysics({ ScrollPhysics? parent }): super(parent: parent);
|
||||
// @override
|
||||
// FooScrollPhysics applyTo(ScrollPhysics? ancestor) {
|
||||
// return FooScrollPhysics(parent: buildParent(ancestor));
|
||||
// }
|
||||
// }
|
||||
// class BarScrollPhysics extends ScrollPhysics {
|
||||
// const BarScrollPhysics({ ScrollPhysics parent }): super(parent: parent);
|
||||
// const BarScrollPhysics({ ScrollPhysics? parent }): super(parent: parent);
|
||||
// }
|
||||
|
||||
/// Determines the physics of a [Scrollable] widget.
|
||||
|
@ -6,9 +6,6 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import 'framework.dart';
|
||||
|
||||
// Examples can assume:
|
||||
// // @dart = 2.9
|
||||
|
||||
/// Builds a [Widget] when given a concrete value of a [ValueListenable<T>].
|
||||
///
|
||||
/// If the `child` parameter provided to the [ValueListenableBuilder] is not
|
||||
@ -50,7 +47,7 @@ typedef ValueWidgetBuilder<T> = Widget Function(BuildContext context, T value, W
|
||||
///
|
||||
/// ```dart
|
||||
/// class MyHomePage extends StatefulWidget {
|
||||
/// MyHomePage({Key key, this.title}) : super(key: key);
|
||||
/// MyHomePage({Key? key, required this.title}) : super(key: key);
|
||||
/// final String title;
|
||||
///
|
||||
/// @override
|
||||
@ -72,14 +69,14 @@ typedef ValueWidgetBuilder<T> = Widget Function(BuildContext context, T value, W
|
||||
/// children: <Widget>[
|
||||
/// Text('You have pushed the button this many times:'),
|
||||
/// ValueListenableBuilder(
|
||||
/// builder: (BuildContext context, int value, Widget child) {
|
||||
/// builder: (BuildContext context, int value, Widget? child) {
|
||||
/// // This builder will only get called when the _counter
|
||||
/// // is updated.
|
||||
/// return Row(
|
||||
/// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
/// children: <Widget>[
|
||||
/// Text('$value'),
|
||||
/// child,
|
||||
/// child!,
|
||||
/// ],
|
||||
/// );
|
||||
/// },
|
||||
|
Loading…
Reference in New Issue
Block a user