mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-24 04:59:26 +01:00
fix: Multiline keyboard on web and desktop
This commit is contained in:
parent
e300048d3b
commit
f9bec90f3d
@ -668,11 +668,9 @@ class ChatView extends StatelessWidget {
|
|||||||
child: InputBar(
|
child: InputBar(
|
||||||
room: controller.room,
|
room: controller.room,
|
||||||
minLines: 1,
|
minLines: 1,
|
||||||
maxLines: kIsWeb ? 1 : 8,
|
maxLines: 8,
|
||||||
autofocus: !PlatformInfos.isMobile,
|
autofocus: !PlatformInfos.isMobile,
|
||||||
keyboardType: !PlatformInfos.isMobile
|
keyboardType: TextInputType.multiline,
|
||||||
? TextInputType.text
|
|
||||||
: TextInputType.multiline,
|
|
||||||
onSubmitted:
|
onSubmitted:
|
||||||
controller.onInputBarSubmitted,
|
controller.onInputBarSubmitted,
|
||||||
focusNode: controller.inputFocus,
|
focusNode: controller.inputFocus,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:famedlysdk/famedlysdk.dart';
|
import 'package:famedlysdk/famedlysdk.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
import 'package:flutter_typeahead/flutter_typeahead.dart';
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'avatar.dart';
|
import 'avatar.dart';
|
||||||
@ -263,43 +264,81 @@ class InputBar extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return TypeAheadField<Map<String, String>>(
|
return Shortcuts(
|
||||||
direction: AxisDirection.up,
|
shortcuts: {
|
||||||
hideOnEmpty: true,
|
LogicalKeySet(LogicalKeyboardKey.shift, LogicalKeyboardKey.enter):
|
||||||
hideOnLoading: true,
|
NewLineIntent(),
|
||||||
keepSuggestionsOnSuggestionSelected: true,
|
LogicalKeySet(LogicalKeyboardKey.enter): SubmitLineIntent(),
|
||||||
debounceDuration: Duration(
|
},
|
||||||
milliseconds:
|
child: Actions(
|
||||||
50), // show suggestions after 50ms idle time (default is 300)
|
actions: {
|
||||||
textFieldConfiguration: TextFieldConfiguration(
|
NewLineIntent: CallbackAction(onInvoke: (i) {
|
||||||
minLines: minLines,
|
final val = controller.value;
|
||||||
maxLines: maxLines,
|
final selection = val.selection.start;
|
||||||
keyboardType: keyboardType,
|
final messageWithoutNewLine =
|
||||||
autofocus: autofocus,
|
controller.text.substring(0, val.selection.start) +
|
||||||
onSubmitted: (text) {
|
'\n' +
|
||||||
// fix for library for now
|
controller.text.substring(val.selection.start);
|
||||||
// it sets the types for the callback incorrectly
|
controller.value = TextEditingValue(
|
||||||
onSubmitted(text);
|
text: messageWithoutNewLine,
|
||||||
|
selection: TextSelection.fromPosition(
|
||||||
|
TextPosition(offset: selection + 1),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}),
|
||||||
|
SubmitLineIntent: CallbackAction(onInvoke: (i) {
|
||||||
|
if (PlatformInfos.kIsWeb || PlatformInfos.isDesktop){
|
||||||
|
onSubmitted(controller.text);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
focusNode: focusNode,
|
child: TypeAheadField<Map<String, String>>(
|
||||||
controller: controller,
|
direction: AxisDirection.up,
|
||||||
decoration: decoration,
|
hideOnEmpty: true,
|
||||||
onChanged: (text) {
|
hideOnLoading: true,
|
||||||
// fix for the library for now
|
keepSuggestionsOnSuggestionSelected: true,
|
||||||
// it sets the types for the callback incorrectly
|
debounceDuration: Duration(
|
||||||
onChanged(text);
|
milliseconds:
|
||||||
},
|
50), // show suggestions after 50ms idle time (default is 300)
|
||||||
textCapitalization: TextCapitalization.sentences,
|
textFieldConfiguration: TextFieldConfiguration(
|
||||||
|
minLines: minLines,
|
||||||
|
maxLines: maxLines,
|
||||||
|
keyboardType: keyboardType,
|
||||||
|
autofocus: autofocus,
|
||||||
|
onSubmitted: (text) {
|
||||||
|
// fix for library for now
|
||||||
|
// it sets the types for the callback incorrectly
|
||||||
|
onSubmitted(text);
|
||||||
|
},
|
||||||
|
//focusNode: focusNode,
|
||||||
|
controller: controller,
|
||||||
|
decoration: decoration,
|
||||||
|
focusNode: focusNode,
|
||||||
|
onChanged: (text) {
|
||||||
|
// fix for the library for now
|
||||||
|
// it sets the types for the callback incorrectly
|
||||||
|
onChanged(text);
|
||||||
|
},
|
||||||
|
textCapitalization: TextCapitalization.sentences,
|
||||||
|
),
|
||||||
|
suggestionsCallback: getSuggestions,
|
||||||
|
itemBuilder: (c, s) =>
|
||||||
|
buildSuggestion(c, s, Matrix.of(context).client),
|
||||||
|
onSuggestionSelected: (Map<String, String> suggestion) =>
|
||||||
|
insertSuggestion(context, suggestion),
|
||||||
|
errorBuilder: (BuildContext context, Object error) => Container(),
|
||||||
|
loadingBuilder: (BuildContext context) =>
|
||||||
|
Container(), // fix loading briefly flickering a dark box
|
||||||
|
noItemsFoundBuilder: (BuildContext context) =>
|
||||||
|
Container(), // fix loading briefly showing no suggestions
|
||||||
|
),
|
||||||
),
|
),
|
||||||
suggestionsCallback: getSuggestions,
|
|
||||||
itemBuilder: (c, s) => buildSuggestion(c, s, Matrix.of(context).client),
|
|
||||||
onSuggestionSelected: (Map<String, String> suggestion) =>
|
|
||||||
insertSuggestion(context, suggestion),
|
|
||||||
errorBuilder: (BuildContext context, Object error) => Container(),
|
|
||||||
loadingBuilder: (BuildContext context) =>
|
|
||||||
Container(), // fix loading briefly flickering a dark box
|
|
||||||
noItemsFoundBuilder: (BuildContext context) =>
|
|
||||||
Container(), // fix loading briefly showing no suggestions
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class NewLineIntent extends Intent {}
|
||||||
|
|
||||||
|
class SubmitLineIntent extends Intent {}
|
||||||
|
Loading…
Reference in New Issue
Block a user