Comments (2)
Hi @simphotonics π
Thanks for opening an issue!
Can you elaborate on why youβre creating a separate rewind event when you can just call undo on the bloc directly from the widget tree?
from bloc.
Hi @felangel. Thanks for taking the time to have a look.
In the concrete example I am working on the events are AwardPointTeam1
, AwardPointTeam2
, and ReplayLastPoint
:
part of 'score_bloc.dart';
@immutable
sealed class ScoreEvent extends ReplayEvent {
const ScoreEvent();
@override
String toString() => '$runtimeType';
}
@immutable
sealed class AwardPoint extends ScoreEvent {
const AwardPoint();
}
@immutable
class AwardPointTeam1 extends AwardPoint {
const AwardPointTeam1();
}
@immutable
class AwardPointTeam2 extends ScoreEvent {
const AwardPointTeam2();
}
@immutable
class ReplayLastPoint extends ScoreEvent {
const ReplayLastPoint();
}
and the bloc state represents a tennis score:
part of 'score_bloc.dart';
@immutable
final class ScoreState extends Equatable {
const ScoreState({
required this.server,
this.points = const (0, 0),
this.pointsWon = const (0, 0),
this.games = const [(0, 0)],
this.sets = const (0, 0),
this.winner,
});
final (int, int) points;
final (int, int) pointsWon;
final List<(int, int)> games;
final (int, int) sets;
final TeamSelector server;
final TeamSelector? winner;
bool get hasWinner => winner == null ? false : true;
@override
List<Object?> get props => [points, pointsWon, games, sets, winner];
}
During a ReplayLastPoint
event some logic is required to change the scoring method if necessary.
For example at games: 6:0, 6:7, 0:0, and points 0:0 the scoring method is that of a standard tennis game in the third set.
After the event ReplayLastPoint
at score: 6:0, 6:6, and tiebreak points e.g. 8:9, the scoring method has to be changed to that of a set tiebreaker. I placed this logic into onTransition
since it has access to the current and the next state.
@override
void onTransition(covariant Transition<ReplayEvent, ScoreState> transition) {
super.onTransition(transition);
if (transition.event is AwardPoint) {
return;
}
// Set the correct set configuration after an undo.
if (transition.nextState.sets != decidingSetAtScore &&
transition.currentState.sets == decidingSetAtScore) {
_setConfig = matchConfig.setConfig.standard;
}
// Set the correct game configuration after an undo.
_gameConfig =
(transition.nextState.games.last == _setConfig.tiebreakAtScore)
? _setConfig.gameConfig.tiebreak
: _setConfig.gameConfig.standard;
}
from bloc.
Related Issues (20)
- fix: Unable to use bloc consumer and go router together in flutter web, site get redirected to "/" automatically. HOT 2
- Question: Cancel running streams with another event HOT 4
- docs: example output in bloclibrary.dev#error-handling is not correctly HOT 1
- fix: ReorderableListView flickers with Flutter BLoC HOT 1
- AutoFillGroup does not work with flutter bloc HOT 2
- Concurrency Issue with Bloc Events Processing Sequentially when events are Async HOT 4
- fix: Right-click on No bloc related options HOT 6
- Getting Assertion error when emit a state in aysnc function HOT 5
- Question: bug or misuse? HOT 4
- fix: hydrated_bloc is not working like it should HOT 8
- docs: I need help understanding Bloc-to-Bloc Communication HOT 2
- feat(evented_bloc): A new package for Blocs and Cubits with the ability to fire events... HOT 1
- discussion: Implementing Dynamic Bloc Switching HOT 4
- fix: In Flutter v3.16.4 stable the fromJson method stopped working HOT 1
- Flutter Bloc With Alert Dialogs throws an error HOT 4
- why my code will result in error? HOT 2
- BlocBuilder not getting called after creating new task, ListView still displays old data HOT 2
- question: bloc with many datasets HOT 26
- feat: Use with Freezed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bloc.