diff --git a/lib/models/pad_button_item.dart b/lib/models/pad_button_item.dart index eac22d4..64a0525 100644 --- a/lib/models/pad_button_item.dart +++ b/lib/models/pad_button_item.dart @@ -11,15 +11,15 @@ class PadButtonItem { /// [buttonText] optional parameter, the text to be displayed inside the /// button. Omitted if [buttonImage] is set. Default value is empty string. - final String buttonText; + final String? buttonText; /// [buttonImage] optional parameter, image which will be displayed inside /// the button. - final Image buttonImage; + final Image? buttonImage; /// [buttonIcon] optional parameter, image which will be displayed inside /// the button. - final Icon buttonIcon; + final Icon? buttonIcon; /// [backgroundColor] color of button in default state. final Color backgroundColor; @@ -34,7 +34,7 @@ class PadButtonItem { final List supportedGestures; const PadButtonItem({ - @required this.index, + required this.index, this.buttonText, this.buttonImage, this.buttonIcon, diff --git a/lib/views/circle_view.dart b/lib/views/circle_view.dart index b201b4a..8701c01 100644 --- a/lib/views/circle_view.dart +++ b/lib/views/circle_view.dart @@ -2,21 +2,21 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; class CircleView extends StatelessWidget { - final double size; + final double? size; - final Color color; + final Color? color; - final List boxShadow; + final List? boxShadow; - final Border border; + final Border? border; - final double opacity; + final double? opacity; - final Image buttonImage; + final Image? buttonImage; - final Icon buttonIcon; + final Icon? buttonIcon; - final String buttonText; + final String? buttonText; CircleView({ this.size, @@ -39,7 +39,7 @@ class CircleView extends StatelessWidget { ? buttonIcon : (buttonImage != null) ? buttonImage - : (buttonText != null) ? Text(buttonText) : null, + : (buttonText != null) ? Text(buttonText!) : null, ), decoration: BoxDecoration( color: color, @@ -87,7 +87,7 @@ class CircleView extends StatelessWidget { factory CircleView.padBackgroundCircle( double size, Color backgroundColour, borderColor, Color shadowColor, - {double opacity}) => + {double? opacity}) => CircleView( size: size, color: backgroundColour, @@ -108,10 +108,10 @@ class CircleView extends StatelessWidget { factory CircleView.padButtonCircle( double size, - Color color, - Image image, - Icon icon, - String text, + Color? color, + Image? image, + Icon? icon, + String? text, ) => CircleView( size: size, diff --git a/lib/views/joystick_view.dart b/lib/views/joystick_view.dart index bbc32b0..f45ee1c 100644 --- a/lib/views/joystick_view.dart +++ b/lib/views/joystick_view.dart @@ -13,7 +13,7 @@ class JoystickView extends StatelessWidget { /// /// Defaults to half of the width in the portrait /// or half of the height in the landscape mode - final double size; + final double? size; /// Color of the icons /// @@ -35,12 +35,12 @@ class JoystickView extends StatelessWidget { /// The opacity applies to the whole joystick including icons /// /// Defaults to [null] which means there will be no [Opacity] widget used - final double opacity; + final double? opacity; /// Callback to be called when user pans the joystick /// /// Defaults to [null] - final JoystickDirectionCallback onDirectionChanged; + final JoystickDirectionCallback? onDirectionChanged; /// Indicates how often the [onDirectionChanged] should be called. /// @@ -50,7 +50,7 @@ class JoystickView extends StatelessWidget { /// /// The exception is the [onDirectionChanged] callback being called /// on the [onPanStart] and [onPanEnd] callbacks. It will be called immediately. - final Duration interval; + final Duration? interval; /// Shows top/right/bottom/left arrows on top of Joystick /// @@ -70,7 +70,7 @@ class JoystickView extends StatelessWidget { @override Widget build(BuildContext context) { double actualSize = size != null - ? size + ? size! : _math.min(MediaQuery.of(context).size.width, MediaQuery.of(context).size.height) * 0.5; @@ -79,7 +79,7 @@ class JoystickView extends StatelessWidget { Offset joystickInnerPosition = _calculatePositionOfInnerCircle( lastPosition, innerCircleSize, actualSize, Offset(0, 0)); - DateTime _callbackTimestamp; + DateTime? _callbackTimestamp; return Center( child: StatefulBuilder( @@ -111,7 +111,7 @@ class JoystickView extends StatelessWidget { onPanEnd: (details) { _callbackTimestamp = null; if (onDirectionChanged != null) { - onDirectionChanged(0, 0); + onDirectionChanged!(0, 0); } joystickInnerPosition = _calculatePositionOfInnerCircle( Offset(innerCircleSize, innerCircleSize), @@ -133,7 +133,7 @@ class JoystickView extends StatelessWidget { setState(() => lastPosition = details.localPosition); }, child: (opacity != null) - ? Opacity(opacity: opacity, child: joystick) + ? Opacity(opacity: opacity!, child: joystick) : joystick, ); }, @@ -182,8 +182,8 @@ class JoystickView extends StatelessWidget { ]; } - DateTime _processGesture(double size, double ignoreSize, Offset offset, - DateTime callbackTimestamp) { + DateTime? _processGesture(double size, double ignoreSize, Offset offset, + DateTime? callbackTimestamp) { double middle = size / 2.0; double angle = _math.atan2(offset.dy - middle, offset.dx - middle); @@ -200,11 +200,11 @@ class JoystickView extends StatelessWidget { double normalizedDistance = _math.min(distance / (size / 2), 1.0); - DateTime _callbackTimestamp = callbackTimestamp; + DateTime? _callbackTimestamp = callbackTimestamp; if (onDirectionChanged != null && _canCallOnDirectionChanged(callbackTimestamp)) { _callbackTimestamp = DateTime.now(); - onDirectionChanged(degrees, normalizedDistance); + onDirectionChanged!(degrees, normalizedDistance); } return _callbackTimestamp; @@ -214,9 +214,9 @@ class JoystickView extends StatelessWidget { /// /// Returns true if enough time has passed since last time it was called /// or when there is no [interval] set. - bool _canCallOnDirectionChanged(DateTime callbackTimestamp) { + bool _canCallOnDirectionChanged(DateTime? callbackTimestamp) { if (interval != null && callbackTimestamp != null) { - int intervalMilliseconds = interval.inMilliseconds; + int intervalMilliseconds = interval!.inMilliseconds; int timestampMilliseconds = callbackTimestamp.millisecondsSinceEpoch; int currentTimeMilliseconds = DateTime.now().millisecondsSinceEpoch; diff --git a/lib/views/pad_button_view.dart b/lib/views/pad_button_view.dart index 906d057..54278b6 100644 --- a/lib/views/pad_button_view.dart +++ b/lib/views/pad_button_view.dart @@ -16,14 +16,14 @@ class PadButtonsView extends StatelessWidget { /// recalculated for pad buttons size. /// /// Default value is calculated according to screen size. - final double size; + final double? size; /// List of pad buttons, default contains 4 buttons final List buttons; /// [padButtonPressedCallback] contains information which button(index) was /// used by user and what gesture was done on it. - final PadButtonPressedCallback padButtonPressedCallback; + final PadButtonPressedCallback? padButtonPressedCallback; /// [buttonsStateMap] contains current colors of each button. final Map buttonsStateMap = HashMap(); @@ -53,7 +53,7 @@ class PadButtonsView extends StatelessWidget { @override Widget build(BuildContext context) { double actualSize = size != null - ? size + ? size! : _math.min(MediaQuery.of(context).size.width, MediaQuery.of(context).size.height) * 0.5; @@ -64,7 +64,7 @@ class PadButtonsView extends StatelessWidget { } List createButtons(double innerCircleSize, double actualSize) { - List list = List(); + List list = []; list.add(CircleView.padBackgroundCircle( actualSize, backgroundPadButtonsColor, @@ -148,7 +148,7 @@ class PadButtonsView extends StatelessWidget { void _processGesture(PadButtonItem button, Gestures gesture) { if (padButtonPressedCallback != null && button.supportedGestures.contains(gesture)) { - padButtonPressedCallback(button.index, gesture); + padButtonPressedCallback!(button.index, gesture); print("$gesture paddbutton id = ${[button.index]}"); } } diff --git a/pubspec.lock b/pubspec.lock index ea53bf7..824d5d1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1,62 +1,55 @@ # Generated by pub # See https://dart.dev/tools/pub/glossary#lockfile packages: - archive: - dependency: transitive - description: - name: archive - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.11" - args: - dependency: transitive - description: - name: args - url: "https://pub.dartlang.org" - source: hosted - version: "1.5.2" async: dependency: transitive description: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.0" + version: "2.6.1" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.1.0" + characters: + dependency: transitive + description: + name: characters + url: "https://pub.dartlang.org" + source: hosted + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.2" - collection: + version: "1.2.0" + clock: dependency: transitive description: - name: collection + name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.14.11" - convert: + version: "1.1.0" + collection: dependency: transitive description: - name: convert + name: collection url: "https://pub.dartlang.org" source: hosted - version: "2.1.1" - crypto: + version: "1.15.0" + fake_async: dependency: transitive description: - name: crypto + name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "2.1.3" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -67,34 +60,27 @@ packages: description: flutter source: sdk version: "0.0.0" - image: - dependency: transitive - description: - name: image - url: "https://pub.dartlang.org" - source: hosted - version: "2.1.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.6" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.6.4" + version: "1.8.0" pedantic: dependency: "direct dev" description: @@ -102,20 +88,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0+1" - petitparser: - dependency: transitive - description: - name: petitparser - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.5" sky_engine: dependency: transitive description: flutter @@ -127,62 +99,55 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.5.5" + version: "1.8.1" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.3" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.11" + version: "0.3.0" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.1.6" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" - xml: - dependency: transitive - description: - name: xml - url: "https://pub.dartlang.org" - source: hosted - version: "3.5.0" + version: "2.1.0" sdks: - dart: ">=2.4.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 68db99d..0814871 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ version: 1.1.1+1 homepage: https://github.com/artrmz/flutter_control_pad environment: - sdk: ">=2.2.2 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: