Создайте текстовое поле с различным форматированием и несколькими предложениями - PullRequest
0 голосов
/ 02 июня 2019

Я хочу эмулировать функцию тега Facebook / Twitter в моем приложении. Я использую flutter_typeahead в качестве плагина, но мне трудно отделить выбранные предложения от текста и различного форматирования в TextField.

Я не уверен, как: - разрешить пользователю продолжать печатать после выбора предложения - если пользователь удаляет только часть предложения, удалите все это (а-ля тег Facebook) - сохранить форму как текст + выделенные @ теги

Widget _buildAtalakuRecipientsField(String sField, Atalaku atalaku) {
    return ScopedModelDescendant<MainModel>(
      builder: (BuildContext context, Widget child, MainModel model) {
        return EnsureVisibleWhenFocused(
          focusNode: _recipientsFocusNode,
          child: TypeAheadField(
            textFieldConfiguration: TextFieldConfiguration(
              focusNode: _recipientsFocusNode,
              autofocus: true, //to change maybe
              controller: _typeAheadController,
              decoration: InputDecoration(
                labelText: sField,
                prefixIcon: Icon(Icons.people),
              ),
              onSubmitted: (value) {
                _typeAheadController.text = value;
                _formData['recipients'] = List<Map<String, dynamic>>.from([
                  {'recipient': value}
                ]);
              },
              //onEditingComplete:
            ),
            suggestionsCallback: (value) async {
              if (value != null && value != '') {
                if (value.startsWith('@') && value.length >= 3)
                  return await model.getProfilesBySuggestion(value);
                else
                  return [];
              } else
                return [];
            },
            itemBuilder: (context, suggestion) {
              return SingleChildScrollView(
                child: ListTile(
                  leading: CircleAvatar(
                    backgroundImage: (suggestion['photoURL'] != null &&
                            suggestion['photoURL'] != '')
                        ? NetworkImage(suggestion['photoURL'])
                        : AssetImage('assets/images/profile_placeholder.png'),
                    radius: 20,
                  ),
                  title: Text(suggestion['name']),
                ),
              );
            },
            onSuggestionSelected: (suggestion) {
              //set the full name as part of the field, add a coma and allow the user to select another recipient
              _typeAheadController.text = suggestion['name'];
              _formData['recipients'] =
                  List<Map<String, dynamic>>.from([suggestion]);
            },
            noItemsFoundBuilder: (BuildContext context) =>
                Container(height: 0, width: 0),
            transitionBuilder: (context, suggestionsBox, controller) {
              return suggestionsBox;
            },
            /* loadingBuilder: (BuildContext context) {
              return CircularProgressIndicator();
            }, */
            //onSa
          ),
        );
      },
    );
  }

Точно а-ля Фейсбук. Отметьте один или несколько в сообщении и сохраните их в бэкэнде, чтобы они могли получать уведомления:

введите описание изображения здесь

...