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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document public members, where it is necessary #13

Merged
merged 5 commits into from
Apr 25, 2023
Merged
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: 3 additions & 0 deletions lib/domain/language_check_service.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import 'package:languagetool_textfield/domain/mistake.dart';

/// A base language check service.
abstract class LanguageCheckService {
/// Creates a new instance of the [LanguageCheckService] class.
const LanguageCheckService();

/// Returns found mistakes in the given [text].
Future<List<Mistake>> findMistakes(String text);
}
13 changes: 13 additions & 0 deletions lib/domain/mistake.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
/// A data model class that stores information about a single writing mistake.
class Mistake {
/// A brief description of the mistake.
final String message;

/// A type of this mistake.
final String type;

/// A position of the beginning of this mistake.
final int offset;

/// A length of this mistake after the offset.
final int length;

/// A list of suggestions for replacing this mistake.
///
/// Sorted by probability.
final List<String> replacements;

/// Creates a new instance of the [Mistake] class.
const Mistake({
required this.message,
required this.type,
Expand Down
5 changes: 5 additions & 0 deletions lib/implementations/debounce_lang_tool_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import 'package:languagetool_textfield/domain/language_check_service.dart';
import 'package:languagetool_textfield/domain/mistake.dart';
import 'package:throttling/throttling.dart';

/// A language check service with debouncing.
class DebounceLangToolService extends LanguageCheckService {
/// A base language check service.
final LanguageCheckService baseService;

/// A debouncing used to debounce the API calls.
final Debouncing debouncing;

/// Creates a new instance of the [DebounceLangToolService] class.
DebounceLangToolService(
this.baseService,
Duration debouncingDuration,
Expand Down
3 changes: 3 additions & 0 deletions lib/implementations/lang_tool_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import 'package:language_tool/language_tool.dart';
import 'package:languagetool_textfield/domain/language_check_service.dart';
import 'package:languagetool_textfield/domain/mistake.dart';

/// An implementation of language check service with language tool service.
class LangToolService extends LanguageCheckService {
/// An instance of this class that is used to interact with LanguageTool API.
final LanguageTool languageTool;

/// Creates a new instance of the [LangToolService].
const LangToolService(this.languageTool);

@override
Expand Down
6 changes: 6 additions & 0 deletions lib/implementations/throttling_lang_tool_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import 'package:languagetool_textfield/domain/language_check_service.dart';
import 'package:languagetool_textfield/domain/mistake.dart';
import 'package:throttling/throttling.dart';

/// A language check service with debouncing.
class ThrottlingLangToolService extends LanguageCheckService {
/// A base language check service that is used to interact
/// with the language check API.
final LanguageCheckService baseService;

/// A throttling used to throttle the API calls.
final Throttling throttling;

/// Creates a new instance of the [ThrottlingLangToolService] class.
ThrottlingLangToolService(
this.baseService,
Duration throttlingDuration,
Expand Down
10 changes: 9 additions & 1 deletion lib/presentation/language_tool_text_field.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import 'package:flutter/material.dart';
import 'package:languagetool_textfield/domain/language_check_service.dart';

/// A TextField widget that checks the grammar using the given [langService]
class LanguageToolTextField extends StatefulWidget {
/// A service for checking errors.
final LanguageCheckService langService;

/// A style to use for the text being edited.
final TextStyle style;

/// A decoration of this [TextField].
final InputDecoration decoration;

/// A builder function used to build errors.
final Widget Function()? mistakeBuilder;

/// Creates a widget that checks grammar errors.
const LanguageToolTextField({
Key? key,
required this.langService,
Expand All @@ -20,7 +29,6 @@ class LanguageToolTextField extends StatefulWidget {
}

class _LanguageToolTextFieldState extends State<LanguageToolTextField> {

@override
Widget build(BuildContext context) {
return const Placeholder();
Expand Down