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() { ...@@ -23,9 +23,9 @@ void main() {
/// the undo stack when they are invoked. /// the undo stack when they are invoked.
class Memento extends Object with Diagnosticable { class Memento extends Object with Diagnosticable {
const Memento({ const Memento({
@required this.name, required this.name,
@required this.undo, required this.undo,
@required this.redo, required this.redo,
}); });
/// Returns true if this Memento can be used to undo. /// Returns true if this Memento can be used to undo.
...@@ -110,11 +110,11 @@ class UndoableActionDispatcher extends ActionDispatcher implements Listenable { ...@@ -110,11 +110,11 @@ class UndoableActionDispatcher extends ActionDispatcher implements Listenable {
} }
@override @override
Object invokeAction(Action<Intent> action, Intent intent, [BuildContext context]) { Object? invokeAction(Action<Intent> action, Intent intent, [BuildContext? context]) {
final Object result = super.invokeAction(action, intent, context); final Object? result = super.invokeAction(action, intent, context);
print('Invoking ${action is UndoableAction ? 'undoable ' : ''}$intent as $action: $this '); print('Invoking ${action is UndoableAction ? 'undoable ' : ''}$intent as $action: $this ');
if (action is UndoableAction) { if (action is UndoableAction) {
_completedActions.addLast(result as Memento); _completedActions.addLast(result! as Memento);
_undoneActions.clear(); _undoneActions.clear();
_pruneActions(); _pruneActions();
notifyListeners(); notifyListeners();
...@@ -193,14 +193,22 @@ class UndoIntent extends Intent { ...@@ -193,14 +193,22 @@ class UndoIntent extends Intent {
class UndoAction extends Action<UndoIntent> { class UndoAction extends Action<UndoIntent> {
@override @override
bool isEnabled(UndoIntent intent) { 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; return manager.canUndo;
} }
@override @override
void invoke(UndoIntent intent) { void invoke(UndoIntent intent) {
final UndoableActionDispatcher manager = Actions.of(primaryFocus?.context ?? FocusDemo.appKey.currentContext) as UndoableActionDispatcher; final BuildContext? buildContext = primaryFocus?.context ?? FocusDemo.appKey.currentContext;
manager?.undo(); 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 { ...@@ -211,14 +219,22 @@ class RedoIntent extends Intent {
class RedoAction extends Action<RedoIntent> { class RedoAction extends Action<RedoIntent> {
@override @override
bool isEnabled(RedoIntent intent) { 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; return manager.canRedo;
} }
@override @override
RedoAction invoke(RedoIntent intent) { RedoAction invoke(RedoIntent intent) {
final UndoableActionDispatcher manager = Actions.of(primaryFocus.context) as UndoableActionDispatcher; final BuildContext? buildContext = primaryFocus?.context ?? FocusDemo.appKey.currentContext;
manager?.redo(); if (buildContext == null) {
return this;
}
final UndoableActionDispatcher manager = Actions.of(buildContext) as UndoableActionDispatcher;
manager.redo();
return this; return this;
} }
} }
...@@ -226,11 +242,11 @@ class RedoAction extends Action<RedoIntent> { ...@@ -226,11 +242,11 @@ class RedoAction extends Action<RedoIntent> {
/// An action that can be undone. /// An action that can be undone.
abstract class UndoableAction<T extends Intent> extends Action<T> { abstract class UndoableAction<T extends Intent> extends Action<T> {
/// The [Intent] this action was originally invoked with. /// The [Intent] this action was originally invoked with.
Intent get invocationIntent => _invocationTag; Intent? get invocationIntent => _invocationTag;
Intent _invocationTag; Intent? _invocationTag;
@protected @protected
set invocationIntent(Intent value) => _invocationTag = value; set invocationIntent(Intent? value) => _invocationTag = value;
@override @override
@mustCallSuper @mustCallSuper
...@@ -244,8 +260,8 @@ class UndoableFocusActionBase<T extends Intent> extends UndoableAction<T> { ...@@ -244,8 +260,8 @@ class UndoableFocusActionBase<T extends Intent> extends UndoableAction<T> {
@mustCallSuper @mustCallSuper
Memento invoke(T intent) { Memento invoke(T intent) {
super.invoke(intent); super.invoke(intent);
final FocusNode previousFocus = primaryFocus; final FocusNode? previousFocus = primaryFocus;
return Memento(name: previousFocus.debugLabel, undo: () { return Memento(name: previousFocus!.debugLabel!, undo: () {
previousFocus.requestFocus(); previousFocus.requestFocus();
}, redo: () { }, redo: () {
return invoke(intent); return invoke(intent);
...@@ -267,7 +283,7 @@ class UndoableNextFocusAction extends UndoableFocusActionBase<NextFocusIntent> { ...@@ -267,7 +283,7 @@ class UndoableNextFocusAction extends UndoableFocusActionBase<NextFocusIntent> {
@override @override
Memento invoke(NextFocusIntent intent) { Memento invoke(NextFocusIntent intent) {
final Memento memento = super.invoke(intent); final Memento memento = super.invoke(intent);
primaryFocus.nextFocus(); primaryFocus?.nextFocus();
return memento; return memento;
} }
} }
...@@ -276,25 +292,25 @@ class UndoablePreviousFocusAction extends UndoableFocusActionBase<PreviousFocusI ...@@ -276,25 +292,25 @@ class UndoablePreviousFocusAction extends UndoableFocusActionBase<PreviousFocusI
@override @override
Memento invoke(PreviousFocusIntent intent) { Memento invoke(PreviousFocusIntent intent) {
final Memento memento = super.invoke(intent); final Memento memento = super.invoke(intent);
primaryFocus.previousFocus(); primaryFocus?.previousFocus();
return memento; return memento;
} }
} }
class UndoableDirectionalFocusAction extends UndoableFocusActionBase<DirectionalFocusIntent> { class UndoableDirectionalFocusAction extends UndoableFocusActionBase<DirectionalFocusIntent> {
TraversalDirection direction; TraversalDirection? direction;
@override @override
Memento invoke(DirectionalFocusIntent intent) { Memento invoke(DirectionalFocusIntent intent) {
final Memento memento = super.invoke(intent); final Memento memento = super.invoke(intent);
primaryFocus.focusInDirection(intent.direction); primaryFocus?.focusInDirection(intent.direction);
return memento; return memento;
} }
} }
/// A button class that takes focus when clicked. /// A button class that takes focus when clicked.
class DemoButton extends StatefulWidget { 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; final String name;
...@@ -303,19 +319,13 @@ class DemoButton extends StatefulWidget { ...@@ -303,19 +319,13 @@ class DemoButton extends StatefulWidget {
} }
class _DemoButtonState extends State<DemoButton> { class _DemoButtonState extends State<DemoButton> {
FocusNode _focusNode; late final FocusNode _focusNode = FocusNode(debugLabel: widget.name);
final GlobalKey _nameKey = GlobalKey(); final GlobalKey _nameKey = GlobalKey();
@override
void initState() {
super.initState();
_focusNode = FocusNode(debugLabel: widget.name);
}
void _handleOnPressed() { void _handleOnPressed() {
print('Button ${widget.name} pressed.'); print('Button ${widget.name} pressed.');
setState(() { setState(() {
Actions.invoke(_nameKey.currentContext, RequestFocusIntent(_focusNode)); Actions.invoke(_nameKey.currentContext!, RequestFocusIntent(_focusNode));
}); });
} }
...@@ -336,7 +346,7 @@ class _DemoButtonState extends State<DemoButton> { ...@@ -336,7 +346,7 @@ class _DemoButtonState extends State<DemoButton> {
return Colors.red; return Colors.red;
if (states.contains(MaterialState.hovered)) if (states.contains(MaterialState.hovered))
return Colors.blue; return Colors.blue;
return null; return Colors.transparent;
}), }),
), ),
onPressed: () => _handleOnPressed(), onPressed: () => _handleOnPressed(),
...@@ -346,7 +356,7 @@ class _DemoButtonState extends State<DemoButton> { ...@@ -346,7 +356,7 @@ class _DemoButtonState extends State<DemoButton> {
} }
class FocusDemo extends StatefulWidget { class FocusDemo extends StatefulWidget {
const FocusDemo({Key key}) : super(key: key); const FocusDemo({Key? key}) : super(key: key);
static GlobalKey appKey = GlobalKey(); static GlobalKey appKey = GlobalKey();
...@@ -355,16 +365,14 @@ class FocusDemo extends StatefulWidget { ...@@ -355,16 +365,14 @@ class FocusDemo extends StatefulWidget {
} }
class _FocusDemoState extends State<FocusDemo> { class _FocusDemoState extends State<FocusDemo> {
FocusNode outlineFocus; final FocusNode outlineFocus = FocusNode(debugLabel: 'Demo Focus Node');
UndoableActionDispatcher dispatcher; late final UndoableActionDispatcher dispatcher = UndoableActionDispatcher();
bool canUndo; bool canUndo = false;
bool canRedo; bool canRedo = false;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
outlineFocus = FocusNode(debugLabel: 'Demo Focus Node');
dispatcher = UndoableActionDispatcher();
canUndo = dispatcher.canUndo; canUndo = dispatcher.canUndo;
canRedo = dispatcher.canRedo; canRedo = dispatcher.canRedo;
dispatcher.addListener(_handleUndoStateChange); dispatcher.addListener(_handleUndoStateChange);
...@@ -415,7 +423,7 @@ class _FocusDemoState extends State<FocusDemo> { ...@@ -415,7 +423,7 @@ class _FocusDemoState extends State<FocusDemo> {
debugLabel: 'Scope', debugLabel: 'Scope',
autofocus: true, autofocus: true,
child: DefaultTextStyle( child: DefaultTextStyle(
style: textTheme.headline4, style: textTheme.headline4!,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('Actions Demo'), title: const Text('Actions Demo'),
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class AnimatedIconsTestApp extends StatelessWidget { class AnimatedIconsTestApp extends StatelessWidget {
const AnimatedIconsTestApp({Key key}) : super(key: key); const AnimatedIconsTestApp({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -19,7 +19,7 @@ class AnimatedIconsTestApp extends StatelessWidget { ...@@ -19,7 +19,7 @@ class AnimatedIconsTestApp extends StatelessWidget {
} }
class IconsList extends StatelessWidget { class IconsList extends StatelessWidget {
const IconsList({Key key}) : super(key: key); const IconsList({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -30,7 +30,7 @@ class IconsList extends StatelessWidget { ...@@ -30,7 +30,7 @@ class IconsList extends StatelessWidget {
} }
class IconSampleRow extends StatefulWidget { 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; final IconSample sample;
...@@ -39,7 +39,7 @@ class IconSampleRow extends StatefulWidget { ...@@ -39,7 +39,7 @@ class IconSampleRow extends StatefulWidget {
} }
class IconSampleRowState extends State<IconSampleRow> with SingleTickerProviderStateMixin { class IconSampleRowState extends State<IconSampleRow> with SingleTickerProviderStateMixin {
AnimationController progress; late final AnimationController progress = AnimationController(vsync: this, duration: const Duration(milliseconds: 300));
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -63,7 +63,6 @@ class IconSampleRowState extends State<IconSampleRow> with SingleTickerProviderS ...@@ -63,7 +63,6 @@ class IconSampleRowState extends State<IconSampleRow> with SingleTickerProviderS
@override @override
void initState() { void initState() {
super.initState(); super.initState();
progress = AnimationController(vsync: this, duration: const Duration(milliseconds: 300));
progress.addListener(_handleChange); progress.addListener(_handleChange);
} }
......
...@@ -7,18 +7,18 @@ import 'dart:math'; ...@@ -7,18 +7,18 @@ import 'dart:math';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class CardModel { class CardModel {
CardModel(this.value, this.height) { CardModel(this.value, this.height) :
textController = TextEditingController(text: 'Item $value'); textController = TextEditingController(text: 'Item $value');
}
int value; int value;
double height; double height;
int get color => ((value % 9) + 1) * 100; int get color => ((value % 9) + 1) * 100;
TextEditingController textController; final TextEditingController textController;
Key get key => ObjectKey(this); Key get key => ObjectKey(this);
} }
class CardCollection extends StatefulWidget { class CardCollection extends StatefulWidget {
const CardCollection({Key key}) : super(key: key); const CardCollection({Key? key}) : super(key: key);
@override @override
CardCollectionState createState() => CardCollectionState(); CardCollectionState createState() => CardCollectionState();
...@@ -41,7 +41,7 @@ class CardCollectionState extends State<CardCollection> { ...@@ -41,7 +41,7 @@ class CardCollectionState extends State<CardCollection> {
]; ];
MaterialColor _primaryColor = Colors.deepPurple; MaterialColor _primaryColor = Colors.deepPurple;
List<CardModel> _cardModels; List<CardModel> _cardModels = <CardModel>[];
DismissDirection _dismissDirection = DismissDirection.horizontal; DismissDirection _dismissDirection = DismissDirection.horizontal;
TextAlign _textAlign = TextAlign.center; TextAlign _textAlign = TextAlign.center;
bool _editable = false; bool _editable = false;
...@@ -164,21 +164,21 @@ class CardCollectionState extends State<CardCollection> { ...@@ -164,21 +164,21 @@ class CardCollectionState extends State<CardCollection> {
}); });
} }
void _selectColor(MaterialColor selection) { void _selectColor(MaterialColor? selection) {
setState(() { setState(() {
_primaryColor = selection; _primaryColor = selection!;
}); });
} }
void _changeDismissDirection(DismissDirection newDismissDirection) { void _changeDismissDirection(DismissDirection? newDismissDirection) {
setState(() { setState(() {
_dismissDirection = newDismissDirection; _dismissDirection = newDismissDirection!;
}); });
} }
void _changeTextAlign(TextAlign newTextAlign) { void _changeTextAlign(TextAlign? newTextAlign) {
setState(() { setState(() {
_textAlign = newTextAlign; _textAlign = newTextAlign!;
}); });
} }
...@@ -193,7 +193,7 @@ class CardCollectionState extends State<CardCollection> { ...@@ -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( return ListTile(
leading: Icon(icon), leading: Icon(icon),
title: Text(label), title: Text(label),
...@@ -206,7 +206,7 @@ class CardCollectionState extends State<CardCollection> { ...@@ -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( return ListTile(
leading: Icon(icon), leading: Icon(icon),
title: Text(label), title: Text(label),
...@@ -219,7 +219,7 @@ class CardCollectionState extends State<CardCollection> { ...@@ -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( return ListTile(
leading: Icon(icon), leading: Icon(icon),
title: Text(label), title: Text(label),
...@@ -306,7 +306,7 @@ class CardCollectionState extends State<CardCollection> { ...@@ -306,7 +306,7 @@ class CardCollectionState extends State<CardCollection> {
rightArrowIcon = Opacity(opacity: 0.1, child: rightArrowIcon); rightArrowIcon = Opacity(opacity: 0.1, child: rightArrowIcon);
final ThemeData theme = Theme.of(context); 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 // The background Widget appears behind the Dismissible card when the card
// moves to the left or right. The Positioned widget ensures that the // moves to the left or right. The Positioned widget ensures that the
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ColorTestingDemo extends StatelessWidget { class ColorTestingDemo extends StatelessWidget {
const ColorTestingDemo({ Key key }) : super(key: key); const ColorTestingDemo({ Key? key }) : super(key: key);
static const String routeName = '/color_demo'; static const String routeName = '/color_demo';
...@@ -14,7 +14,7 @@ class ColorTestingDemo extends StatelessWidget { ...@@ -14,7 +14,7 @@ class ColorTestingDemo extends StatelessWidget {
} }
class ColorDemoHome extends StatelessWidget { class ColorDemoHome extends StatelessWidget {
const ColorDemoHome({Key key}) : super(key: key); const ColorDemoHome({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -52,7 +52,7 @@ class ColorDemoHome extends StatelessWidget { ...@@ -52,7 +52,7 @@ class ColorDemoHome extends StatelessWidget {
} }
class GradientRow 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 leftColor;
final Color rightColor; final Color rightColor;
...@@ -73,7 +73,7 @@ class GradientRow extends StatelessWidget { ...@@ -73,7 +73,7 @@ class GradientRow extends StatelessWidget {
} }
class ColorRow 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; final Color color;
......
...@@ -17,12 +17,12 @@ final Map<int, Color> m2SwatchColors = <int, Color>{ ...@@ -17,12 +17,12 @@ final Map<int, Color> m2SwatchColors = <int, Color>{
800: const Color(0xff270096), 800: const Color(0xff270096),
900: 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()); void main() => runApp(const MyApp());
class MyApp extends StatelessWidget { class MyApp extends StatelessWidget {
const MyApp({Key key}) : super(key: key); const MyApp({Key? key}) : super(key: key);
static const String _title = 'Density Test'; static const String _title = 'Density Test';
...@@ -36,7 +36,7 @@ class MyApp extends StatelessWidget { ...@@ -36,7 +36,7 @@ class MyApp extends StatelessWidget {
} }
class MyHomePage extends StatefulWidget { 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; final String title;
...@@ -112,11 +112,11 @@ class OptionModel extends ChangeNotifier { ...@@ -112,11 +112,11 @@ class OptionModel extends ChangeNotifier {
} }
class LabeledCheckbox extends StatelessWidget { 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 String label;
final ValueChanged<bool> onChanged; final ValueChanged<bool?>? onChanged;
final bool value; final bool? value;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
...@@ -134,7 +134,7 @@ class LabeledCheckbox extends StatelessWidget { ...@@ -134,7 +134,7 @@ class LabeledCheckbox extends StatelessWidget {
} }
class Options extends StatefulWidget { 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; final OptionModel model;
...@@ -181,7 +181,7 @@ class _OptionsState extends State<Options> { ...@@ -181,7 +181,7 @@ class _OptionsState extends State<Options> {
return 'custom'; return 'custom';
} }
VisualDensity _profileToDensity(String profile) { VisualDensity _profileToDensity(String? profile) {
switch (profile) { switch (profile) {
case 'standard': case 'standard':
return VisualDensity.standard; return VisualDensity.standard;
...@@ -304,7 +304,7 @@ class _OptionsState extends State<Options> { ...@@ -304,7 +304,7 @@ class _OptionsState extends State<Options> {
child: DropdownButton<String>( child: DropdownButton<String>(
style: TextStyle(color: Colors.grey[50]), style: TextStyle(color: Colors.grey[50]),
isDense: true, isDense: true,
onChanged: (String value) { onChanged: (String? value) {
widget.model.density = _profileToDensity(value); widget.model.density = _profileToDensity(value);
}, },
items: const <DropdownMenuItem<String>>[ items: const <DropdownMenuItem<String>>[
...@@ -321,15 +321,15 @@ class _OptionsState extends State<Options> { ...@@ -321,15 +321,15 @@ class _OptionsState extends State<Options> {
), ),
LabeledCheckbox( LabeledCheckbox(
label: 'Enabled', label: 'Enabled',
onChanged: (bool checked) { onChanged: (bool? checked) {
widget.model.enable = checked; widget.model.enable = checked == true;
}, },
value: widget.model.enable, value: widget.model.enable,
), ),
LabeledCheckbox( LabeledCheckbox(
label: 'Slow', label: 'Slow',
onChanged: (bool checked) { onChanged: (bool? checked) {
widget.model.slowAnimations = checked; widget.model.slowAnimations = checked == true;
Future<void>.delayed(const Duration(milliseconds: 150)).then((_) { Future<void>.delayed(const Duration(milliseconds: 150)).then((_) {
if (widget.model.slowAnimations) { if (widget.model.slowAnimations) {
timeDilation = 20.0; timeDilation = 20.0;
...@@ -342,8 +342,8 @@ class _OptionsState extends State<Options> { ...@@ -342,8 +342,8 @@ class _OptionsState extends State<Options> {
), ),
LabeledCheckbox( LabeledCheckbox(
label: 'RTL', label: 'RTL',
onChanged: (bool checked) { onChanged: (bool? checked) {
widget.model.rtl = checked; widget.model.rtl = checked == true;
}, },
value: widget.model.rtl, value: widget.model.rtl,
), ),
...@@ -365,7 +365,7 @@ class _OptionsState extends State<Options> { ...@@ -365,7 +365,7 @@ class _OptionsState extends State<Options> {
} }
class _ControlTile extends StatelessWidget { 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(label != null),
assert(child != null), assert(child != null),
super(key: key); super(key: key);
...@@ -398,13 +398,12 @@ class _ControlTile extends StatelessWidget { ...@@ -398,13 +398,12 @@ class _ControlTile extends StatelessWidget {
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
static final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>(); static final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey<ScaffoldState>();
final OptionModel _model = OptionModel(); final OptionModel _model = OptionModel();
TextEditingController textController; final TextEditingController textController = TextEditingController();
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_model.addListener(_modelChanged); _model.addListener(_modelChanged);
textController = TextEditingController();
} }
@override @override
...@@ -565,9 +564,9 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -565,9 +564,9 @@ class _MyHomePageState extends State<MyHomePage> {
children: List<Widget>.generate(checkboxValues.length, (int index) { children: List<Widget>.generate(checkboxValues.length, (int index) {
return Checkbox( return Checkbox(
onChanged: _model.enable onChanged: _model.enable
? (bool value) { ? (bool? value) {
setState(() { setState(() {
checkboxValues[index] = value; checkboxValues[index] = value == true;
}); });
} }
: null, : null,
...@@ -583,9 +582,9 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -583,9 +582,9 @@ class _MyHomePageState extends State<MyHomePage> {
children: List<Widget>.generate(4, (int index) { children: List<Widget>.generate(4, (int index) {
return Radio<int>( return Radio<int>(
onChanged: _model.enable onChanged: _model.enable
? (int value) { ? (int? value) {
setState(() { setState(() {
radioValue = value; radioValue = value!;
}); });
} }
: null, : null,
......
...@@ -7,7 +7,7 @@ import 'dart:math' as math; ...@@ -7,7 +7,7 @@ import 'dart:math' as math;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class ExampleDragTarget extends StatefulWidget { class ExampleDragTarget extends StatefulWidget {
const ExampleDragTarget({Key key}) : super(key: key); const ExampleDragTarget({Key? key}) : super(key: key);
@override @override
ExampleDragTargetState createState() => ExampleDragTargetState(); ExampleDragTargetState createState() => ExampleDragTargetState();
...@@ -26,7 +26,7 @@ class ExampleDragTargetState extends State<ExampleDragTarget> { ...@@ -26,7 +26,7 @@ class ExampleDragTargetState extends State<ExampleDragTarget> {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return DragTarget<Color>( return DragTarget<Color>(
onAccept: _handleAccept, onAccept: _handleAccept,
builder: (BuildContext context, List<Color> data, List<dynamic> rejectedData) { builder: (BuildContext context, List<Color?> data, List<dynamic> rejectedData) {
return Container( return Container(
height: 100.0, height: 100.0,
margin: const EdgeInsets.all(10.0), margin: const EdgeInsets.all(10.0),
...@@ -44,11 +44,11 @@ class ExampleDragTargetState extends State<ExampleDragTarget> { ...@@ -44,11 +44,11 @@ class ExampleDragTargetState extends State<ExampleDragTarget> {
} }
class Dot extends StatefulWidget { 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 Color? color;
final double size; final double? size;
final Widget child; final Widget? child;
final bool tappable; final bool tappable;
@override @override
...@@ -77,17 +77,17 @@ class DotState extends State<Dot> { ...@@ -77,17 +77,17 @@ class DotState extends State<Dot> {
class ExampleDragSource extends StatelessWidget { class ExampleDragSource extends StatelessWidget {
const ExampleDragSource({ const ExampleDragSource({
Key key, Key? key,
this.color, this.color,
this.heavy = false, this.heavy = false,
this.under = true, this.under = true,
this.child, this.child,
}) : super(key: key); }) : super(key: key);
final Color color; final Color? color;
final bool heavy; final bool heavy;
final bool under; final bool under;
final Widget child; final Widget? child;
static const double kDotSize = 50.0; static const double kDotSize = 50.0;
static const double kHeavyMultiplier = 1.5; static const double kHeavyMultiplier = 1.5;
...@@ -100,7 +100,7 @@ class ExampleDragSource extends StatelessWidget { ...@@ -100,7 +100,7 @@ class ExampleDragSource extends StatelessWidget {
size *= kHeavyMultiplier; size *= kHeavyMultiplier;
final Widget contents = DefaultTextStyle( final Widget contents = DefaultTextStyle(
style: Theme.of(context).textTheme.bodyText2, style: Theme.of(context).textTheme.bodyText2!,
textAlign: TextAlign.center, textAlign: TextAlign.center,
child: Dot( child: Dot(
color: color, color: color,
...@@ -176,7 +176,7 @@ class DashOutlineCirclePainter extends CustomPainter { ...@@ -176,7 +176,7 @@ class DashOutlineCirclePainter extends CustomPainter {
} }
class MovableBall extends StatelessWidget { 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 position;
final int ballPosition; final int ballPosition;
...@@ -188,7 +188,7 @@ class MovableBall extends StatelessWidget { ...@@ -188,7 +188,7 @@ class MovableBall extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final Widget ball = DefaultTextStyle( final Widget ball = DefaultTextStyle(
style: Theme.of(context).primaryTextTheme.bodyText2, style: Theme.of(context).primaryTextTheme.bodyText2!,
textAlign: TextAlign.center, textAlign: TextAlign.center,
child: Dot( child: Dot(
key: kBallKey, key: kBallKey,
...@@ -216,7 +216,7 @@ class MovableBall extends StatelessWidget { ...@@ -216,7 +216,7 @@ class MovableBall extends StatelessWidget {
} else { } else {
return DragTarget<bool>( return DragTarget<bool>(
onAccept: (bool data) { callback(position); }, 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; return dashedBall;
}, },
); );
...@@ -225,7 +225,7 @@ class MovableBall extends StatelessWidget { ...@@ -225,7 +225,7 @@ class MovableBall extends StatelessWidget {
} }
class DragAndDropApp extends StatefulWidget { class DragAndDropApp extends StatefulWidget {
const DragAndDropApp({Key key}) : super(key: key); const DragAndDropApp({Key? key}) : super(key: key);
@override @override
DragAndDropAppState createState() => DragAndDropAppState(); DragAndDropAppState createState() => DragAndDropAppState();
......
...@@ -13,7 +13,7 @@ void main() { ...@@ -13,7 +13,7 @@ void main() {
} }
class DemoButton extends StatefulWidget { 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 String name;
final bool canRequestFocus; final bool canRequestFocus;
...@@ -24,20 +24,14 @@ class DemoButton extends StatefulWidget { ...@@ -24,20 +24,14 @@ class DemoButton extends StatefulWidget {
} }
class _DemoButtonState extends State<DemoButton> { class _DemoButtonState extends State<DemoButton> {
FocusNode focusNode; late final FocusNode focusNode = FocusNode(
@override
void initState() {
super.initState();
focusNode = FocusNode(
debugLabel: widget.name, debugLabel: widget.name,
canRequestFocus: widget.canRequestFocus, canRequestFocus: widget.canRequestFocus,
); );
}
@override @override
void dispose() { void dispose() {
focusNode?.dispose(); focusNode.dispose();
super.dispose(); super.dispose();
} }
...@@ -64,7 +58,7 @@ class _DemoButtonState extends State<DemoButton> { ...@@ -64,7 +58,7 @@ class _DemoButtonState extends State<DemoButton> {
return Colors.red.withOpacity(0.25); return Colors.red.withOpacity(0.25);
if (states.contains(MaterialState.hovered)) if (states.contains(MaterialState.hovered))
return Colors.blue.withOpacity(0.25); return Colors.blue.withOpacity(0.25);
return null; return Colors.transparent;
}), }),
), ),
onPressed: () => _handleOnPressed(), onPressed: () => _handleOnPressed(),
...@@ -74,14 +68,14 @@ class _DemoButtonState extends State<DemoButton> { ...@@ -74,14 +68,14 @@ class _DemoButtonState extends State<DemoButton> {
} }
class FocusDemo extends StatefulWidget { class FocusDemo extends StatefulWidget {
const FocusDemo({Key key}) : super(key: key); const FocusDemo({Key? key}) : super(key: key);
@override @override
State<FocusDemo> createState() => _FocusDemoState(); State<FocusDemo> createState() => _FocusDemoState();
} }
class _FocusDemoState extends State<FocusDemo> { class _FocusDemoState extends State<FocusDemo> {
FocusNode outlineFocus; FocusNode? outlineFocus;
@override @override
void initState() { void initState() {
...@@ -91,7 +85,7 @@ class _FocusDemoState extends State<FocusDemo> { ...@@ -91,7 +85,7 @@ class _FocusDemoState extends State<FocusDemo> {
@override @override
void dispose() { void dispose() {
outlineFocus.dispose(); outlineFocus?.dispose();
super.dispose(); super.dispose();
} }
...@@ -142,7 +136,7 @@ class _FocusDemoState extends State<FocusDemo> { ...@@ -142,7 +136,7 @@ class _FocusDemoState extends State<FocusDemo> {
onKey: _handleKeyPress, onKey: _handleKeyPress,
autofocus: true, autofocus: true,
child: DefaultTextStyle( child: DefaultTextStyle(
style: textTheme.headline4, style: textTheme.headline4!,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('Focus Demo'), title: const Text('Focus Demo'),
......
...@@ -12,7 +12,7 @@ void main() { ...@@ -12,7 +12,7 @@ void main() {
} }
class DemoButton extends StatelessWidget { 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; final String name;
...@@ -30,7 +30,7 @@ class DemoButton extends StatelessWidget { ...@@ -30,7 +30,7 @@ class DemoButton extends StatelessWidget {
} }
class HoverDemo extends StatefulWidget { class HoverDemo extends StatefulWidget {
const HoverDemo({Key key}) : super(key: key); const HoverDemo({Key? key}) : super(key: key);
@override @override
State<HoverDemo> createState() => _HoverDemoState(); State<HoverDemo> createState() => _HoverDemoState();
...@@ -42,12 +42,12 @@ class _HoverDemoState extends State<HoverDemo> { ...@@ -42,12 +42,12 @@ class _HoverDemoState extends State<HoverDemo> {
final TextTheme textTheme = Theme.of(context).textTheme; final TextTheme textTheme = Theme.of(context).textTheme;
final ButtonStyle overrideFocusColor = ButtonStyle( final ButtonStyle overrideFocusColor = ButtonStyle(
overlayColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) { 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( return DefaultTextStyle(
style: textTheme.headline4, style: textTheme.headline4!,
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('Hover Demo'), title: const Text('Hover Demo'),
......
This diff is collapsed.
...@@ -20,8 +20,8 @@ enum MarkerType { topLeft, bottomRight, touch } ...@@ -20,8 +20,8 @@ enum MarkerType { topLeft, bottomRight, touch }
class _MarkerPainter extends CustomPainter { class _MarkerPainter extends CustomPainter {
const _MarkerPainter({ const _MarkerPainter({
this.size, required this.size,
this.type, required this.type,
}); });
final double size; final double size;
...@@ -56,21 +56,21 @@ class _MarkerPainter extends CustomPainter { ...@@ -56,21 +56,21 @@ class _MarkerPainter extends CustomPainter {
class Marker extends StatelessWidget { class Marker extends StatelessWidget {
const Marker({ const Marker({
Key key, Key? key,
this.type = MarkerType.touch, this.type = MarkerType.touch,
this.position, this.position,
this.size = 40.0, this.size = 40.0,
}) : super(key: key); }) : super(key: key);
final Offset position; final Offset? position;
final double size; final double size;
final MarkerType type; final MarkerType type;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Positioned( return Positioned(
left: position.dx - size / 2.0, left: position!.dx - size / 2.0,
top: position.dy - size / 2.0, top: position!.dy - size / 2.0,
width: size, width: size,
height: size, height: size,
child: IgnorePointer( child: IgnorePointer(
...@@ -86,7 +86,7 @@ class Marker extends StatelessWidget { ...@@ -86,7 +86,7 @@ class Marker extends StatelessWidget {
} }
class OverlayGeometryApp extends StatefulWidget { class OverlayGeometryApp extends StatefulWidget {
const OverlayGeometryApp({Key key}) : super(key: key); const OverlayGeometryApp({Key? key}) : super(key: key);
@override @override
OverlayGeometryAppState createState() => OverlayGeometryAppState(); OverlayGeometryAppState createState() => OverlayGeometryAppState();
...@@ -95,22 +95,22 @@ class OverlayGeometryApp extends StatefulWidget { ...@@ -95,22 +95,22 @@ class OverlayGeometryApp extends StatefulWidget {
typedef CardTapCallback = void Function(GlobalKey targetKey, Offset globalPosition); typedef CardTapCallback = void Function(GlobalKey targetKey, Offset globalPosition);
class CardBuilder extends SliverChildDelegate { class CardBuilder extends SliverChildDelegate {
CardBuilder({ this.cardModels, this.onTapUp }); CardBuilder({List<CardModel>? cardModels, this.onTapUp }) : cardModels = cardModels ?? <CardModel>[];
final List<CardModel> cardModels; final List<CardModel> cardModels;
final CardTapCallback onTapUp; final CardTapCallback? onTapUp;
static const TextStyle cardLabelStyle = static const TextStyle cardLabelStyle =
TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold); TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold);
@override @override
Widget build(BuildContext context, int index) { Widget? build(BuildContext context, int index) {
if (index >= cardModels.length) if (index >= cardModels.length)
return null; return null;
final CardModel cardModel = cardModels[index]; final CardModel cardModel = cardModels[index];
return GestureDetector( return GestureDetector(
key: cardModel.key, key: cardModel.key,
onTapUp: (TapUpDetails details) { onTapUp(cardModel.targetKey, details.globalPosition); }, onTapUp: (TapUpDetails details) { onTapUp!(cardModel.targetKey, details.globalPosition); },
child: Card( child: Card(
key: cardModel.targetKey, key: cardModel.targetKey,
color: cardModel.color, color: cardModel.color,
...@@ -133,7 +133,7 @@ class CardBuilder extends SliverChildDelegate { ...@@ -133,7 +133,7 @@ class CardBuilder extends SliverChildDelegate {
} }
class OverlayGeometryAppState extends State<OverlayGeometryApp> { class OverlayGeometryAppState extends State<OverlayGeometryApp> {
List<CardModel> cardModels; List<CardModel> cardModels = <CardModel>[];
Map<MarkerType, Offset> markers = <MarkerType, Offset>{}; Map<MarkerType, Offset> markers = <MarkerType, Offset>{};
double markersScrollOffset = 0.0; double markersScrollOffset = 0.0;
...@@ -146,8 +146,8 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> { ...@@ -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, 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) { cardModels = List<CardModel>.generate(cardHeights.length, (int i) {
final Color color = Color.lerp(Colors.red.shade300, Colors.blue.shade900, i / cardHeights.length); final Color? color = Color.lerp(Colors.red.shade300, Colors.blue.shade900, i / cardHeights.length);
return CardModel(i, cardHeights[i], color); return CardModel(i, cardHeights[i], color!);
}); });
} }
...@@ -156,10 +156,9 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> { ...@@ -156,10 +156,9 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
setState(() { setState(() {
final double dy = markersScrollOffset - notification.metrics.extentBefore; final double dy = markersScrollOffset - notification.metrics.extentBefore;
markersScrollOffset = notification.metrics.extentBefore; markersScrollOffset = notification.metrics.extentBefore;
for (final MarkerType type in markers.keys) { markers.forEach((MarkerType type, Offset oldPosition) {
final Offset oldPosition = markers[type];
markers[type] = oldPosition.translate(0.0, dy); markers[type] = oldPosition.translate(0.0, dy);
} });
}); });
} }
return false; return false;
...@@ -168,12 +167,12 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> { ...@@ -168,12 +167,12 @@ class OverlayGeometryAppState extends State<OverlayGeometryApp> {
void handleTapUp(GlobalKey target, Offset globalPosition) { void handleTapUp(GlobalKey target, Offset globalPosition) {
setState(() { setState(() {
markers[MarkerType.touch] = globalPosition; markers[MarkerType.touch] = globalPosition;
final RenderBox box = target.currentContext.findRenderObject() as RenderBox; final RenderBox? box = target.currentContext?.findRenderObject() as RenderBox?;
markers[MarkerType.topLeft] = box.localToGlobal(Offset.zero); markers[MarkerType.topLeft] = box!.localToGlobal(Offset.zero);
final Size size = box.size; final Size size = box.size;
markers[MarkerType.bottomRight] = box.localToGlobal(Offset(size.width, size.height)); markers[MarkerType.bottomRight] = box.localToGlobal(Offset(size.width, size.height));
final ScrollableState scrollable = Scrollable.of(target.currentContext); final ScrollableState? scrollable = Scrollable.of(target.currentContext!);
markersScrollOffset = scrollable.position.pixels; markersScrollOffset = scrollable!.position.pixels;
}); });
} }
......
...@@ -14,7 +14,7 @@ class CardModel { ...@@ -14,7 +14,7 @@ class CardModel {
} }
class PageViewApp extends StatefulWidget { class PageViewApp extends StatefulWidget {
const PageViewApp({Key key}) : super(key: key); const PageViewApp({Key? key}) : super(key: key);
@override @override
PageViewAppState createState() => PageViewAppState(); PageViewAppState createState() => PageViewAppState();
...@@ -33,15 +33,15 @@ class PageViewAppState extends State<PageViewApp> { ...@@ -33,15 +33,15 @@ class PageViewAppState extends State<PageViewApp> {
]; ];
cardModels = List<CardModel>.generate(cardSizes.length, (int i) { cardModels = List<CardModel>.generate(cardSizes.length, (int i) {
final Color color = Color.lerp(Colors.red.shade300, Colors.blue.shade900, i / cardSizes.length); final Color? color = Color.lerp(Colors.red.shade300, Colors.blue.shade900, i / cardSizes.length);
return CardModel(i, cardSizes[i], color); return CardModel(i, cardSizes[i], color!);
}); });
} }
static const TextStyle cardLabelStyle = static const TextStyle cardLabelStyle =
TextStyle(color: Colors.white, fontSize: 18.0, fontWeight: FontWeight.bold); 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); Size pageSize = const Size(200.0, 200.0);
Axis scrollDirection = Axis.horizontal; Axis scrollDirection = Axis.horizontal;
bool itemsWrap = false; bool itemsWrap = false;
......
...@@ -20,7 +20,7 @@ void main() { ...@@ -20,7 +20,7 @@ void main() {
} }
class RawKeyboardDemo extends StatefulWidget { class RawKeyboardDemo extends StatefulWidget {
const RawKeyboardDemo({Key key}) : super(key: key); const RawKeyboardDemo({Key? key}) : super(key: key);
@override @override
State<RawKeyboardDemo> createState() => _HardwareKeyDemoState(); State<RawKeyboardDemo> createState() => _HardwareKeyDemoState();
...@@ -28,7 +28,7 @@ class RawKeyboardDemo extends StatefulWidget { ...@@ -28,7 +28,7 @@ class RawKeyboardDemo extends StatefulWidget {
class _HardwareKeyDemoState extends State<RawKeyboardDemo> { class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
final FocusNode _focusNode = FocusNode(); final FocusNode _focusNode = FocusNode();
RawKeyEvent _event; RawKeyEvent? _event;
@override @override
void dispose() { void dispose() {
...@@ -60,7 +60,7 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> { ...@@ -60,7 +60,7 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
autofocus: true, autofocus: true,
child: AnimatedBuilder( child: AnimatedBuilder(
animation: _focusNode, animation: _focusNode,
builder: (BuildContext context, Widget child) { builder: (BuildContext context, Widget? child) {
if (!_focusNode.hasFocus) { if (!_focusNode.hasFocus) {
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
...@@ -74,11 +74,11 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> { ...@@ -74,11 +74,11 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
return Text('Press a key', style: textTheme.headline4); return Text('Press a key', style: textTheme.headline4);
} }
final RawKeyEventData data = _event.data; final RawKeyEventData? data = _event?.data;
final String modifierList = data.modifiersPressed.keys.map<String>(_getEnumName).join(', ').replaceAll('Modifier', ''); final String? modifierList = data?.modifiersPressed.keys.map<String>(_getEnumName).join(', ').replaceAll('Modifier', '');
final List<Widget> dataText = <Widget>[ final List<Widget> dataText = <Widget>[
Text('${_event.runtimeType}'), 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'), Text('modifiers set: $modifierList'),
]; ];
if (data is RawKeyEventDataAndroid) { if (data is RawKeyEventDataAndroid) {
...@@ -119,12 +119,12 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> { ...@@ -119,12 +119,12 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
dataText.add(Text('code: ${data.code}')); dataText.add(Text('code: ${data.code}'));
dataText.add(Text('metaState: ${data.metaState} (${_asHex(data.metaState)})')); dataText.add(Text('metaState: ${data.metaState} (${_asHex(data.metaState)})'));
} }
dataText.add(Text('logical: ${_event.logicalKey}')); dataText.add(Text('logical: ${_event?.logicalKey}'));
dataText.add(Text('physical: ${_event.physicalKey}')); dataText.add(Text('physical: ${_event?.physicalKey}'));
if (_event.character != null) { if (_event?.character != null) {
dataText.add(Text('character: ${_event.character}')); 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) { for (final KeyboardSide side in KeyboardSide.values) {
if (data.isModifierPressed(modifier, side: side)) { if (data.isModifierPressed(modifier, side: side)) {
dataText.add( dataText.add(
...@@ -135,11 +135,11 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> { ...@@ -135,11 +135,11 @@ class _HardwareKeyDemoState extends State<RawKeyboardDemo> {
} }
final List<String> pressed = <String>['Pressed:']; final List<String> pressed = <String>['Pressed:'];
for (final LogicalKeyboardKey key in RawKeyboard.instance.keysPressed) { for (final LogicalKeyboardKey key in RawKeyboard.instance.keysPressed) {
pressed.add(key.debugName); pressed.add(key.debugName!);
} }
dataText.add(Text(pressed.join(' '))); dataText.add(Text(pressed.join(' ')));
return DefaultTextStyle( return DefaultTextStyle(
style: textTheme.subtitle1, style: textTheme.subtitle1!,
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: dataText, children: dataText,
......
This diff is collapsed.
name: manual_tests name: manual_tests
environment: environment:
sdk: ">=2.2.2 <3.0.0" sdk: ">=2.12.0 <3.0.0"
dependencies: dependencies:
flutter: flutter:
......
...@@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart'; ...@@ -10,7 +10,7 @@ import 'package:flutter_test/flutter_test.dart';
import '../../../packages/flutter/test/image_data.dart'; import '../../../packages/flutter/test/image_data.dart';
// Returns a mock HTTP client that responds with an image to all requests. // Returns a mock HTTP client that responds with an image to all requests.
FakeHttpClient createMockImageHttpClient(SecurityContext _) { FakeHttpClient createMockImageHttpClient(SecurityContext? _) {
final FakeHttpClient client = FakeHttpClient(); final FakeHttpClient client = FakeHttpClient();
return client; return client;
} }
...@@ -50,10 +50,10 @@ class FakeHttpClientResponse extends Fake implements HttpClientResponse { ...@@ -50,10 +50,10 @@ class FakeHttpClientResponse extends Fake implements HttpClientResponse {
HttpClientResponseCompressionState get compressionState => HttpClientResponseCompressionState.notCompressed; HttpClientResponseCompressionState get compressionState => HttpClientResponseCompressionState.notCompressed;
@override @override
StreamSubscription<List<int>> listen(void Function(List<int>) onData, { StreamSubscription<List<int>> listen(void Function(List<int>)? onData, {
void Function() onDone, void Function()? onDone,
Function onError, Function? onError,
bool cancelOnError, bool? cancelOnError,
}) { }) {
return Stream<List<int>>.fromIterable(<List<int>>[kTransparentImage]) return Stream<List<int>>.fromIterable(<List<int>>[kTransparentImage])
.listen(onData, onDone: onDone, onError: onError, cancelOnError: cancelOnError); .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