Skip to content

Commit

Permalink
Cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hecatoncheir committed May 30, 2022
1 parent cb61c3f commit 257a1ae
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 199 deletions.
2 changes: 2 additions & 0 deletions lib/bloc/group_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ class GroupField {
final String text;
final Group group;
final Widget widget;

// ignore: no-object-declaration
final Object field;

GroupField({
Expand Down
58 changes: 25 additions & 33 deletions lib/bloc/groups_field_bloc.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore_for_file: no-magic-number

import 'dart:async';

import 'package:pedantic/pedantic.dart';
Expand All @@ -6,7 +8,7 @@ import 'package:flutter/widgets.dart';

import 'package:groups_field/group.dart';

part 'interface.dart';
part 'groups_field_bloc_interface.dart';
part 'group_field.dart';
part 'groups_field_event.dart';
part 'groups_field_state.dart';
Expand All @@ -26,7 +28,7 @@ class GroupsFieldBloc implements GroupsFieldBlocInterface {
@visibleForTesting
List<GroupField> fields;

String _textFieldValue;
String textFieldValue;

late final StreamController<GroupsFieldState> stateController;

Expand All @@ -43,8 +45,8 @@ class GroupsFieldBloc implements GroupsFieldBlocInterface {
required this.delimiters,
required this.isFieldCanBeDeleted,
this.isScrollable = false,
}) : fields = <GroupField>[],
_textFieldValue = "" {
this.textFieldValue = "",
}) : fields = <GroupField>[] {
stateController = StreamController<GroupsFieldState>();
stateStream =
stateController.stream.asBroadcastStream().asBroadcastStream();
Expand All @@ -71,7 +73,7 @@ class GroupsFieldBloc implements GroupsFieldBlocInterface {

@visibleForTesting
Future<void> prepareExistedGroupsFieldsWidgets(
PrepareExistedGroupsFieldsWidgets event,
PrepareExistedGroupsFieldsWidgets _,
) async {
fields = prepareExistedGroupsFields(groups: groups);
final widgets = fields.map((field) => field.widget).toList();
Expand Down Expand Up @@ -110,15 +112,9 @@ class GroupsFieldBloc implements GroupsFieldBlocInterface {
isScrollable: isScrollable,
);

Size fieldsSize;
if (isScrollable) {
fieldsSize = event.parentLayoutElement.size;
} else {
fieldsSize = Size(
cursorPosition.dx,
event.parentLayoutElement.size.height,
);
}
final fieldsSize = isScrollable
? event.parentLayoutElement.size
: Size(cursorPosition.dx, event.parentLayoutElement.size.height);

final lastChildElement = event.lastChildElement;
final lastFieldSize =
Expand Down Expand Up @@ -192,7 +188,7 @@ class GroupsFieldBloc implements GroupsFieldBlocInterface {
}
}

final previousTextFieldValue = _textFieldValue;
final previousTextFieldValue = textFieldValue;

/// latest field must be removed.
if (event.isRemovedFieldKeyPressed &&
Expand Down Expand Up @@ -221,7 +217,7 @@ class GroupsFieldBloc implements GroupsFieldBlocInterface {

stateController.add(state);

_textFieldValue = event.textFieldValue;
textFieldValue = event.textFieldValue;
} else {
// Check is new text must be a field.

Expand Down Expand Up @@ -260,9 +256,9 @@ class GroupsFieldBloc implements GroupsFieldBlocInterface {

stateController.add(state);

_textFieldValue = "";
textFieldValue = "";
} else {
_textFieldValue = event.textFieldValue;
textFieldValue = event.textFieldValue;
}
}
}
Expand Down Expand Up @@ -416,21 +412,17 @@ class GroupsFieldBloc implements GroupsFieldBlocInterface {
Offset cursorPosition;

if (isScrollable) {
if (parentElement == null) {
cursorPosition = const Offset(0, 0);
} else {
if (parentElement.size.width < parentLayoutElement.size.width) {
cursorPosition = Offset(
parentElement.size.width,
parentElement.size.height / 2,
);
} else {
cursorPosition = Offset(
parentLayoutElement.size.width,
parentLayoutElement.size.height / 2,
);
}
}
cursorPosition = parentElement == null
? const Offset(0, 0)
: parentElement.size.width < parentLayoutElement.size.width
? Offset(
parentElement.size.width,
parentElement.size.height / 2,
)
: Offset(
parentLayoutElement.size.width,
parentLayoutElement.size.height / 2,
);
} else {
Offset offset;

Expand Down
2 changes: 2 additions & 0 deletions lib/bloc/groups_field_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class TextFieldChanged extends GroupsFieldEvent {

class SuggestionSelected extends GroupsFieldEvent {
final Group group;

// ignore: no-object-declaration
final Object suggestion;

SuggestionSelected({
Expand Down
8 changes: 8 additions & 0 deletions lib/bloc/groups_field_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ class GroupFieldRemove extends GroupsFieldState {
final List<Widget> widgets;
final String removedFieldText;

// ignore: no-object-declaration
final Object removedField;

final Group removedFieldGroup;

GroupFieldRemove({
Expand All @@ -52,7 +54,10 @@ class NewFieldAdd extends GroupsFieldState {
final String newFieldText;

final Widget addedFieldWidget;

// ignore: no-object-declaration
final Object addedField;

final Group addedFieldGroup;

NewFieldAdd({
Expand Down Expand Up @@ -82,7 +87,10 @@ class SuggestionsReady extends GroupsFieldState {
class SuggestionSelect extends GroupsFieldState {
/// widgets - already build fields in groups.
final List<Widget> widgets;

// ignore: no-object-declaration
final Object field;

final Group group;
final String text;

Expand Down
Loading

0 comments on commit 257a1ae

Please sign in to comment.