Skip to content

Conversation

@waseemdev
Copy link

Hi,
Here are two commits:

  1. I made Autocompleter abstract class and renamed default one to DefaultAutocompleter, so user can create its own implementation

    • also created SuggestionItem to be more customizable than just String, in some cases the displayed text in the popup list can be different than the actual code.
  2. made the popup list customizable so user can use his own widget using autocompleteListBuilder.

    • also moved these variables (caretPadding, autocompletePopupMaxHeight, autocompletePopupMaxWidth) to be fields in CodeEditor widget

@nausharipov
Copy link
Collaborator

@waseemdev hello, thank you. I just started allocating time on reviews for this project. I can't resolve conflicts in your forked branch. Can you do it?

Comment on lines +5 to +6
Mode? mode;
List<String> blacklist = [];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autocompleter.dart declares concrete fields instead of abstract accessors
Problem: Autocompleter currently has

Mode? mode;
List blacklist = []; DefaultAutocompleter implements getters/setters for mode and blacklist (and uses @OverRide). You cannot override a concrete field with getters/setters — this causes analyzer/compile errors.
Fix: make those members abstract (declare getters/setters) in Autocompleter. Example replacement:

Mode? get mode; set mode(Mode? value);

List get blacklist; set blacklist(List value);

(Keep the other abstract methods: setText, getSuggestionItems, replaceText.)

Example:

import 'package:flutter/material.dart'; import 'package:highlight/highlight_core.dart';

abstract class Autocompleter { Autocompleter();

// Language mode used to extract keywords from highlight Mode Mode? get mode; set mode(Mode? value);

// Words to exclude from suggestions List<String> get blacklist; set blacklist(List<String> value);

/// Sets the [text] to parse all words from. /// Multiple texts are supported, each with its own [key]. /// Use this to set current texts from multiple controllers. void setText(Object key, String? text);

/// Returns items ready to be shown in popup based on current editing value Future<List<SuggestionItem>> getSuggestionItems(TextEditingValue value);

/// Replace selection/value using picked suggestion item. /// Returns a new TextEditingValue to assign to controller.value, or null if nothing changed. TextEditingValue? replaceText( TextSelection selection, TextEditingValue value, SuggestionItem item, ); }

class SuggestionItem { final String text; final String displayText; final dynamic data;

@@ -0,0 +1,210 @@
import 'package:autotrie/autotrie.dart';
import 'package:flutter/material.dart';
import 'package:highlight/highlight_core.dart';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Autocompleter imports package:highlight/highlight.dart while DefaultAutocompleter imports package:highlight/highlight_core.dart. Choose the correct import that exposes Mode (typically highlight_core.dart) and use it in autocompleter.dart so Mode is known.

.toList();
}

Future<List<String>> getSuggestions(String prefix) async {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decide whether getSuggestions(String) should be part of the Autocompleter interface (currently only DefaultAutocompleter exposes it; CodeController uses getSuggestionItems, so this is optional).

@@ -1,133 +1,29 @@
import 'package:autotrie/autotrie.dart';
import 'package:highlight/highlight_core.dart';
import 'package:flutter/material.dart';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since autocompleter.dart is a non-UI, library-level file (it only needs the types, not Material widgets), prefer the smaller import for TextEditingValue and TextSelection to avoid pulling Material into a low-level lib file: import 'package:flutter/services.dart';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants