Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/models/pad_button_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +34,7 @@ class PadButtonItem {
final List<Gestures> supportedGestures;

const PadButtonItem({
@required this.index,
required this.index,
this.buttonText,
this.buttonImage,
this.buttonIcon,
Expand Down
28 changes: 14 additions & 14 deletions lib/views/circle_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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> boxShadow;
final List<BoxShadow>? 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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
28 changes: 14 additions & 14 deletions lib/views/joystick_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand All @@ -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.
///
Expand All @@ -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
///
Expand All @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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),
Expand All @@ -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,
);
},
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;

Expand Down
10 changes: 5 additions & 5 deletions lib/views/pad_button_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<PadButtonItem> 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<int, Color> buttonsStateMap = HashMap<int, Color>();
Expand Down Expand Up @@ -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;
Expand All @@ -64,7 +64,7 @@ class PadButtonsView extends StatelessWidget {
}

List<Widget> createButtons(double innerCircleSize, double actualSize) {
List<Widget> list = List();
List<Widget> list = [];
list.add(CircleView.padBackgroundCircle(
actualSize,
backgroundPadButtonsColor,
Expand Down Expand Up @@ -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]}");
}
}
Expand Down
Loading