Unverified Commit a8e26069 authored by Abhishek Ghaskata's avatar Abhishek Ghaskata Committed by GitHub

Migrate manual_tests to null safety (#82611)

parent aae6cc8e
......@@ -23,9 +23,9 @@ void main() {
/// the undo stack when they are invoked.
class Memento extends Object with Diagnosticable {
const Memento({
@required this.name,
@required this.undo,
@required this.redo,
required this.name,
required this.undo,
required this.redo,
});
/// Returns true if this Memento can be used to undo.
......@@ -110,11 +110,11 @@ class UndoableActionDispatcher extends ActionDispatcher implements Listenable {
}
@override
Object invokeAction(Action<Intent> action, Intent intent, [BuildContext context]) {
final Object result = super.invokeAction(action, intent, context);
Object? invokeAction(Action<Intent> action, Intent intent, [BuildContext? context]) {
final Object? result = super.invokeAction(action, intent, context);
print('Invoking ${action is UndoableAction ? 'undoable ' : ''}$intent as $action: $this ');
if (action is UndoableAction) {
_completedActions.addLast(result as Memento);
_completedActions.addLast(result! as Memento);
_undoneActions.clear();
_pruneActions();
notifyListeners();
......@@ -193,14 +193,22 @@ class UndoIntent extends Intent {
class UndoAction extends Action<UndoIntent> {
@override
bool isEnabled(UndoIntent intent) {
final UndoableActionDispatcher manager = Actions.of(primaryFocus?.context ?? FocusDemo.appKey.currentContext) as UndoableActionDispatcher;
final BuildContext? buildContext = primaryFocus?.context ?? FocusDemo.appKey.currentContext;
if (buildContext == null) {
return false;
}
final UndoableActionDispatcher manager = Actions.of(buildContext) as UndoableActionDispatcher;
return manager.canUndo;
}
@override
void invoke(UndoIntent intent) {
final UndoableActionDispatcher manager = Actions.of(primaryFocus?.context ?? FocusDemo.appKey.currentContext) as UndoableActionDispatcher;
manager?.undo();
final BuildContext? buildContext = primaryFocus?.context ?? FocusDemo.appKey.currentContext;
if (buildContext == null) {
return;
}
final UndoableActionDispatcher manager = Actions.of(primaryFocus?.context ?? FocusDemo.appKey.currentContext!) as UndoableActionDispatcher;
manager.undo();
}
}
......@@ -211,14 +219,22 @@ class RedoIntent extends Intent {
class RedoAction extends Action<RedoIntent> {
@override
bool isEnabled(RedoIntent intent) {
final UndoableActionDispatcher manager = Actions.of(primaryFocus.context) as UndoableActionDispatcher;
final BuildContext? buildContext = primaryFocus?.context ?? FocusDemo.appKey.currentContext;
if (buildContext == null) {
return false;
}
final UndoableActionDispatcher manager = Actions.of(buildContext) as UndoableActionDispatcher;
return manager.canRedo;
}
@override
RedoAction invoke(RedoIntent intent) {
final UndoableActionDispatcher manager = Actions.of(primaryFocus.context) as UndoableActionDispatcher;
manager?.redo();
final BuildContext? buildContext = primaryFocus?.context ?? FocusDemo.appKey.currentContext;
if (buildContext == null) {
return this;
}
final UndoableActionDispatcher manager = Actions.of(buildContext) as UndoableActionDispatcher;
manager.redo();
return this;
}
}
......@@ -226,11 +242,11 @@ class RedoAction extends Action<RedoIntent> {
/// An action that can be undone.
abstract class UndoableAction<T extends Intent> extends Action<T> {
/// The [Intent] this action was originally invoked with.
Intent get invocationIntent => _invocationTag;
Intent _invocationTag;
Intent? get invocationIntent => _invocationTag;
Intent? _invocationTag;
@protected
set invocationIntent(Intent value) => _invocationTag = value;
set invocationIntent(Intent? value) => _invocationTag = value;
@override
@mustCallSuper
......@@ -244,8 +260,8 @@ class UndoableFocusActionBase<T extends Intent> extends UndoableAction<T> {
@mustCallSuper
Memento invoke(T intent) {
super.invoke(intent);
final FocusNode previousFocus = primaryFocus;
return Memento(name: previousFocus.debugLabel, undo: () {
final FocusNode? previousFocus = primaryFocus;
return Memento(name: previousFocus!.debugLabel!, undo: () {
previousFocus.requestFocus();
}, redo: () {
return invoke(intent);
......@@ -267,7 +283,7 @@ class UndoableNextFocusAction extends UndoableFocusActionBase<NextFocusIntent> {
@override
Memento invoke(NextFocusIntent intent) {
final Memento memento = super.invoke(intent);
primaryFocus.nextFocus();
primaryFocus?.nextFocus();
return memento;
}
}
......@@ -276,25 +292,25 @@ class UndoablePreviousFocusAction extends UndoableFocusActionBase<PreviousFocusI
@override
Memento invoke(PreviousFocusIntent intent) {
final Memento memento = super.invoke(intent);
primaryFocus.previousFocus();
primaryFocus?.previousFocus();
return memento;
}
}
class UndoableDirectionalFocusAction extends UndoableFocusActionBase<DirectionalFocusIntent> {
TraversalDirection direction;
TraversalDirection? direction;
@override
Memento invoke(DirectionalFocusIntent intent) {
final Memento memento = super.invoke(intent);
primaryFocus.focusInDirection(intent.direction);
primaryFocus?.focusInDirection(intent.direction);
return memento;
}
}
/// A button class that takes focus when clicked.
class DemoButton extends StatefulWidget {
const DemoButton({Key key, this.name}) : super(key: key);
const DemoButton({Key? key, required this.name}) : super(key: key);
final String name;
......@@ -303,19 +319,13 @@ class DemoButton extends StatefulWidget {
}
class _DemoButtonState extends State<DemoButton> {
FocusNode _focusNode;
late final FocusNode _focusNode = FocusNode(debugLabel: widget.name);
final GlobalKey _nameKey = GlobalKey();
@override
void initState() {
super.initState();
_focusNode = FocusNode(debugLabel: widget.name);
}
void _handleOnPressed() {
print('Button ${widget.name} pressed.');
setState(() {
Actions.invoke(_nameKey.currentContext, RequestFocusIntent(_focusNode));
Actions.invoke(_nameKey.currentContext!, RequestFocusIntent(_focusNode));
});
}
......@@ -336,7 +346,7 @@ class _DemoButtonState extends State<DemoButton> {
return Colors.red;
if (states.contains(MaterialState.hovered))
return Colors.blue;
return null;
return Colors.transparent;
}),
),
onPressed: () => _handleOnPressed(),
......@@ -346,7 +356,7 @@ class _DemoButtonState extends State<DemoButton> {
}
class FocusDemo extends StatefulWidget {
const FocusDemo({Key key}) : super(key: key);
const FocusDemo({Key? key}) : super(key: key);
static GlobalKey appKey = GlobalKey();
......@@ -355,16 +365,14 @@ class FocusDemo extends StatefulWidget {
}
class _FocusDemoState extends State<FocusDemo> {
FocusNode outlineFocus;
UndoableActionDispatcher dispatcher;
bool canUndo;
bool canRedo;
final FocusNode outlineFocus = FocusNode(debugLabel: 'Demo Focus Node');
late final UndoableActionDispatcher dispatcher = UndoableActionDispatcher();
bool canUndo = false;
bool canRedo = false;
@override
void initState() {
super.initState();
outlineFocus = FocusNode(debugLabel: 'Demo Focus Node');
dispatcher = UndoableActionDispatcher();
canUndo = dispatcher.canUndo;
canRedo = dispatcher.canRedo;
dispatcher.addListener(_handleUndoStateChange);
......@@ -415,7 +423,7 @@ class _FocusDemoState extends State<FocusDemo> {
debugLabel: 'Scope',
autofocus: true,
child: DefaultTextStyle(
style: textTheme.headline4,
style: textTheme.headline4!,
child: Scaffold(
appBar: AppBar(
title: const Text('Actions Demo'),
......
......@@ -5,7 +5,7 @@
import 'package:flutter/material.dart';
class AnimatedIconsTestApp extends StatelessWidget {
const AnimatedIconsTestApp({Key key}) : super(key: key);
const AnimatedIconsTestApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
......@@ -19,7 +19,7 @@ class AnimatedIconsTestApp extends StatelessWidget {
}
class IconsList extends StatelessWidget {
const IconsList({Key key}) : super(key: key);
const IconsList({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
......@@ -30,7 +30,7 @@ class IconsList extends StatelessWidget {
}
class IconSampleRow extends StatefulWidget {
const IconSampleRow(this.sample, {Key key}) : super(key: key);
const IconSampleRow(this.sample, {Key? key}) : super(key: key);
final IconSample sample;
......@@ -39,7 +39,7 @@ class IconSampleRow extends StatefulWidget {
}
class IconSampleRowState extends State<IconSampleRow> with SingleTickerProviderStateMixin {
AnimationController progress;
late final AnimationController progress = AnimationController(vsync: this, duration: const Duration(milliseconds: 300));
@override
Widget build(BuildContext context) {
......@@ -63,7 +63,6 @@ class IconSampleRowState extends State<IconSampleRow> with SingleTickerProviderS
@override
void initState() {
super.initState();
progress = AnimationController(vsync: this, duration: const Duration(milliseconds: 300));
progress.addListener(_handleChange);
}
......
......@@ -7,18 +7,18 @@ import 'dart:math';
import 'package:flutter/material.dart';
class CardModel {
CardModel(this.value, this.height) {
CardModel(this.value, this.height) :
textController = TextEditingController(text: 'Item $value');
}
int value;
double height;
int get color => ((value % 9) + 1) * 100;
TextEditingController textController;
final TextEditingController textController;
Key get key => ObjectKey(this);
}
class CardCollection extends StatefulWidget {
const CardCollection({Key key}) : super(key: key);
const CardCollection({Key? key}) : super(key: key);
@override
CardCollectionState createState() => CardCollectionState();
......@@ -41,7 +41,7 @@ class CardCollectionState extends State<CardCollection> {
];
MaterialColor _primaryColor = Colors.deepPurple;
List<CardModel> _cardModels;
List<CardModel> _cardModels = <CardModel>[];
DismissDirection _dismissDirection = DismissDirection.horizontal;
TextAlign _textAlign = TextAlign.center;
bool _editable = false;
......@@ -164,21 +164,21 @@ class CardCollectionState extends State<CardCollection> {
});
}
void _selectColor(MaterialColor selection) {
void _selectColor(MaterialColor? selection) {
setState(() {
_primaryColor = selection;
_primaryColor = selection!;
});
}
void _changeDismissDirection(DismissDirection newDismissDirection) {
void _changeDismissDirection(DismissDirection? newDismissDirection) {
setState(() {
_dismissDirection = newDismissDirection;
_dismissDirection = newDismissDirection!;
});
}
void _changeTextAlign(TextAlign newTextAlign) {
void _changeTextAlign(TextAlign? newTextAlign) {
setState(() {
_textAlign = newTextAlign;
_textAlign = newTextAlign!;
});
}
......@@ -193,7 +193,7 @@ class CardCollectionState extends State<CardCollection> {
);
}
Widget buildDrawerColorRadioItem(String label, MaterialColor itemValue, MaterialColor currentValue, ValueChanged<MaterialColor> onChanged, { IconData icon, bool enabled = true }) {
Widget buildDrawerColorRadioItem(String label, MaterialColor itemValue, MaterialColor currentValue, ValueChanged<MaterialColor?> onChanged, { IconData? icon, bool enabled = true }) {
return ListTile(
leading: Icon(icon),
title: Text(label),
......@@ -206,7 +206,7 @@ class CardCollectionState extends State<CardCollection> {
);
}
Widget buildDrawerDirectionRadioItem(String label, DismissDirection itemValue, DismissDirection currentValue, ValueChanged<DismissDirection> onChanged, { IconData icon, bool enabled = true }) {
Widget buildDrawerDirectionRadioItem(String label, DismissDirection itemValue, DismissDirection currentValue, ValueChanged<DismissDirection?> onChanged, { IconData? icon, bool enabled = true }) {
return ListTile(
leading: Icon(icon),
title: Text(label),
......@@ -219,7 +219,7 @@ class CardCollectionState extends State<CardCollection> {
);
}
Widget buildFontRadioItem(String label, TextAlign itemValue, TextAlign currentValue, ValueChanged<TextAlign> onChanged, { IconData icon, bool enabled = true }) {
Widget buildFontRadioItem(String label, TextAlign itemValue, TextAlign currentValue, ValueChanged<TextAlign?> onChanged, { IconData? icon, bool enabled = true }) {
return ListTile(
leading: Icon(icon),
title: Text(label),
......@@ -306,7 +306,7 @@ class CardCollectionState extends State<CardCollection> {
rightArrowIcon = Opacity(opacity: 0.1, child: rightArrowIcon);
final ThemeData theme = Theme.of(context);
final TextStyle backgroundTextStyle = theme.primaryTextTheme.headline6;
final TextStyle? backgroundTextStyle = theme.primaryTextTheme.headline6;
// The background Widget appears behind the Dismissible card when the card
// moves to the left or right. The Positioned widget ensures that the
......
......@@ -5,7 +5,7 @@
import 'package:flutter/material.dart';
class ColorTestingDemo extends StatelessWidget {
const ColorTestingDemo({ Key key }) : super(key: key);
const ColorTestingDemo({ Key? key }) : super(key: key);
static const String routeName = '/color_demo';
......@@ -14,7 +14,7 @@ class ColorTestingDemo extends StatelessWidget {
}
class ColorDemoHome extends StatelessWidget {
const ColorDemoHome({Key key}) : super(key: key);
const ColorDemoHome({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
......@@ -52,7 +52,7 @@ class ColorDemoHome extends StatelessWidget {
}
class GradientRow extends StatelessWidget {
const GradientRow({ Key key, this.rightColor, this.leftColor }) : super(key: key);
const GradientRow({ Key? key, required this.rightColor, required this.leftColor }) : super(key: key);
final Color leftColor;
final Color rightColor;
......@@ -73,7 +73,7 @@ class GradientRow extends StatelessWidget {
}
class ColorRow extends StatelessWidget {
const ColorRow({ Key key, this.color }) : super(key: key);
const ColorRow({ Key? key, required this.color }) : super(key: key);
final Color color;
......
......@@ -17,12 +17,12 @@ final Map<int, Color> m2SwatchColors = <int, Color>{
800: const Color(0xff270096),
900: const Color(0xff270096),
};
final MaterialColor m2Swatch = MaterialColor(m2SwatchColors[500].value, m2SwatchColors);
final MaterialColor m2Swatch = MaterialColor(m2SwatchColors[500]!.value, m2SwatchColors);
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key);
const MyApp({Key? key}) : super(key: key);
static const String _title = 'Density Test';
......@@ -36,7 +36,7 @@ class MyApp extends StatelessWidget {
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key key, this.title}) : super(key: key);
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
......@@ -112,11 +112,11 @@ class OptionModel extends ChangeNotifier {
}
class LabeledCheckbox extends StatelessWidget {
const LabeledCheckbox({Key key, this.label, this.onChanged, this.value}) : super(key: key);
const LabeledCheckbox({Key? key, required this.label, this.onChanged, this.value}) : super(key: key);
final String label;
final ValueChanged<bool> onChanged;
final bool value;
final ValueChanged<bool?>? onChanged;
final bool? value;
@override
Widget build(BuildContext context) {
......@@ -134,7 +134,7 @@ class LabeledCheckbox extends StatelessWidget {
}
class Options extends StatefulWidget {
const Options(this.model, {Key key}) : super(key: key);
const Options(this.model, {Key? key}) : super(key: key);
final OptionModel model;
......@@ -181,7 +181,7 @@ class _OptionsState extends State<Options> {
return 'custom';
}
VisualDensity _profileToDensity(String profile) {
VisualDensity _profileToDensity(String? profile) {
switch (profile) {
case 'standard':
return VisualDensity.standard;
......@@ -304,7 +304,7 @@ class _OptionsState extends State<Options> {
child: DropdownButton<String>(
style: TextStyle(color: Colors.grey[50]),
isDense: true,
onChanged: (String value) {
onChanged: (String? value) {
widget.model.density = _profileToDensity(value);
},
items: const <DropdownMenuItem<String>>[
......@@ -321,15 +321,15 @@ class _OptionsState extends State<Options> {
),
LabeledCheckbox(
label: 'Enabled',
onChanged: (bool checked) {
widget.model.enable = checked;
onChanged: (bool? checked) {
widget.model.enable = checked == true;
},
value: widget.model.enable,
),
LabeledCheckbox(
label: 'Slow',
onChanged: (bool checked) {
widget.model.slowAnimations = checked;
onChanged: (bool? checked) {
widget.model.slowAnimations = checked == true;
Future<void>.delayed(const Duration(milliseconds: 150)).then((_) {
if (widget.model.slowAnimations) {
timeDilation = 20.0;
......@@ -342,8 +342,8 @@ class _OptionsState extends State<Options> {
),
LabeledCheckbox(
label: 'RTL',
onChanged: (bool checked) {
widget.model.rtl = checked;
onChanged: (bool? checked) {
widget.model.rtl = checked == true;
},
value: widget.model.rtl,
),
......@@ -365,7 +365,7 @@ class _OptionsState extends State<Options> {
}
class _ControlTile extends StatelessWidget {
const _ControlTile({Key key, @required this.label, @required this.child})
const _ControlTile({Key? key, required this.label, required this.child})
: assert(label != null),
assert(child != null),
super(key: key);
......@@ -398,13 +398,12 @@ class _ControlTile extends StatelessWidget {
class _MyHomePageState extends State<MyHomePage> {
static final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
final OptionModel _model = OptionModel();
TextEditingController textController;
final TextEditingController textController = TextEditingController();
@override
void initState() {
super.initState();
_model.addListener(_modelChanged);
textController = TextEditingController();
}
@override
......@@ -565,9 +564,9 @@ class _MyHomePageState extends State<MyHomePage> {
children: List<Widget>.generate(checkboxValues.length, (int index) {
return Checkbox(
onChanged: _model.enable
? (bool value) {
? (bool? value) {
setState(() {
checkboxValues[index] = value;
checkboxValues[index] = value == true;
});
}
: null,
......@@ -583,9 +582,9 @@ class _MyHomePageState extends State<MyHomePage> {
children: List<Widget>.generate(4, (int index) {
return Radio<int>(
onChanged: _model.enable
? (int value) {
? (int? value) {
setState(() {
radioValue = value;
radioValue = value!;
});
}
: null,
......
......@@ -7,7 +7,7 @@ import 'dart:math' as math;
import 'package:flutter/material.dart';
class ExampleDragTarget extends StatefulWidget {
const ExampleDragTarget({Key key}) : super(key: key);
const ExampleDragTarget({Key? key}) : super(key: key);
@override
ExampleDragTargetState createState() => ExampleDragTargetState();
......@@ -26,7 +26,7 @@ class ExampleDragTargetState extends State<ExampleDragTarget> {
Widget build(BuildContext context) {
return DragTarget<Color>(
onAccept: _handleAccept,
builder: (BuildContext context, List<Color> data, List<dynamic> rejectedData) {
builder: (BuildContext context, List<Color?> data, List<dynamic> rejectedData) {
return Container(
height: 100.0,
margin: const EdgeInsets.all(10.0),
......@@ -44,11 +44,11 @@ class ExampleDragTargetState extends State<ExampleDragTarget> {
}
class Dot extends StatefulWidget {
const Dot({ Key key, this.color, this.size, this.child, this.tappable = false }) : super(key: key);
const Dot({ Key? key, this.color, this.size, this.child, this.tappable = false }) : super(key: key);
final Color color;
final double size;
final Widget child;
final Color? color;
final double? size;
final Widget? child;
final bool tappable;
@override
......@@ -77,17 +77,17 @@ class DotState extends State<Dot> {
class ExampleDragSource extends StatelessWidget {
const ExampleDragSource({
Key key,
Key? key,
this.color,
this.heavy = false,
this.under = true,
this.child,
}) : super(key: key);
final Color color;
final Color? color;
final bool heavy;
final bool under;
final Widget child;
final Widget? child;
static const double kDotSize = 50.0;
static const double kHeavyMultiplier = 1.5;
......@@ -100,7 +100,7 @@ class ExampleDragSource extends StatelessWidget {
size *= kHeavyMultiplier;
final Widget contents = DefaultTextStyle(
style: Theme.of(context).textTheme.bodyText2,
style: Theme.of(context).textTheme.bodyText2!,
textAlign: TextAlign.center,
child: Dot(
color: color,
......@@ -176,7 +176,7 @@ class DashOutlineCirclePainter extends CustomPainter {
}
class MovableBall extends StatelessWidget {
const MovableBall(this.position, this.ballPosition, this.callback, {Key key}) : super(key: key);
const MovableBall(this.position, this.ballPosition, this.callback, {Key? key}) : super(key: key);
final int position;
final int ballPosition;
......@@ -188,7 +188,7 @@ class MovableBall extends StatelessWidget {
@override
Widget build(BuildContext context) {
final Widget ball = DefaultTextStyle(
style: Theme.of(context).primaryTextTheme.bodyText2,
style: Theme.of(context).primaryTextTheme.bodyText2!,
textAlign: TextAlign.center,
child: Dot(
key: kBallKey,
......@@ -216,7 +216,7 @@ class MovableBall extends StatelessWidget {
} else {
return DragTarget<bool>(
onAccept: (bool data) { callback(position); },
builder: (BuildContext context, List<bool> accepted, List<dynamic> rejected) {
builder: (BuildContext context, List<bool?> accepted, List<dynamic> rejected) {
return dashedBall;
},
);
......@@ -225,7 +225,7 @@ class MovableBall extends StatelessWidget {
}
class DragAndDropApp extends StatefulWidget {
const DragAndDropApp({Key key}) : super(key: key);
const DragAndDropApp({Key? key}) : super(key: key);
@override
DragAndDropAppState createState() => DragAndDropAppState();
......
......@@ -13,7 +13,7 @@ void main() {
}
class DemoButton extends StatefulWidget {
const DemoButton({Key key, this.name, this.canRequestFocus = true, this.autofocus = false}) : super(key: key);
const DemoButton({Key? key, required this.name, this.canRequestFocus = true, this.autofocus = false}) : super(key: key);
final String name;
final bool canRequestFocus;
......@@ -24,20 +24,14 @@ class DemoButton extends StatefulWidget {
}
class _DemoButtonState extends State<DemoButton> {
FocusNode focusNode;
@override
void initState() {
super.initState();
focusNode = FocusNode(
late final FocusNode focusNode = FocusNode(
debugLabel: widget.name,
canRequestFocus: widget.canRequestFocus,
);
}
);
@override
void dispose() {
focusNode?.dispose();
focusNode.dispose();
super.dispose();
}
......@@ -64,7 +58,7 @@ class _DemoButtonState extends State<DemoButton> {
return Colors.red.withOpacity(0.25);
if (states.contains(MaterialState.hovered))
return Colors.blue.withOpacity(0.25);
return null;
return Colors.transparent;
}),
),
onPressed: () => _handleOnPressed(),
......@@ -74,14 +68,14 @@ class _DemoButtonState extends State<DemoButton> {
}
class FocusDemo extends StatefulWidget {
const FocusDemo({Key key}) : super(key: key);
const FocusDemo({Key? key}) : super(key: key);
@override
State<FocusDemo> createState() => _FocusDemoState();
}
class _FocusDemoState extends State<FocusDemo> {
FocusNode outlineFocus;
FocusNode? outlineFocus;
@override
void initState() {
......@@ -91,7 +85,7 @@ class _FocusDemoState extends State<FocusDemo> {
@override
void dispose() {
outlineFocus.dispose();
outlineFocus?.dispose();
super.dispose();
}
......@@ -142,7 +136,7 @@ class _FocusDemoState extends State<FocusDemo> {
onKey: _handleKeyPress,
autofocus: true,
child: DefaultTextStyle(
style: textTheme.headline4,
style: textTheme.headline4!,
child: Scaffold(
appBar: AppBar(
title: const Text('Focus Demo'),
......
......@@ -12,7 +12,7 @@ void main() {
}
class DemoButton extends StatelessWidget {
const DemoButton({Key key, this.name}) : super(key: key);
const DemoButton({Key? key, required this.name}) : super(key: key);
final String name;
......@@ -30,7 +30,7 @@ class DemoButton extends StatelessWidget {
}
class HoverDemo extends StatefulWidget {
const HoverDemo({Key key}) : super(key: key);
const HoverDemo({Key? key}) : super(key: key);
@override
State<HoverDemo> createState() => _HoverDemoState();
......@@ -42,12 +42,12 @@ class _HoverDemoState extends State<HoverDemo> {
final TextTheme textTheme = Theme.of(context).textTheme;
final ButtonStyle overrideFocusColor = ButtonStyle(
overlayColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
return states.contains(MaterialState.focused) ? Colors.deepOrangeAccent : null;
return states.contains(MaterialState.focused) ? Colors.deepOrangeAccent : Colors.transparent;
})
);
return DefaultTextStyle(
style: textTheme.headline4,
style: textTheme.headline4!,
child: Scaffold(
appBar: AppBar(
title: const Text('Hover Demo'),
......
......@@ -45,12 +45,12 @@ class _IgnoreDrag extends Drag {
class _PointDemoPainter extends CustomPainter {
_PointDemoPainter({
Animation<double> repaint,
this.arc,
Animation<double>? repaint,
required this.arc,
}) : _repaint = repaint, super(repaint: repaint);
final MaterialPointArcTween arc;
final Animation<double> _repaint;
final Animation<double>? _repaint;
void drawPoint(Canvas canvas, Offset point, Color color) {
final Paint paint = Paint()
......@@ -69,7 +69,7 @@ class _PointDemoPainter extends CustomPainter {
final Paint paint = Paint();
if (arc.center != null)
drawPoint(canvas, arc.center, Colors.grey.shade400);
drawPoint(canvas, arc.center!, Colors.grey.shade400);
paint
..isAntiAlias = false // Work-around for github.com/flutter/flutter/issues/5720
......@@ -77,23 +77,23 @@ class _PointDemoPainter extends CustomPainter {
..strokeWidth = 4.0
..style = PaintingStyle.stroke;
if (arc.center != null && arc.radius != null)
canvas.drawCircle(arc.center, arc.radius, paint);
canvas.drawCircle(arc.center!, arc.radius!, paint);
else
canvas.drawLine(arc.begin, arc.end, paint);
canvas.drawLine(arc.begin!, arc.end!, paint);
drawPoint(canvas, arc.begin, Colors.green);
drawPoint(canvas, arc.end, Colors.red);
drawPoint(canvas, arc.begin!, Colors.green);
drawPoint(canvas, arc.end!, Colors.red);
paint
..color = Colors.green
..style = PaintingStyle.fill;
canvas.drawCircle(arc.lerp(_repaint.value), _kPointRadius, paint);
canvas.drawCircle(arc.lerp(_repaint!.value), _kPointRadius, paint);
}
@override
bool hitTest(Offset position) {
return (arc.begin - position).distanceSquared < _kTargetSlop
|| (arc.end - position).distanceSquared < _kTargetSlop;
return (arc.begin! - position).distanceSquared < _kTargetSlop
|| (arc.end! - position).distanceSquared < _kTargetSlop;
}
@override
......@@ -101,7 +101,7 @@ class _PointDemoPainter extends CustomPainter {
}
class _PointDemo extends StatefulWidget {
const _PointDemo({ Key key, this.controller }) : super(key: key);
const _PointDemo({ Key? key, required this.controller }) : super(key: key);
final AnimationController controller;
......@@ -112,11 +112,11 @@ class _PointDemo extends StatefulWidget {
class _PointDemoState extends State<_PointDemo> {
final GlobalKey _painterKey = GlobalKey();
CurvedAnimation _animation;
_DragTarget _dragTarget;
Size _screenSize;
Offset _begin;
Offset _end;
CurvedAnimation? _animation;
_DragTarget? _dragTarget;
Size? _screenSize;
Offset? _begin;
Offset? _end;
@override
void initState() {
......@@ -135,9 +135,9 @@ class _PointDemoState extends State<_PointDemo> {
if (_dragTarget != null)
return _IgnoreDrag();
final RenderBox box = _painterKey.currentContext.findRenderObject() as RenderBox;
final double startOffset = (box.localToGlobal(_begin) - position).distanceSquared;
final double endOffset = (box.localToGlobal(_end) - position).distanceSquared;
final RenderBox? box = _painterKey.currentContext!.findRenderObject() as RenderBox?;
final double startOffset = (box!.localToGlobal(_begin!) - position).distanceSquared;
final double endOffset = (box.localToGlobal(_end!) - position).distanceSquared;
setState(() {
if (startOffset < endOffset && startOffset < _kTargetSlop)
_dragTarget = _DragTarget.start;
......@@ -151,15 +151,15 @@ class _PointDemoState extends State<_PointDemo> {
}
void _handleDragUpdate(DragUpdateDetails details) {
switch (_dragTarget) {
switch (_dragTarget!) {
case _DragTarget.start:
setState(() {
_begin = _begin + details.delta;
_begin = _begin! + details.delta;
});
break;
case _DragTarget.end:
setState(() {
_end = _end + details.delta;
_end = _end! + details.delta;
});
break;
}
......@@ -210,7 +210,7 @@ class _PointDemoState extends State<_PointDemo> {
child: Text(
'Tap the refresh button to run the animation. Drag the green '
"and red points to change the animation's path.",
style: Theme.of(context).textTheme.caption.copyWith(fontSize: 16.0),
style: Theme.of(context).textTheme.caption?.copyWith(fontSize: 16.0),
),
),
),
......@@ -222,8 +222,8 @@ class _PointDemoState extends State<_PointDemo> {
class _RectangleDemoPainter extends CustomPainter {
_RectangleDemoPainter({
Animation<double> repaint,
this.arc,
required Animation<double> repaint,
required this.arc,
}) : _repaint = repaint, super(repaint: repaint);
final MaterialRectArcTween arc;
......@@ -252,15 +252,15 @@ class _RectangleDemoPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
drawRect(canvas, arc.begin, Colors.green);
drawRect(canvas, arc.end, Colors.red);
drawRect(canvas, arc.begin!, Colors.green);
drawRect(canvas, arc.end!, Colors.red);
drawRect(canvas, arc.lerp(_repaint.value), Colors.blue);
}
@override
bool hitTest(Offset position) {
return (arc.begin.center - position).distanceSquared < _kTargetSlop
|| (arc.end.center - position).distanceSquared < _kTargetSlop;
return (arc.begin!.center - position).distanceSquared < _kTargetSlop
|| (arc.end!.center - position).distanceSquared < _kTargetSlop;
}
@override
......@@ -268,7 +268,7 @@ class _RectangleDemoPainter extends CustomPainter {
}
class _RectangleDemo extends StatefulWidget {
const _RectangleDemo({ Key key, this.controller }) : super(key: key);
const _RectangleDemo({ Key? key, required this.controller }) : super(key: key);
final AnimationController controller;
......@@ -279,17 +279,11 @@ class _RectangleDemo extends StatefulWidget {
class _RectangleDemoState extends State<_RectangleDemo> {
final GlobalKey _painterKey = GlobalKey();
CurvedAnimation _animation;
_DragTarget _dragTarget;
Size _screenSize;
Rect _begin;
Rect _end;
@override
void initState() {
super.initState();
_animation = CurvedAnimation(parent: widget.controller, curve: Curves.fastOutSlowIn);
}
late final CurvedAnimation _animation = CurvedAnimation(parent: widget.controller, curve: Curves.fastOutSlowIn);
_DragTarget? _dragTarget;
Size? _screenSize;
Rect? _begin;
Rect? _end;
@override
void dispose() {
......@@ -302,9 +296,9 @@ class _RectangleDemoState extends State<_RectangleDemo> {
if (_dragTarget != null)
return _IgnoreDrag();
final RenderBox box = _painterKey.currentContext.findRenderObject() as RenderBox;
final double startOffset = (box.localToGlobal(_begin.center) - position).distanceSquared;
final double endOffset = (box.localToGlobal(_end.center) - position).distanceSquared;
final RenderBox? box = _painterKey.currentContext?.findRenderObject() as RenderBox?;
final double startOffset = (box!.localToGlobal(_begin!.center) - position).distanceSquared;
final double endOffset = (box.localToGlobal(_end!.center) - position).distanceSquared;
setState(() {
if (startOffset < endOffset && startOffset < _kTargetSlop)
_dragTarget = _DragTarget.start;
......@@ -317,15 +311,15 @@ class _RectangleDemoState extends State<_RectangleDemo> {
}
void _handleDragUpdate(DragUpdateDetails details) {
switch (_dragTarget) {
switch (_dragTarget!) {
case _DragTarget.start:
setState(() {
_begin = _begin.shift(details.delta);
_begin = _begin?.shift(details.delta);
});
break;
case _DragTarget.end:
setState(() {
_end = _end.shift(details.delta);
_end = _end?.shift(details.delta);
});
break;
}
......@@ -382,7 +376,7 @@ class _RectangleDemoState extends State<_RectangleDemo> {
child: Text(
'Tap the refresh button to run the animation. Drag the rectangles '
"to change the animation's path.",
style: Theme.of(context).textTheme.caption.copyWith(fontSize: 16.0),
style: Theme.of(context).textTheme.caption!.copyWith(fontSize: 16.0),
),
),
),
......@@ -406,37 +400,31 @@ class _ArcDemo {
}
class AnimationDemo extends StatefulWidget {
const AnimationDemo({ Key key }) : super(key: key);
const AnimationDemo({ Key? key }) : super(key: key);
@override
State<AnimationDemo> createState() => _AnimationDemoState();
}
class _AnimationDemoState extends State<AnimationDemo> with TickerProviderStateMixin {
List<_ArcDemo> _allDemos;
@override
void initState() {
super.initState();
_allDemos = <_ArcDemo>[
_ArcDemo('POINT', (_ArcDemo demo) {
return _PointDemo(
key: demo.key,
controller: demo.controller,
);
}, this),
_ArcDemo('RECTANGLE', (_ArcDemo demo) {
return _RectangleDemo(
key: demo.key,
controller: demo.controller,
);
}, this),
];
}
late final List<_ArcDemo> _allDemos = <_ArcDemo>[
_ArcDemo('POINT', (_ArcDemo demo) {
return _PointDemo(
key: demo.key,
controller: demo.controller,
);
}, this),
_ArcDemo('RECTANGLE', (_ArcDemo demo) {
return _RectangleDemo(
key: demo.key,
controller: demo.controller,
);
}, this),
];
Future<void> _play(_ArcDemo demo) async {
await demo.controller.forward();
if (demo.key.currentState != null && demo.key.currentState.mounted)
if (demo.key.currentState != null && demo.key.currentState!.mounted)
demo.controller.reverse();
}
......@@ -456,7 +444,7 @@ class _AnimationDemoState extends State<AnimationDemo> with TickerProviderStateM
return FloatingActionButton(
child: const Icon(Icons.refresh),
onPressed: () {
_play(_allDemos[DefaultTabController.of(context).index]);
_play(_allDemos[DefaultTabController.of(context)!.index]);
},
);
},
......
......@@ -20,8 +20,8 @@ enum MarkerType { topLeft, bottomRight, touch }
class _MarkerPainter extends CustomPainter {
const _MarkerPainter({
this.size,
this.type,
required this.size,
required this.type,
});
final double size;
......@@ -56,21 +56,21 @@ class _MarkerPainter extends CustomPainter {
class Marker extends StatelessWidget {
const Marker({
Key key,
Key? key,
this.type = MarkerType.touch,
this.position,
this.size = 40.0,
}) : super(key: key);
final Offset position;
final Offset? position;
final double size;
final MarkerType type;
@override
Widget build(BuildContext context) {
return Positioned(
left: position.dx - size / 2.0,
top: position.dy - size / 2.0,
left: position!.dx - size / 2.0,
top: position!.dy - size / 2.0,
width: size,
height: size,
child: IgnorePointer(
......@@ -86,7 +86,7 @@ class Marker extends StatelessWidget {
}
class OverlayGeometryApp extends StatefulWidget {
const OverlayGeometryApp({Key key}) : super(key: key);
const OverlayGeometryApp({Key? key}) : super(key: key);
@override
OverlayGeometryAppState createState() => OverlayGeometryAppState();
......@@ -95,22 +95,22 @@ class OverlayGeometryApp extends StatefulWidget {
typedef CardTapCallback = void Function(GlobalKey targetKey, Offset globalPosition);
class CardBuilder extends SliverChildDelegate {
CardBuilder({ this.cardModels, this.onTapUp });
CardBuilder({List<CardModel>? cardModels, this.onTapUp }) : cardModels = cardModels ?? <CardModel>[];
final List<CardModel> cardModels;
final CardTapCallback onTapUp;
final CardTapCallback? onTapUp;
static const TextStyle cardLabelStyle =
TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold);
@override
Widget build(BuildContext context, int index) {
Widget? build(BuildContext context, int index) {
if (index >= cardModels.length)
return null;
final CardModel cardModel = cardModels[index];
return GestureDetector(
key: cardModel.key,
onTapUp: (TapUpDetails details) { onTapUp(cardModel.targetKey, details.globalPosition); },
onTapUp: (TapUpDetails details) { onTapUp!(cardModel.targetKey, details.globalPosition); },
child: Card(
key: cardModel.targetKey,
color: cardModel.color,
......@@ -133,7 +133,7 @@ class CardBuilder extends SliverChildDelegate {
}
class OverlayGeometryAppState extends State<OverlayGeometryApp> {
List<CardModel> cardModels;
List<CardModel> cardModels = <CardModel>[];
Map<MarkerType, Offset> markers = <MarkerType, Offset>{};
double markersScrollOffset = 0.0;
......@@ -146,8 +146,8 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
48.0, 63.0, 82.0, 146.0, 60.0, 55.0, 84.0, 96.0, 50.0,
];
cardModels = List<CardModel>.generate(cardHeights.length, (int i) {
final Color color = Color.lerp(Colors.red.shade300, Colors.blue.shade900, i / cardHeights.length);
return CardModel(i, cardHeights[i], color);
final Color? color = Color.lerp(Colors.red.shade300, Colors.blue.shade900, i / cardHeights.length);
return CardModel(i, cardHeights[i], color!);
});
}
......@@ -156,10 +156,9 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
setState(() {
final double dy = markersScrollOffset - notification.metrics.extentBefore;
markersScrollOffset = notification.metrics.extentBefore;
for (final MarkerType type in markers.keys) {
final Offset oldPosition = markers[type];
markers.forEach((MarkerType type, Offset oldPosition) {
markers[type] = oldPosition.translate(0.0, dy);
}
});
});
}
return false;
......@@ -168,12 +167,12 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
void handleTapUp(GlobalKey target, Offset globalPosition) {
setState(() {
markers[MarkerType.touch] = globalPosition;
final RenderBox box = target.currentContext.findRenderObject() as RenderBox;
markers[MarkerType.topLeft] = box.localToGlobal(Offset.zero);
final RenderBox? box = target.currentContext?.findRenderObject() as RenderBox?;
markers[MarkerType.topLeft] = box!.localToGlobal(Offset.zero);
final Size size = box.size;
markers[MarkerType.bottomRight] = box.localToGlobal(Offset(size.width, size.height));
final ScrollableState scrollable = Scrollable.of(target.currentContext);
markersScrollOffset = scrollable.position.pixels;
final ScrollableState? scrollable = Scrollable.of(target.currentContext!);
markersScrollOffset = scrollable!.position.pixels;
});
}
......
......@@ -14,7 +14,7 @@ class CardModel {
}
class PageViewApp extends StatefulWidget {
const PageViewApp({Key key}) : super(key: key);
const PageViewApp({Key? key}) : super(key: key);
@override
PageViewAppState createState() => PageViewAppState();
......@@ -33,15 +33,15 @@ class PageViewAppState extends State<PageViewApp> {
];
cardModels = List<CardModel>.generate(cardSizes.length, (int i) {
final Color color = Color.lerp(Colors.red.shade300, Colors.blue.shade900, i / cardSizes.length);
return CardModel(i, cardSizes[i], color);
final Color? color = Color.lerp(Colors.red.shade300, Colors.blue.shade900, i / cardSizes.length);
return CardModel(i, cardSizes[i], color!);
});
}
static const TextStyle cardLabelStyle =
TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold);
List<CardModel> cardModels;
List<CardModel> cardModels = <CardModel>[];
Size pageSize = const Size(200.0, 200.0);
Axis scrollDirection = Axis.horizontal;
bool itemsWrap = false;
......
......@@ -20,7 +20,7 @@ void main() {
}
class RawKeyboardDemo extends StatefulWidget {
const RawKeyboardDemo({Key key}) : super(key: key);
const RawKeyboardDemo({Key? key}) : super(key: key);
@override
State<RawKeyboardDemo> createState() => _HardwareKeyDemoState();
......@@ -28,7 +28,7 @@ class RawKeyboardDemo extends StatefulWidget {
class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
final FocusNode _focusNode = FocusNode();
RawKeyEvent _event;
RawKeyEvent? _event;
@override
void dispose() {
......@@ -60,7 +60,7 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
autofocus: true,
child: AnimatedBuilder(
animation: _focusNode,
builder: (BuildContext context, Widget child) {
builder: (BuildContext context, Widget? child) {
if (!_focusNode.hasFocus) {
return GestureDetector(
onTap: () {
......@@ -74,11 +74,11 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
return Text('Press a key', style: textTheme.headline4);
}
final RawKeyEventData data = _event.data;
final String modifierList = data.modifiersPressed.keys.map<String>(_getEnumName).join(', ').replaceAll('Modifier', '');
final RawKeyEventData? data = _event?.data;
final String? modifierList = data?.modifiersPressed.keys.map<String>(_getEnumName).join(', ').replaceAll('Modifier', '');
final List<Widget> dataText = <Widget>[
Text('${_event.runtimeType}'),
if (_event.character?.isNotEmpty ?? false) Text('character produced: "${_event.character}"'),
if (_event?.character?.isNotEmpty ?? false) Text('character produced: "${_event?.character}"'),
Text('modifiers set: $modifierList'),
];
if (data is RawKeyEventDataAndroid) {
......@@ -119,12 +119,12 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
dataText.add(Text('code: ${data.code}'));
dataText.add(Text('metaState: ${data.metaState} (${_asHex(data.metaState)})'));
}
dataText.add(Text('logical: ${_event.logicalKey}'));
dataText.add(Text('physical: ${_event.physicalKey}'));
if (_event.character != null) {
dataText.add(Text('character: ${_event.character}'));
dataText.add(Text('logical: ${_event?.logicalKey}'));
dataText.add(Text('physical: ${_event?.physicalKey}'));
if (_event?.character != null) {
dataText.add(Text('character: ${_event?.character}'));
}
for (final ModifierKey modifier in data.modifiersPressed.keys) {
for (final ModifierKey modifier in data!.modifiersPressed.keys) {
for (final KeyboardSide side in KeyboardSide.values) {
if (data.isModifierPressed(modifier, side: side)) {
dataText.add(
......@@ -135,11 +135,11 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
}
final List<String> pressed = <String>['Pressed:'];
for (final LogicalKeyboardKey key in RawKeyboard.instance.keysPressed) {
pressed.add(key.debugName);
pressed.add(key.debugName!);
}
dataText.add(Text(pressed.join(' ')));
return DefaultTextStyle(
style: textTheme.subtitle1,
style: textTheme.subtitle1!,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: dataText,
......
......@@ -26,7 +26,7 @@ void main() {
}
class Home extends StatefulWidget {
const Home({ Key key }) : super(key: key);
const Home({ Key? key }) : super(key: key);
@override
State<Home> createState() => _HomeState();
......@@ -119,7 +119,7 @@ class _HomeState extends State<Home> {
}
class Fuzzer extends StatefulWidget {
const Fuzzer({ Key key, this.seed }) : super(key: key);
const Fuzzer({ Key? key, required this.seed }) : super(key: key);
final int seed;
......@@ -129,14 +129,12 @@ class Fuzzer extends StatefulWidget {
class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
TextSpan _textSpan = const TextSpan(text: 'Welcome to the Flutter text fuzzer.');
Ticker _ticker;
math.Random _random;
late final Ticker _ticker = createTicker(_updateTextSpan)..start();
late final math.Random _random = math.Random(widget.seed); // providing a seed is important for reproducibility;
@override
void initState() {
super.initState();
_random = math.Random(widget.seed); // providing a seed is important for reproducibility
_ticker = createTicker(_updateTextSpan)..start();
_updateTextSpan(null);
}
......@@ -146,7 +144,7 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
super.dispose();
}
void _updateTextSpan(Duration duration) {
void _updateTextSpan(Duration? duration) {
setState(() {
_textSpan = _fiddleWith(_textSpan);
});
......@@ -156,17 +154,17 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
return TextSpan(
text: _fiddleWithText(node.text),
style: _fiddleWithStyle(node.style),
children: _fiddleWithChildren(node.children?.map((InlineSpan child) => _fiddleWith(child as TextSpan))?.toList() ?? <TextSpan>[]),
children: _fiddleWithChildren(node.children?.map((InlineSpan child) => _fiddleWith(child as TextSpan)).toList() ?? <TextSpan>[]),
);
}
String _fiddleWithText(String text) {
String? _fiddleWithText(String? text) {
if (_random.nextInt(10) > 0)
return text;
return _createRandomText();
}
TextStyle _fiddleWithStyle(TextStyle style) {
TextStyle? _fiddleWithStyle(TextStyle? style) {
if (style == null) {
switch (_random.nextInt(20)) {
case 0:
......@@ -196,7 +194,7 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
);
}
Color _fiddleWithColor(Color value) {
Color? _fiddleWithColor(Color? value) {
switch (_random.nextInt(10)) {
case 0:
if (value == null)
......@@ -218,7 +216,7 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
return value;
}
TextDecoration _fiddleWithDecoration(TextDecoration value) {
TextDecoration? _fiddleWithDecoration(TextDecoration? value) {
if (_random.nextInt(10) > 0)
return value;
switch (_random.nextInt(100)) {
......@@ -246,7 +244,7 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
return null;
}
TextDecorationStyle _fiddleWithDecorationStyle(TextDecorationStyle value) {
TextDecorationStyle? _fiddleWithDecorationStyle(TextDecorationStyle? value) {
switch (_random.nextInt(10)) {
case 0:
return null;
......@@ -256,7 +254,7 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
return value;
}
FontWeight _fiddleWithFontWeight(FontWeight value) {
FontWeight? _fiddleWithFontWeight(FontWeight? value) {
switch (_random.nextInt(10)) {
case 0:
return null;
......@@ -266,7 +264,7 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
return value;
}
FontStyle _fiddleWithFontStyle(FontStyle value) {
FontStyle? _fiddleWithFontStyle(FontStyle? value) {
switch (_random.nextInt(10)) {
case 0:
return null;
......@@ -276,7 +274,7 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
return value;
}
String _fiddleWithFontFamily(String value) {
String? _fiddleWithFontFamily(String? value) {
switch (_random.nextInt(10)) {
case 0:
return null;
......@@ -300,7 +298,7 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
return value;
}
double _fiddleWithDouble(double value, double defaultValue, double max) {
double? _fiddleWithDouble(double? value, double defaultValue, double max) {
switch (_random.nextInt(10)) {
case 0:
if (value == null)
......@@ -312,7 +310,7 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
return value;
}
List<TextSpan> _fiddleWithChildren(List<TextSpan> children) {
List<TextSpan>? _fiddleWithChildren(List<TextSpan> children) {
switch (_random.nextInt(100)) {
case 0:
case 1:
......@@ -340,10 +338,10 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
}
int depthOf(TextSpan node) {
if (node.children == null || node.children.isEmpty)
if (node.children == null || node.children?.isEmpty == true)
return 0;
int result = 0;
for (final TextSpan child in node.children.cast<TextSpan>())
for (final TextSpan child in node.children!.cast<TextSpan>())
result = math.max(result, depthOf(child));
return result;
}
......@@ -354,7 +352,7 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
);
}
String _createRandomText() {
String? _createRandomText() {
switch (_random.nextInt(90)) {
case 0:
case 1:
......@@ -536,7 +534,7 @@ class _FuzzerState extends State<Fuzzer> with SingleTickerProviderStateMixin {
}
class Underlines extends StatefulWidget {
const Underlines({ Key key }) : super(key: key);
const Underlines({ Key? key }) : super(key: key);
@override
State<Underlines> createState() => _UnderlinesState();
......@@ -554,7 +552,7 @@ class _UnderlinesState extends State<Underlines> {
decorationColor: Colors.yellow.shade500,
);
Widget _wrap(TextDecorationStyle style) {
Widget _wrap(TextDecorationStyle? style) {
return Align(
alignment: Alignment.centerLeft,
heightFactor: 1.0,
......@@ -641,7 +639,7 @@ class _UnderlinesState extends State<Underlines> {
}
class Fallback extends StatefulWidget {
const Fallback({ Key key }) : super(key: key);
const Fallback({ Key? key }) : super(key: key);
@override
State<Fallback> createState() => _FallbackState();
......@@ -736,7 +734,7 @@ class _FallbackState extends State<Fallback> {
}
class Bidi extends StatefulWidget {
const Bidi({ Key key }) : super(key: key);
const Bidi({ Key? key }) : super(key: key);
@override
State<Bidi> createState() => _BidiState();
......@@ -811,7 +809,7 @@ class _BidiState extends State<Bidi> {
}
class Zalgo extends StatefulWidget {
const Zalgo({ Key key, this.seed }) : super(key: key);
const Zalgo({ Key? key, required this.seed }) : super(key: key);
final int seed;
......@@ -820,15 +818,14 @@ class Zalgo extends StatefulWidget {
}
class _ZalgoState extends State<Zalgo> with SingleTickerProviderStateMixin {
String _text;
Ticker _ticker;
math.Random _random;
String? _text;
late final Ticker _ticker = createTicker(_update)..start();
math.Random _random = math.Random();
@override
void initState() {
super.initState();
_random = math.Random(widget.seed); // providing a seed is important for reproducibility
_ticker = createTicker(_update)..start();
_random = math.Random(widget.seed); // providing a seed is important for reproducibility;
_update(null);
}
......@@ -841,7 +838,7 @@ class _ZalgoState extends State<Zalgo> with SingleTickerProviderStateMixin {
bool _allowSpacing = false;
bool _varyBase = false;
void _update(Duration duration) {
void _update(Duration? duration) {
setState(() {
_text = zalgo(
_random,
......@@ -918,7 +915,7 @@ class _ZalgoState extends State<Zalgo> with SingleTickerProviderStateMixin {
}
class Painting extends StatefulWidget {
const Painting({ Key key, this.seed }) : super(key: key);
const Painting({ Key? key, required this.seed }) : super(key: key);
final int seed;
......@@ -927,15 +924,14 @@ class Painting extends StatefulWidget {
}
class _PaintingState extends State<Painting> with SingleTickerProviderStateMixin {
String _text;
Ticker _ticker;
math.Random _random;
String? _text;
late final Ticker _ticker = createTicker(_update)..start();
math.Random _random = math.Random();
@override
void initState() {
super.initState();
_random = math.Random(widget.seed); // providing a seed is important for reproducibility
_ticker = createTicker(_update)..start();
_random = math.Random(widget.seed); // providing a seed is important for reproducibility;
_update(null);
}
......@@ -950,7 +946,7 @@ class _PaintingState extends State<Painting> with SingleTickerProviderStateMixin
bool _ellipsize = false;
void _update(Duration duration) {
void _update(Duration? duration) {
setState(() {
final StringBuffer buffer = StringBuffer();
final int targetLength = _random.nextInt(20) + (_ellipsize ? MediaQuery.of(context).size.width.round() : 1);
......@@ -963,11 +959,11 @@ class _PaintingState extends State<Painting> with SingleTickerProviderStateMixin
}
_text = buffer.toString();
});
SchedulerBinding.instance.addPostFrameCallback((Duration duration) {
if (mounted && intrinsicKey.currentContext.size.height != controlKey.currentContext.size.height) {
SchedulerBinding.instance?.addPostFrameCallback((Duration duration) {
if (mounted && intrinsicKey.currentContext?.size?.height != controlKey.currentContext?.size?.height) {
debugPrint('Found some text that unexpectedly renders at different heights.');
debugPrint('Text: $_text');
debugPrint(_text.runes.map<String>((int index) => 'U+' + index.toRadixString(16).padLeft(4, '0')).join(' '));
debugPrint(_text?.runes.map<String>((int index) => 'U+' + index.toRadixString(16).padLeft(4, '0')).join(' '));
setState(() {
_ticker.stop();
});
......@@ -1080,7 +1076,7 @@ class _PaintingState extends State<Painting> with SingleTickerProviderStateMixin
TextButton(
onPressed: _ticker.isActive ? null : () {
print('The currently visible text is: $_text');
print(_text.runes.map<String>((int value) => 'U+${value.toRadixString(16).padLeft(4, '0').toUpperCase()}').join(' '));
print(_text?.runes.map<String>((int value) => 'U+${value.toRadixString(16).padLeft(4, '0').toUpperCase()}').join(' '));
},
child: const Text('DUMP TEXT TO LOGS'),
),
......@@ -1096,7 +1092,7 @@ class _PaintingState extends State<Painting> with SingleTickerProviderStateMixin
}
}
String zalgo(math.Random random, int targetLength, { bool includeSpacingCombiningMarks = false, String base }) {
String zalgo(math.Random random, int targetLength, { bool includeSpacingCombiningMarks = false, String? base }) {
// The following three tables are derived from UnicodeData.txt:
// http://unicode.org/Public/UNIDATA/UnicodeData.txt
// There are three groups, character classes Mc, Me, and Mn.
......
name: manual_tests
environment:
sdk: ">=2.2.2 <3.0.0"
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
......
......@@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
import '../../../packages/flutter/test/image_data.dart';
// Returns a mock HTTP client that responds with an image to all requests.
FakeHttpClient createMockImageHttpClient(SecurityContext _) {
FakeHttpClient createMockImageHttpClient(SecurityContext? _) {
final FakeHttpClient client = FakeHttpClient();
return client;
}
......@@ -50,10 +50,10 @@ class FakeHttpClientResponse extends Fake implements HttpClientResponse {
HttpClientResponseCompressionState get compressionState => HttpClientResponseCompressionState.notCompressed;
@override
StreamSubscription<List<int>> listen(void Function(List<int>) onData, {
void Function() onDone,
Function onError,
bool cancelOnError,
StreamSubscription<List<int>> listen(void Function(List<int>)? onData, {
void Function()? onDone,
Function? onError,
bool? cancelOnError,
}) {
return Stream<List<int>>.fromIterable(<List<int>>[kTransparentImage])
.listen(onData, onDone: onDone, onError: onError, cancelOnError: cancelOnError);
......
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