Skip to content

Commit 5bb1de9

Browse files
committed
Dart 3.7 requirement and formatting.
1 parent d9352e5 commit 5bb1de9

File tree

7 files changed

+210
-152
lines changed

7 files changed

+210
-152
lines changed

CHANGELOG.md

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
# Changelog
22

3-
## 3.5.0 (Unpublished)
3+
## 3.4.0 (Unpublished)
44

5-
* Dart 3.3 requirement.
6-
7-
## 3.4.0
8-
9-
* Dart 3.0 requirement.
5+
* Dart 3.7 requirement.
106

117
## 3.3.0
128

example/tooltip/tooltip.dart

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ import 'package:web/web.dart';
77
/// A pretty HTML tooltip machine.
88
class Tooltip {
99
/// Constructor for tooltip machine.
10-
Tooltip(this.root,
11-
{this.attributeKey = 'data-tooltip',
12-
this.baseCssClass = 'tooltip',
13-
this.visibleCssClass = 'visible',
14-
this.offsetX = 0,
15-
this.offsetY = 0,
16-
Duration delay = const Duration(milliseconds: 500)}) {
10+
Tooltip(
11+
this.root, {
12+
this.attributeKey = 'data-tooltip',
13+
this.baseCssClass = 'tooltip',
14+
this.visibleCssClass = 'visible',
15+
this.offsetX = 0,
16+
this.offsetY = 0,
17+
Duration delay = const Duration(milliseconds: 500),
18+
}) {
1719
tooltip.classList.add(baseCssClass);
1820

1921
final waiting = machine.newState(#waiting);

example/traffic/traffic.dart

+15-19
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ import 'dart:io';
22

33
import 'package:statemachine/statemachine.dart';
44

5-
enum TrafficState {
6-
green,
7-
yellowToRed,
8-
yellowToGreen,
9-
red,
10-
}
5+
enum TrafficState { green, yellowToRed, yellowToGreen, red }
116

127
const ansiReset = '\u001b[0m';
138
const ansiRed = '\u001b[31m';
@@ -18,19 +13,20 @@ void output(String output) {
1813
stdout.write('\r$output$ansiReset');
1914
}
2015

21-
Callback1<String> keyboardDispatcher(Machine<TrafficState> machine,
22-
[TrafficState? state]) =>
23-
(input) {
24-
if (input == ' ') {
25-
if (state != null) {
26-
machine.current = state;
27-
}
28-
} else if (input == 'q') {
29-
stdin.echoMode = true;
30-
stdin.lineMode = true;
31-
exit(0);
32-
}
33-
};
16+
Callback1<String> keyboardDispatcher(
17+
Machine<TrafficState> machine, [
18+
TrafficState? state,
19+
]) => (input) {
20+
if (input == ' ') {
21+
if (state != null) {
22+
machine.current = state;
23+
}
24+
} else if (input == 'q') {
25+
stdin.echoMode = true;
26+
stdin.lineMode = true;
27+
exit(0);
28+
}
29+
};
3430

3531
void main() {
3632
// Require stdout to be connected to terminal.

lib/src/machine.dart

+21-12
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ class Machine<T> {
4141
State<T> newState(T identifier) {
4242
if (_states.containsKey(identifier)) {
4343
throw ArgumentError.value(
44-
identifier, 'identifier', 'Duplicated state identifier');
44+
identifier,
45+
'identifier',
46+
'Duplicated state identifier',
47+
);
4548
}
4649
final state = createState(identifier);
4750
_states[identifier] = state;
@@ -59,10 +62,14 @@ class Machine<T> {
5962
Iterable<State<T>> get states => _states.values;
6063

6164
/// Returns the state of the provided identifier.
62-
State<T> operator [](T identifier) => _states.containsKey(identifier)
63-
? _states[identifier]!
64-
: throw ArgumentError.value(
65-
identifier, 'identifier', 'Unknown identifier');
65+
State<T> operator [](T identifier) =>
66+
_states.containsKey(identifier)
67+
? _states[identifier]!
68+
: throw ArgumentError.value(
69+
identifier,
70+
'identifier',
71+
'Unknown identifier',
72+
);
6673

6774
/// Returns an event stream that is triggered before each transition.
6875
Stream<BeforeTransitionEvent<T>> get onBeforeTransition =>
@@ -91,13 +98,14 @@ class Machine<T> {
9198
/// a single [TransitionError] is rethrown at the end of the state change.
9299
set current(/*State<T>|T|Null*/ Object? state) {
93100
// Find and validate the target state.
94-
final target = state is State<T>
95-
? state
96-
: state is T
101+
final target =
102+
state is State<T>
103+
? state
104+
: state is T
97105
? this[state]
98106
: state == null
99-
? null
100-
: throw ArgumentError.value(state, 'state', 'Invalid state');
107+
? null
108+
: throw ArgumentError.value(state, 'state', 'Invalid state');
101109
if (target != null && target.machine != this) {
102110
throw ArgumentError.value(state, 'state', 'Invalid machine');
103111
}
@@ -136,8 +144,9 @@ class Machine<T> {
136144
}
137145
// Notify listeners about the completed transition.
138146
if (_afterTransitionController.hasListener) {
139-
_afterTransitionController
140-
.add(AfterTransitionEvent<T>(this, source, target, errors));
147+
_afterTransitionController.add(
148+
AfterTransitionEvent<T>(this, source, target, errors),
149+
);
141150
}
142151
// Rethrow any remaining transition errors at the end.
143152
if (errors.isNotEmpty) {

lib/src/state.dart

+6-4
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,9 @@ class State<T> {
4545
/// Triggers the [callback] when the [Stream] provided by [provider] triggers
4646
/// an event.
4747
void onStreamProvider<S>(
48-
Provider<Stream<S>> provider, Callback1<S> callback) =>
49-
addTransition(StreamTransition<S>(provider, callback));
48+
Provider<Stream<S>> provider,
49+
Callback1<S> callback,
50+
) => addTransition(StreamTransition<S>(provider, callback));
5051

5152
/// Triggers the [callback] when a [future] yields a value.
5253
void onFuture<S>(Future<S> future, Callback1<S> callback) =>
@@ -55,8 +56,9 @@ class State<T> {
5556
/// Triggers the [callback] when the [Future] provided by [provider] yields a
5657
/// value.
5758
void onFutureProvider<S>(
58-
Provider<Future<S>> provider, Callback1<S> callback) =>
59-
addTransition(FutureTransition<S>(provider, callback));
59+
Provider<Future<S>> provider,
60+
Callback1<S> callback,
61+
) => addTransition(FutureTransition<S>(provider, callback));
6062

6163
/// Triggers the [callback] when [duration] elapses.
6264
void onTimeout(Duration duration, Callback0 callback) =>

pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: statemachine
2-
version: 3.3.1
2+
version: 3.4.0
33

44
homepage: https://github.com/renggli/dart-statemachine
55
description: A simple, yet powerful state machine framework for Dart supporting
@@ -11,7 +11,7 @@ topics:
1111
- streams
1212

1313
environment:
14-
sdk: ^3.5.0
14+
sdk: ^3.7.0
1515
dependencies:
1616
meta: ^1.16.0
1717
dev_dependencies:

0 commit comments

Comments
 (0)