Skip to content

fix(Flavors Field): Fixed bug with multi spacing.Add TextInputFormatter #66

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,111 +26,139 @@ class ProjectSettingsScreenBloc extends BaseBloc<ProjectSettingsScreenEvent,
on<ProjectSettingsScreenEventFirebaseChange>(_onFirebaseChange);
}

FutureOr<void> _onInit(
void _onInit(
ProjectSettingsScreenEventInit event,
Emitter<ProjectSettingsScreenState> emit,
) {
emit(state.copyWith(
config: event.config,
));
emit(
state.copyWith(
config: event.config,
),
);
}

FutureOr<void> _onFlavorizeChange(
void _onFlavorizeChange(
ProjectSettingsScreenEventFlavorizeChange event,
Emitter<ProjectSettingsScreenState> emit,
) {
emit(state.copyWith(
config: state.config.copyWith(flavorize: !state.config.flavorize)));
emit(
state.copyWith(
config: state.config.copyWith(flavorize: !state.config.flavorize),
),
);
}

FutureOr<void> _onFlavorsChange(
void _onFlavorsChange(
ProjectSettingsScreenEventFlavorsChange event,
Emitter<ProjectSettingsScreenState> emit,
) {
emit(state.copyWith(config: state.config.copyWith(flavors: event.flavors)));
emit(
state.copyWith(
config: state.config.copyWith(
flavors: event.flavors.trim(),
),
),
);
}

FutureOr<void> _onGenerateSigningKeyChange(
void _onGenerateSigningKeyChange(
ProjectSettingsScreenEventGenerateSigningKeyChange event,
Emitter<ProjectSettingsScreenState> emit,
) {
emit(state.copyWith(
emit(
state.copyWith(
config: state.config
.copyWith(generateSigningKey: !state.config.generateSigningKey)));
.copyWith(generateSigningKey: !state.config.generateSigningKey),
),
);
}

FutureOr<void> _onSigningVarsChange(
void _onSigningVarsChange(
ProjectSettingsScreenEventSigningVarsChange event,
Emitter<ProjectSettingsScreenState> emit,
) {
emit(state.copyWith(
config: state.config.copyWith(signingVars: event.signingVars)));
emit(
state.copyWith(
config: state.config.copyWith(signingVars: event.signingVars),
),
);
}

FutureOr<void> _onUseSonarChange(
void _onUseSonarChange(
ProjectSettingsScreenEventUseSonarChange event,
Emitter<ProjectSettingsScreenState> emit,
) {
emit(state.copyWith(
config: state.config.copyWith(useSonar: !state.config.useSonar)));
emit(
state.copyWith(
config: state.config.copyWith(useSonar: !state.config.useSonar),
),
);
}

FutureOr<void> _onGraphQLChange(
void _onGraphQLChange(
ProjectSettingsScreenEventGraphQLChange event,
Emitter<ProjectSettingsScreenState> emit,
) {
emit(state.copyWith(
config: state.config.copyWith(graphql: !state.config.graphql)));
emit(
state.copyWith(
config: state.config.copyWith(graphql: !state.config.graphql),
),
);
}

FutureOr<void> _onRouterChange(
void _onRouterChange(
ProjectSettingsScreenEventRouterChange event,
Emitter<ProjectSettingsScreenState> emit,
) {
emit(
state.copyWith(
config: state.config.copyWith(
router: state.config.router == ProjectRouter.goRouter
? ProjectRouter.autoRouter
: ProjectRouter.goRouter),
router: state.config.router == ProjectRouter.goRouter
? ProjectRouter.autoRouter
: ProjectRouter.goRouter,
),
),
);
}

FutureOr<void> _onLocalizationChange(
void _onLocalizationChange(
ProjectSettingsScreenEventLocalizationChange event,
Emitter<ProjectSettingsScreenState> emit,
) {
emit(
state.copyWith(
config: state.config.copyWith(
localization: state.config.localization == ProjectLocalization.intl
? ProjectLocalization.flutterGen
: ProjectLocalization.intl),
localization: state.config.localization == ProjectLocalization.intl
? ProjectLocalization.flutterGen
: ProjectLocalization.intl,
),
),
);
}

FutureOr<void> _onThemingChange(
void _onThemingChange(
ProjectSettingsScreenEventThemingChange event,
Emitter<ProjectSettingsScreenState> emit,
) {
emit(
state.copyWith(
config: state.config.copyWith(
theming: state.config.theming == ProjectTheming.themeTailor
? ProjectTheming.manual
: ProjectTheming.themeTailor),
theming: state.config.theming == ProjectTheming.themeTailor
? ProjectTheming.manual
: ProjectTheming.themeTailor,
),
),
);
}

FutureOr<void> _onFirebaseChange(
void _onFirebaseChange(
ProjectSettingsScreenEventFirebaseChange event,
Emitter<ProjectSettingsScreenState> emit,
) {
emit(state.copyWith(
config:
state.config.copyWith(firebaseAuth: !state.config.firebaseAuth)));
emit(
state.copyWith(
config: state.config.copyWith(firebaseAuth: !state.config.firebaseAuth),
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'package:onix_flutter_bricks/presentation/widget/inputs/text_field_with_l
import 'package:onix_flutter_bricks/util/enum/project_localization.dart';
import 'package:onix_flutter_bricks/util/enum/project_router.dart';
import 'package:onix_flutter_bricks/util/enum/project_theming.dart';
import 'package:onix_flutter_bricks/util/extra_space_formatter.dart';

class ProjectSettingsScreen extends StatefulWidget {
final Config config;
Expand Down Expand Up @@ -108,7 +109,9 @@ class _ProjectSettingsScreenState extends BaseState<ProjectSettingsScreenState,
textController: _flavorsController,
inputFormatters: [
FilteringTextInputFormatter.allow(
RegExp(r'[a-zA-Z ]')),
RegExp(r'[a-zA-Z\s]', unicode: true),
),
ExtraSpaceFormatter(),
],
onChanged: () => blocOf(context)
.add(ProjectSettingsScreenEventFlavorsChange(
Expand Down
20 changes: 20 additions & 0 deletions lib/util/extra_space_formatter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'package:flutter/services.dart';

class ExtraSpaceFormatter extends TextInputFormatter {
@override
TextEditingValue formatEditUpdate(
TextEditingValue oldValue,
TextEditingValue newValue,
) {
if (newValue.text.startsWith(RegExp(r'\s', unicode: true))) {
return oldValue;
}

final correctedText = newValue.text.replaceAll(RegExp(r'\s+'), ' ');

return TextEditingValue(
text: correctedText,
selection: TextSelection.collapsed(offset: correctedText.length),
);
}
}