Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ class VerticalSpinBoxPage extends StatelessWidget {
textStyle: TextStyle(fontSize: 48),
incrementIcon: Icon(Icons.keyboard_arrow_up, size: 64),
decrementIcon: Icon(Icons.keyboard_arrow_down, size: 64),
iconColor: MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.disabled)) {
iconColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.disabled)) {
return Colors.grey;
}
if (states.contains(MaterialState.error)) {
if (states.contains(WidgetState.error)) {
return Colors.red;
}
if (states.contains(MaterialState.focused)) {
if (states.contains(WidgetState.focused)) {
return Colors.blue;
}
return Colors.black;
Expand Down
2 changes: 1 addition & 1 deletion lib/flutter_spinbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
///
/// SpinBox for Flutter comes in two variants. It provides implementations for
/// both designs in Flutter, Material and Cupertino (iOS).
library flutter_spinbox;
library;

export 'cupertino.dart';
export 'material.dart';
2 changes: 1 addition & 1 deletion lib/src/base_spin_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import 'spin_formatter.dart';
// ignore_for_file: public_member_api_docs

abstract class BaseSpinBox extends StatefulWidget {
const BaseSpinBox({Key? key}) : super(key: key);
const BaseSpinBox({super.key});

double get min;
double get max;
Expand Down
5 changes: 2 additions & 3 deletions lib/src/cupertino/spin_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ part 'third_party/default_rounded_border.dart';
class CupertinoSpinBox extends BaseSpinBox {
/// Creates a spinbox.
CupertinoSpinBox({
Key? key,
super.key,
this.min = 0,
this.max = 100,
this.step = 1,
Expand Down Expand Up @@ -96,8 +96,7 @@ class CupertinoSpinBox extends BaseSpinBox {
incrementIcon =
incrementIcon ?? const Icon(CupertinoIcons.plus_circled),
decrementIcon =
decrementIcon ?? const Icon(CupertinoIcons.minus_circled),
super(key: key);
decrementIcon ?? const Icon(CupertinoIcons.minus_circled);

/// The minimum value the user can enter.
///
Expand Down
4 changes: 2 additions & 2 deletions lib/src/cupertino/spin_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ const double kSpinPadding = 16;

class CupertinoSpinButton extends StatelessWidget {
const CupertinoSpinButton({
Key? key,
super.key,
required this.icon,
this.color,
this.enabled = true,
required this.step,
this.acceleration,
required this.interval,
required this.onStep,
}) : super(key: key);
});

final Icon icon;
final Color? color;
Expand Down
37 changes: 16 additions & 21 deletions lib/src/material/spin_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import 'spin_button.dart';
class SpinBox extends BaseSpinBox {
/// Creates a spinbox.
SpinBox({
Key? key,
super.key,
this.min = 0,
this.max = 100,
this.step = 1,
Expand Down Expand Up @@ -95,8 +95,7 @@ class SpinBox extends BaseSpinBox {
),
enabled = (enabled ?? true) && min < max,
incrementIcon = incrementIcon ?? const Icon(Icons.add),
decrementIcon = decrementIcon ?? const Icon(Icons.remove),
super(key: key);
decrementIcon = decrementIcon ?? const Icon(Icons.remove);

/// The minimum value the user can enter.
///
Expand Down Expand Up @@ -194,7 +193,7 @@ class SpinBox extends BaseSpinBox {
///
/// If `null`, then the value of [SpinBoxThemeData.iconColor] is used. If
/// that is also `null`, then pre-defined defaults are used.
final MaterialStateProperty<Color?>? iconColor;
final WidgetStateProperty<Color?>? iconColor;

/// Whether the increment and decrement buttons are shown.
///
Expand Down Expand Up @@ -281,14 +280,10 @@ class SpinBoxState extends State<SpinBox> with SpinBoxMixin {
if (!widget.enabled) return theme.disabledColor;
if (hasFocus && errorText == null) return theme.colorScheme.primary;

switch (theme.brightness) {
case Brightness.dark:
return Colors.white70;
case Brightness.light:
return Colors.black45;
default:
return theme.iconTheme.color;
}
return switch (theme.brightness) {
Brightness.dark => Colors.white70,
Brightness.light => Colors.black45,
};
}

double _textHeight(String? text, TextStyle style) {
Expand Down Expand Up @@ -318,19 +313,19 @@ class SpinBoxState extends State<SpinBox> with SpinBoxMixin {

final iconColor = widget.iconColor ??
spinBoxTheme?.iconColor ??
MaterialStateProperty.all(_iconColor(theme, errorText));
WidgetStateProperty.all(_iconColor(theme, errorText));

final states = <MaterialState>{
if (!widget.enabled) MaterialState.disabled,
if (hasFocus) MaterialState.focused,
if (errorText != null) MaterialState.error,
final states = <WidgetState>{
if (!widget.enabled) WidgetState.disabled,
if (hasFocus) WidgetState.focused,
if (errorText != null) WidgetState.error,
};

final decrementStates = Set<MaterialState>.of(states);
if (value <= widget.min) decrementStates.add(MaterialState.disabled);
final decrementStates = Set<WidgetState>.of(states);
if (value <= widget.min) decrementStates.add(WidgetState.disabled);

final incrementStates = Set<MaterialState>.of(states);
if (value >= widget.max) incrementStates.add(MaterialState.disabled);
final incrementStates = Set<WidgetState>.of(states);
if (value >= widget.max) incrementStates.add(WidgetState.disabled);

var bottom = 0.0;
final isHorizontal = widget.direction == Axis.horizontal;
Expand Down
18 changes: 9 additions & 9 deletions lib/src/material/spin_box_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class SpinBoxThemeData with Diagnosticable {
/// The color to use for [SpinBox.incrementIcon] and [SpinBox.decrementIcon].
///
/// Resolves in the following states:
/// * [MaterialState.focused].
/// * [MaterialState.disabled].
/// * [MaterialState.error].
/// * [WidgetState.focused].
/// * [WidgetState.disabled].
/// * [WidgetState.error].
///
/// If specified, overrides the default value of [SpinBox.iconColor].
final MaterialStateProperty<Color?>? iconColor;
final WidgetStateProperty<Color?>? iconColor;

/// See [TextField.decoration].
///
Expand All @@ -39,7 +39,7 @@ class SpinBoxThemeData with Diagnosticable {
/// new values.
SpinBoxThemeData copyWith({
double? iconSize,
MaterialStateProperty<Color?>? iconColor,
WidgetStateProperty<Color?>? iconColor,
InputDecoration? decoration,
}) {
return SpinBoxThemeData(
Expand Down Expand Up @@ -73,7 +73,7 @@ class SpinBoxThemeData with Diagnosticable {
),
);
properties.add(
DiagnosticsProperty<MaterialStateProperty<Color?>>(
DiagnosticsProperty<WidgetStateProperty<Color?>>(
'iconColor',
iconColor,
defaultValue: null,
Expand Down Expand Up @@ -103,10 +103,10 @@ class SpinBoxTheme extends InheritedWidget {
/// Constructs a checkbox theme that configures all descendant [SpinBox]
/// widgets.
const SpinBoxTheme({
Key? key,
super.key,
required this.data,
required Widget child,
}) : super(key: key, child: child);
required super.child,
});

/// The properties used for all descendant [SpinBox] widgets.
final SpinBoxThemeData data;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/material/spin_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import '../spin_gesture.dart';

class SpinButton extends StatelessWidget {
const SpinButton({
Key? key,
super.key,
required this.icon,
this.iconSize,
this.color,
Expand All @@ -37,7 +37,7 @@ class SpinButton extends StatelessWidget {
this.acceleration,
required this.interval,
required this.onStep,
}) : super(key: key);
});

final Icon icon;
final double? iconSize;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/spin_gesture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import 'package:flutter/material.dart';

class SpinGesture extends StatefulWidget {
const SpinGesture({
Key? key,
super.key,
this.enabled = true,
required this.child,
required this.step,
this.acceleration,
required this.interval,
required this.onStep,
}) : super(key: key);
});

final bool enabled;
final Widget child;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ repository: https://github.com/jpnurmi/flutter_spinbox
issue_tracker: https://github.com/jpnurmi/flutter_spinbox/issues

environment:
sdk: ">=2.14.0 <4.0.0"
flutter: ">=3.7.0"
sdk: ">=3.6.0 <4.0.0"
flutter: ">=3.27.0"

dependencies:
cupertino_icons: ^1.0.2
Expand Down
4 changes: 2 additions & 2 deletions test/cupertino_spinbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import 'package:flutter_spinbox/cupertino.dart';
import 'test_spinbox.dart';

class TestApp extends CupertinoApp {
TestApp({Key? key, required Widget widget})
: super(key: key, home: CupertinoPageScaffold(child: widget));
TestApp({super.key, required Widget widget})
: super(home: CupertinoPageScaffold(child: widget));
}

void main() {
Expand Down
14 changes: 7 additions & 7 deletions test/material_spinbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'test_spinbox.dart';

class TestApp extends MaterialApp {
TestApp({Key? key, required Widget widget})
: super(key: key, home: Scaffold(body: widget));
TestApp({super.key, required Widget widget})
: super(home: Scaffold(body: widget));
}

void main() {
Expand Down Expand Up @@ -83,10 +83,10 @@ void main() {
});

group('icon color', () {
final iconColor = MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.disabled)) return Colors.yellow;
if (states.contains(MaterialState.error)) return Colors.red;
if (states.contains(MaterialState.focused)) return Colors.blue;
final iconColor = WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.disabled)) return Colors.yellow;
if (states.contains(WidgetState.error)) return Colors.red;
if (states.contains(WidgetState.focused)) return Colors.blue;
return Colors.green;
});

Expand Down Expand Up @@ -198,7 +198,7 @@ void main() {
TestApp(
widget: SpinBoxTheme(
data: SpinBoxThemeData(
iconColor: MaterialStateProperty.all(Colors.black),
iconColor: WidgetStateProperty.all(Colors.black),
),
child: SpinBox(iconColor: iconColor),
),
Expand Down
8 changes: 4 additions & 4 deletions test/test_spinbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,11 @@ void testCallbacks<S>(TestChangeBuilder builder) {
group('callbacks', () {
late StreamController<double> controller;

setUp(() async {
setUp(() {
controller = StreamController<double>();
});

tearDown(() async {
tearDown(() {
controller.close();
});

Expand Down Expand Up @@ -373,11 +373,11 @@ void testLongPress<S>(TestChangeBuilder builder) {
group('long press', () {
late StreamController<double> controller;

setUp(() async {
setUp(() {
controller = StreamController<double>();
});

tearDown(() async {
tearDown(() {
controller.close();
});

Expand Down
Loading