Skip to content
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

fix: suggestions box now visible in WEB #1

Open
wants to merge 4 commits into
base: fix_ios_focus_issue
Choose a base branch
from
Open
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
3 changes: 1 addition & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_chips_input/flutter_chips_input.dart';

void main() => runApp(MyApp());
Expand Down Expand Up @@ -199,7 +198,7 @@ class _MyHomePageState extends State<MyHomePage> {
);
},
),*/
RaisedButton(
ElevatedButton(
child: Text('Add Chip'),
onPressed: () {
_chipKey.currentState.selectSuggestion(AppProfile(
Expand Down
48 changes: 40 additions & 8 deletions lib/src/chips_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:flutter/foundation.dart';
import 'suggestions_box_controller.dart';
import 'text_cursor.dart';

Expand Down Expand Up @@ -133,7 +133,7 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
_focusNode.addListener(_handleFocusChanged);
_nodeAttachment = _focusNode.attach(context);

WidgetsBinding.instance?.addPostFrameCallback((_) async {
WidgetsBinding.instance.addPostFrameCallback((_) async {
_initOverlayEntry();
if (mounted && widget.autofocus) {
FocusScope.of(context).autofocus(_focusNode);
Expand Down Expand Up @@ -292,9 +292,9 @@ class ChipsInputState<T> extends State<ChipsInput<T>>

void _scrollToVisible() {
Future.delayed(const Duration(milliseconds: 300), () {
WidgetsBinding.instance?.addPostFrameCallback((_) async {
WidgetsBinding.instance.addPostFrameCallback((_) async {
final renderBox = context.findRenderObject() as RenderBox;
await Scrollable.of(context)?.position.ensureVisible(renderBox);
await Scrollable.of(context).position.ensureVisible(renderBox);
});
});
}
Expand Down Expand Up @@ -337,6 +337,9 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
}
_updateTextInputState(putText: putText);
} else {
if (kIsWeb) {
_onSearchChanged(_value.normalCharactersText);
}
_updateTextInputState();
}
_onSearchChanged(_value.normalCharactersText);
Expand All @@ -349,12 +352,12 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
"${replaceText ? '' : _value.normalCharactersText}" +
putText;
setState(() {
final textLength = updatedText.characters.length;
final textLength = updatedText.length;
final replacedLength = _chips.length;
_value = _value.copyWith(
text: updatedText,
selection: TextSelection.collapsed(offset: textLength),
composing: (Platform.isIOS || replacedLength == textLength)
composing: (!kIsWeb && Platform.isIOS || replacedLength == textLength)
? TextRange.empty
: TextRange(
start: replacedLength,
Expand Down Expand Up @@ -438,7 +441,7 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
maxLines: 1,
overflow: widget.textOverflow,
style: widget.textStyle ??
theme.textTheme.subtitle1?.copyWith(height: 1.5),
theme.textTheme.titleMedium?.copyWith(height: 1.5),
),
),
Flexible(
Expand All @@ -452,7 +455,7 @@ class ChipsInputState<T> extends State<ChipsInput<T>>

return NotificationListener<SizeChangedLayoutNotification>(
onNotification: (SizeChangedLayoutNotification val) {
WidgetsBinding.instance?.addPostFrameCallback((_) async {
WidgetsBinding.instance.addPostFrameCallback((_) async {
_suggestionsBoxController.overlayEntry?.markNeedsBuild();
});
return true;
Expand Down Expand Up @@ -486,4 +489,33 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
),
);
}

@override
void insertTextPlaceholder(Size size) {
// TODO: implement insertTextPlaceholder
}

@override
void removeTextPlaceholder() {
// TODO: implement removeTextPlaceholder
}

@override
void showToolbar() {
// TODO: implement showToolbar
}

@override
void didChangeInputControl(
TextInputControl? oldControl, TextInputControl? newControl) {}

@override
void performSelector(String selectorName) {
// TODO: implement performSelector
}

@override
void insertContent(KeyboardInsertedContent content) {
// TODO: implement insertContent
}
}
2 changes: 1 addition & 1 deletion lib/src/suggestions_box_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SuggestionsBoxController {
void open() {
if (_isOpened) return;
assert(overlayEntry != null);
Overlay.of(context)?.insert(overlayEntry!);
Overlay.of(context).insert(overlayEntry!);
_isOpened = true;
}

Expand Down