Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a bloc to validate the tier list name
- Loading branch information
Showing
7 changed files
with
97 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:bloc/bloc.dart'; | ||
import 'package:freezed_annotation/freezed_annotation.dart'; | ||
import 'package:genshindb/domain/extensions/string_extensions.dart'; | ||
import 'package:meta/meta.dart'; | ||
|
||
part 'tier_list_form_bloc.freezed.dart'; | ||
part 'tier_list_form_event.dart'; | ||
part 'tier_list_form_state.dart'; | ||
|
||
const _initialState = TierListFormState.loaded(name: '', isNameDirty: false, isNameValid: false); | ||
|
||
class TierListFormBloc extends Bloc<TierListFormEvent, TierListFormState> { | ||
TierListFormBloc() : super(_initialState); | ||
|
||
static int nameMaxLength = 25; | ||
|
||
@override | ||
Stream<TierListFormState> mapEventToState(TierListFormEvent event) async* { | ||
final s = event.map( | ||
nameChanged: (e) { | ||
final isValid = e.name.isNotNullEmptyOrWhitespace && e.name.length <= nameMaxLength; | ||
final isDirty = e.name != state.name; | ||
|
||
return state.copyWith.call(name: e.name, isNameDirty: isDirty, isNameValid: isValid); | ||
}, | ||
close: (_) => _initialState, | ||
); | ||
|
||
yield s; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
part of 'tier_list_form_bloc.dart'; | ||
|
||
@freezed | ||
abstract class TierListFormEvent implements _$TierListFormEvent { | ||
const factory TierListFormEvent.nameChanged({ | ||
@required String name, | ||
}) = _NameChanged; | ||
|
||
const factory TierListFormEvent.close() = _Close; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
part of 'tier_list_form_bloc.dart'; | ||
|
||
@freezed | ||
abstract class TierListFormState implements _$TierListFormState { | ||
const factory TierListFormState.loaded({ | ||
@required String name, | ||
@required bool isNameDirty, | ||
@required bool isNameValid, | ||
}) = _LoadedState; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters