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'),
......
This diff is collapsed.
......@@ -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,
......
This diff is collapsed.
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