diff --git a/super_editor/analysis_options.yaml b/super_editor/analysis_options.yaml index 81dbfcdf95..61140b2eb5 100644 --- a/super_editor/analysis_options.yaml +++ b/super_editor/analysis_options.yaml @@ -1,8 +1,10 @@ -include: package:pedantic/analysis_options.1.11.0.yaml +include: package:flutter_lints/flutter.yaml analyzer: exclude: [build/**] linter: rules: - omit_local_variable_types: false \ No newline at end of file + avoid_print: false + omit_local_variable_types: false + use_key_in_widget_constructors: false diff --git a/super_editor/example/analysis_options.yaml b/super_editor/example/analysis_options.yaml index 43773a5aeb..66bdb93887 100644 --- a/super_editor/example/analysis_options.yaml +++ b/super_editor/example/analysis_options.yaml @@ -1,8 +1,10 @@ -include: package:pedantic/analysis_options.yaml +include: package:flutter_lints/flutter.yaml analyzer: exclude: [lib/spikes] linter: rules: - omit_local_variable_types: false \ No newline at end of file + avoid_print: false + omit_local_variable_types: false + use_key_in_widget_constructors: false diff --git a/super_editor/example/lib/demos/demo_attributed_text.dart b/super_editor/example/lib/demos/demo_attributed_text.dart index 79c0e35d50..a1b57b76cf 100644 --- a/super_editor/example/lib/demos/demo_attributed_text.dart +++ b/super_editor/example/lib/demos/demo_attributed_text.dart @@ -68,19 +68,19 @@ class _AttributedTextDemoState extends State { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Padding( - padding: const EdgeInsets.only(left: 20.0), + const Padding( + padding: EdgeInsets.only(left: 20.0), child: Text( 'AttributedText', style: TextStyle( - color: const Color(0xFF888888), + color: Color(0xFF888888), fontSize: 32, ), ), ), - SizedBox(height: 4), - Padding( - padding: const EdgeInsets.only(left: 20.0), + const SizedBox(height: 4), + const Padding( + padding: EdgeInsets.only(left: 20.0), child: Text( '''AttributedText is a data structure that supports an arbitrary number of "attribution spans". These attributions can be anything, and mean anything. @@ -90,21 +90,21 @@ That TextSpan can then be rendered by Flutter, as usual. Try it yourself by adding and removing attributions to characters in a string...''', style: TextStyle( - color: const Color(0xFF888888), + color: Color(0xFF888888), fontSize: 14, height: 1.4, fontWeight: FontWeight.normal, ), ), ), - SizedBox(height: 24), - SizedBox( + const SizedBox(height: 24), + const SizedBox( width: 600, child: Divider(), ), - SizedBox(height: 24), + const SizedBox(height: 24), Table( - defaultColumnWidth: IntrinsicColumnWidth(), + defaultColumnWidth: const IntrinsicColumnWidth(), defaultVerticalAlignment: TableCellVerticalAlignment.middle, children: [ TableRow( @@ -125,7 +125,7 @@ Try it yourself by adding and removing attributions to characters in a string... _buildCellSelector(_strikethroughRanges), ], ), - TableRow( + const TableRow( children: [ SizedBox(height: 24), SizedBox(height: 24), @@ -136,7 +136,7 @@ Try it yourself by adding and removing attributions to characters in a string... _buildRowTitle('Attributed Text'), SuperSelectableText( key: GlobalKey(), - textSpan: _richText ?? TextSpan(text: 'error'), + textSpan: _richText ?? const TextSpan(text: 'error'), ), ], ), diff --git a/super_editor/example/lib/demos/demo_document_loses_focus.dart b/super_editor/example/lib/demos/demo_document_loses_focus.dart index e57f0974b7..133acfa816 100644 --- a/super_editor/example/lib/demos/demo_document_loses_focus.dart +++ b/super_editor/example/lib/demos/demo_document_loses_focus.dart @@ -46,8 +46,8 @@ class _LoseFocusDemoState extends State { } Widget _buildDocSelector() { - return Padding( - padding: const EdgeInsets.symmetric(horizontal: 48.0), + return const Padding( + padding: EdgeInsets.symmetric(horizontal: 48.0), child: TextField( decoration: InputDecoration( hintText: 'tap to give focus to this TextField', diff --git a/super_editor/example/lib/demos/demo_markdown_serialization.dart b/super_editor/example/lib/demos/demo_markdown_serialization.dart index 789c99f3a5..a1e840622f 100644 --- a/super_editor/example/lib/demos/demo_markdown_serialization.dart +++ b/super_editor/example/lib/demos/demo_markdown_serialization.dart @@ -78,8 +78,8 @@ class _MarkdownSerializationDemoState extends State { padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 24), child: Text( _markdown, - style: TextStyle( - color: const Color(0xFFEEEEEE), + style: const TextStyle( + color: Color(0xFFEEEEEE), height: 1.4, ), ), diff --git a/super_editor/example/lib/demos/demo_selectable_text.dart b/super_editor/example/lib/demos/demo_selectable_text.dart index a3fa59885d..3d38c977a1 100644 --- a/super_editor/example/lib/demos/demo_selectable_text.dart +++ b/super_editor/example/lib/demos/demo_selectable_text.dart @@ -8,10 +8,10 @@ class SelectableTextDemo extends StatefulWidget { } class _SelectableTextDemoState extends State { - final _demoText1 = TextSpan( + final _demoText1 = const TextSpan( text: 'Super Editor', style: TextStyle( - color: const Color(0xFF444444), + color: Color(0xFF444444), fontSize: 18, height: 1.4, fontWeight: FontWeight.bold, @@ -20,7 +20,7 @@ class _SelectableTextDemoState extends State { TextSpan( text: ' is an open source text editor for Flutter projects.', style: TextStyle( - color: const Color(0xFF444444), + color: Color(0xFF444444), fontSize: 18, height: 1.4, fontWeight: FontWeight.normal, @@ -43,28 +43,28 @@ class _SelectableTextDemoState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ _buildTitle('SuperSelectableText Widget'), - SizedBox(height: 24), + const SizedBox(height: 24), _buildDemo( title: 'EMPTY TEXT WITH CARET', demo: SuperSelectableText.plain( text: '', - textSelection: TextSelection.collapsed(offset: 0), + textSelection: const TextSelection.collapsed(offset: 0), showCaret: true, - style: TextStyle( - color: const Color(0xFF444444), + style: const TextStyle( + color: Color(0xFF444444), fontSize: 18, height: 1.4, ), ), ), - SizedBox(height: 24), + const SizedBox(height: 24), _buildDemo( title: 'TEXT WITHOUT SELECTION OR CARET', demo: SuperSelectableText( textSpan: _demoText1, ), ), - SizedBox(height: 24), + const SizedBox(height: 24), _buildDemo( title: 'TEXT WITH CARET + COLLAPSED SELECTION', demo: SuperSelectableText( @@ -73,7 +73,7 @@ class _SelectableTextDemoState extends State { showCaret: true, ), ), - SizedBox(height: 24), + const SizedBox(height: 24), _buildDemo( title: 'TEXT WITH LEFT-TO-RIGHT SELECTION + CARET', demo: SuperSelectableText( @@ -82,7 +82,7 @@ class _SelectableTextDemoState extends State { showCaret: true, ), ), - SizedBox(height: 24), + const SizedBox(height: 24), _buildDemo( title: 'TEXT WITH RIGHT-TO-LEFT SELECTION + CARET', demo: SuperSelectableText( @@ -93,7 +93,7 @@ class _SelectableTextDemoState extends State { showCaret: true, ), ), - SizedBox(height: 24), + const SizedBox(height: 24), _buildDemo( title: 'TEXT WITH FULL SELECTION + CARET, CUSTOM COLORS, CARET SHAPE, DEBUG PAINT', demo: DebugSelectableTextDecorator( @@ -104,7 +104,7 @@ class _SelectableTextDemoState extends State { key: _debugTextKey, textSpan: _demoText1, textSelection: TextSelection(baseOffset: 0, extentOffset: _demoText1.toPlainText().length), - textSelectionDecoration: TextSelectionDecoration( + textSelectionDecoration: const TextSelectionDecoration( selectionColor: Colors.yellow, ), showCaret: true, @@ -127,8 +127,8 @@ class _SelectableTextDemoState extends State { Widget _buildTitle(String title) { return Text( title, - style: TextStyle( - color: const Color(0xFF444444), + style: const TextStyle( + color: Color(0xFF444444), fontSize: 32, ), ); @@ -144,21 +144,21 @@ class _SelectableTextDemoState extends State { children: [ Container( padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), - decoration: BoxDecoration( + decoration: const BoxDecoration( color: Colors.red, borderRadius: BorderRadius.vertical( top: Radius.circular(4), )), child: Text( title, - style: TextStyle( + style: const TextStyle( color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold, ), ), ), - SizedBox(height: 4), + const SizedBox(height: 4), demo, ], ); diff --git a/super_editor/example/lib/demos/demo_switch_document_content.dart b/super_editor/example/lib/demos/demo_switch_document_content.dart index a32cb989e2..20c1507f0a 100644 --- a/super_editor/example/lib/demos/demo_switch_document_content.dart +++ b/super_editor/example/lib/demos/demo_switch_document_content.dart @@ -65,16 +65,16 @@ class _SwitchDocumentDemoState extends State { _activeDocumentEditor = _docEditor1; }); }, - child: Text('Document 1'), + child: const Text('Document 1'), ), - SizedBox(width: 24), + const SizedBox(width: 24), TextButton( onPressed: () { setState(() { _activeDocumentEditor = _docEditor2; }); }, - child: Text('Document 2'), + child: const Text('Document 2'), ), ], ); diff --git a/super_editor/example/lib/demos/example_editor/_toolbar.dart b/super_editor/example/lib/demos/example_editor/_toolbar.dart index 083fdfd07c..63542e1d51 100644 --- a/super_editor/example/lib/demos/example_editor/_toolbar.dart +++ b/super_editor/example/lib/demos/example_editor/_toolbar.dart @@ -431,7 +431,7 @@ class _EditorToolbarState extends State { if (widget.anchor.value == null || widget.composer!.selection == null) { // When no anchor position is available, or the user hasn't // selected any text, show nothing. - return SizedBox(); + return const SizedBox(); } return SizedBox.expand( @@ -452,7 +452,7 @@ class _EditorToolbarState extends State { left: widget.anchor.value!.dx, top: widget.anchor.value!.dy, child: FractionalTranslation( - translation: Offset(-0.5, -1.4), + translation: const Offset(-0.5, -1.4), child: _buildToolbar(), ), ), @@ -465,7 +465,7 @@ class _EditorToolbarState extends State { Widget _buildToolbar() { return Material( - shape: StadiumBorder(), + shape: const StadiumBorder(), elevation: 5, clipBehavior: Clip.hardEdge, child: SizedBox( @@ -489,12 +489,12 @@ class _EditorToolbarState extends State { ), )) .toList(), - icon: Icon(Icons.arrow_drop_down), - style: TextStyle( + icon: const Icon(Icons.arrow_drop_down), + style: const TextStyle( color: Colors.black, fontSize: 12, ), - underline: SizedBox(), + underline: const SizedBox(), elevation: 0, itemHeight: 48, onChanged: _convertTextToNewType, @@ -505,7 +505,7 @@ class _EditorToolbarState extends State { Center( child: IconButton( onPressed: _toggleBold, - icon: Icon(Icons.format_bold), + icon: const Icon(Icons.format_bold), splashRadius: 16, tooltip: AppLocalizations.of(context)!.labelBold, ), @@ -513,7 +513,7 @@ class _EditorToolbarState extends State { Center( child: IconButton( onPressed: _toggleItalics, - icon: Icon(Icons.format_italic), + icon: const Icon(Icons.format_italic), splashRadius: 16, tooltip: AppLocalizations.of(context)!.labelItalics, ), @@ -521,7 +521,7 @@ class _EditorToolbarState extends State { Center( child: IconButton( onPressed: _toggleStrikethrough, - icon: Icon(Icons.strikethrough_s), + icon: const Icon(Icons.strikethrough_s), splashRadius: 16, tooltip: AppLocalizations.of(context)!.labelStrikethrough, ), @@ -529,7 +529,7 @@ class _EditorToolbarState extends State { Center( child: IconButton( onPressed: _areMultipleLinksSelected() ? null : _onLinkPressed, - icon: Icon(Icons.link), + icon: const Icon(Icons.link), color: _isSingleLinkSelected() ? const Color(0xFF007AFF) : IconTheme.of(context).color, splashRadius: 16, tooltip: AppLocalizations.of(context)!.labelLink, @@ -552,12 +552,12 @@ class _EditorToolbarState extends State { ), )) .toList(), - icon: Icon(Icons.arrow_drop_down), - style: TextStyle( + icon: const Icon(Icons.arrow_drop_down), + style: const TextStyle( color: Colors.black, fontSize: 12, ), - underline: SizedBox(), + underline: const SizedBox(), elevation: 0, itemHeight: 48, onChanged: _changeAlignment, @@ -568,7 +568,7 @@ class _EditorToolbarState extends State { Center( child: IconButton( onPressed: () {}, - icon: Icon(Icons.more_vert), + icon: const Icon(Icons.more_vert), splashRadius: 16, tooltip: AppLocalizations.of(context)!.labelMoreOptions, ), @@ -581,7 +581,7 @@ class _EditorToolbarState extends State { Widget _buildUrlField() { return Material( - shape: StadiumBorder(), + shape: const StadiumBorder(), elevation: 5, clipBehavior: Clip.hardEdge, child: Container( @@ -594,7 +594,7 @@ class _EditorToolbarState extends State { child: TextField( focusNode: _urlFocusNode, controller: _urlController, - decoration: InputDecoration( + decoration: const InputDecoration( hintText: 'enter url...', border: InputBorder.none, ), @@ -602,7 +602,7 @@ class _EditorToolbarState extends State { ), ), IconButton( - icon: Icon(Icons.close), + icon: const Icon(Icons.close), iconSize: 20, splashRadius: 16, padding: EdgeInsets.zero, diff --git a/super_editor/example/lib/demos/sliver_example_editor.dart b/super_editor/example/lib/demos/sliver_example_editor.dart index 0e2443468c..146cb70bc2 100644 --- a/super_editor/example/lib/demos/sliver_example_editor.dart +++ b/super_editor/example/lib/demos/sliver_example_editor.dart @@ -32,11 +32,11 @@ class _SliverExampleEditorState extends State { return CustomScrollView( slivers: [ SliverAppBar( - title: Text( + title: const Text( 'Rich Text Editor Sliver Example', ), expandedHeight: 200.0, - leading: SizedBox(), + leading: const SizedBox(), flexibleSpace: FlexibleSpaceBar( background: Image.network( 'https://i.imgur.com/fSZwM7G.jpg', @@ -44,7 +44,7 @@ class _SliverExampleEditorState extends State { ), ), ), - SliverToBoxAdapter( + const SliverToBoxAdapter( child: Text( 'Lorem Ipsum Dolor', style: TextStyle( @@ -73,7 +73,7 @@ class _SliverExampleEditorState extends State { content: Text( 'SliverList element tapped with index $index.', ), - duration: Duration(milliseconds: 500), + duration: const Duration(milliseconds: 500), ), ); }, diff --git a/super_editor/example/lib/demos/supertextfield/_emojis_demo.dart b/super_editor/example/lib/demos/supertextfield/_emojis_demo.dart index 5f09645d4e..9d0f3dfb9b 100644 --- a/super_editor/example/lib/demos/supertextfield/_emojis_demo.dart +++ b/super_editor/example/lib/demos/supertextfield/_emojis_demo.dart @@ -48,7 +48,7 @@ class _EmojisTextFieldDemoState extends State with TickerPr void _startDemo() { _textFieldController - ..selection = TextSelection.collapsed(offset: 0) + ..selection = const TextSelection.collapsed(offset: 0) ..text = AttributedText( text: 'turtle 🐢 bomb 💣 skull ☠', ); @@ -63,7 +63,7 @@ class _EmojisTextFieldDemoState extends State with TickerPr } else { // simulate pressing delete _demoRobot - ..insertCaretAt(TextPosition(offset: 0)) + ..insertCaretAt(const TextPosition(offset: 0)) ..pause(const Duration(seconds: 1)) ..deleteCharacters(_textFieldController.text.text.length) ..start(); @@ -113,7 +113,7 @@ class _EmojisTextFieldDemoState extends State with TickerPr ); }, hintBuilder: (context) { - return Text( + return const Text( 'enter some text', style: TextStyle( color: Colors.grey, @@ -126,10 +126,10 @@ class _EmojisTextFieldDemoState extends State with TickerPr ), ), ), - SizedBox(height: 16), + const SizedBox(height: 16), ElevatedButton( onPressed: _restartDemo, - child: Text('Restart Demo'), + child: const Text('Restart Demo'), ), ], ), diff --git a/super_editor/example/lib/demos/supertextfield/_expanding_multi_line_demo.dart b/super_editor/example/lib/demos/supertextfield/_expanding_multi_line_demo.dart index ca4b1c43f6..45f850449e 100644 --- a/super_editor/example/lib/demos/supertextfield/_expanding_multi_line_demo.dart +++ b/super_editor/example/lib/demos/supertextfield/_expanding_multi_line_demo.dart @@ -53,7 +53,7 @@ class _ExpandingMultiLineTextFieldDemoState extends State { final _textFieldController = AttributedTextEditingController( text: AttributedText( text: 'Super Editor is an open source text editor for Flutter projects.', - spans: AttributedSpans(attributions: [ + spans: AttributedSpans(attributions: const [ SpanMarker(attribution: brandAttribution, offset: 0, markerType: SpanMarkerType.start), SpanMarker(attribution: brandAttribution, offset: 11, markerType: SpanMarkerType.end), SpanMarker(attribution: flutterAttribution, offset: 47, markerType: SpanMarkerType.start), @@ -88,7 +88,7 @@ class _InteractiveTextFieldDemoState extends State { )); _closePopup(); }, - child: Text('Copy'), + child: const Text('Copy'), ), ], ), @@ -150,7 +150,7 @@ class _InteractiveTextFieldDemoState extends State { ); }, hintBuilder: (context) { - return Text( + return const Text( 'enter some text', style: TextStyle( color: Colors.grey, @@ -170,7 +170,7 @@ class _InteractiveTextFieldDemoState extends State { } TextStyle _textStyleBuilder(Set attributions) { - TextStyle textStyle = TextStyle( + TextStyle textStyle = const TextStyle( color: Colors.black, fontSize: 14, ); diff --git a/super_editor/example/lib/demos/supertextfield/_robot.dart b/super_editor/example/lib/demos/supertextfield/_robot.dart index ef684facb0..a66ce13d6e 100644 --- a/super_editor/example/lib/demos/supertextfield/_robot.dart +++ b/super_editor/example/lib/demos/supertextfield/_robot.dart @@ -59,7 +59,7 @@ class TextFieldDemoRobot { } Future deselect() async { - _commands.add(SelectTextCommand(selection: TextSelection.collapsed(offset: -1))); + _commands.add(SelectTextCommand(selection: const TextSelection.collapsed(offset: -1))); } Future pause(Duration duration) async { diff --git a/super_editor/example/lib/demos/supertextfield/_single_line_demo.dart b/super_editor/example/lib/demos/supertextfield/_single_line_demo.dart index 20a38eac05..f0c2531bec 100644 --- a/super_editor/example/lib/demos/supertextfield/_single_line_demo.dart +++ b/super_editor/example/lib/demos/supertextfield/_single_line_demo.dart @@ -52,7 +52,7 @@ class _SingleLineTextFieldDemoState extends State with void _startDemo() { _textFieldController - ..selection = TextSelection.collapsed(offset: 0) + ..selection = const TextSelection.collapsed(offset: 0) ..text = AttributedText(); _demoRobot ..typeText(AttributedText(text: 'Hello World! This is a robot typing some text into a SuperTextField.')) @@ -102,7 +102,7 @@ class _SingleLineTextFieldDemoState extends State with ); }, hintBuilder: (context) { - return Text( + return const Text( 'enter some text', style: TextStyle( color: Colors.grey, @@ -115,10 +115,10 @@ class _SingleLineTextFieldDemoState extends State with ), ), ), - SizedBox(height: 16), + const SizedBox(height: 16), ElevatedButton( onPressed: _restartDemo, - child: Text('Restart Demo'), + child: const Text('Restart Demo'), ), ], ), diff --git a/super_editor/example/lib/demos/supertextfield/_static_multi_line_demo.dart b/super_editor/example/lib/demos/supertextfield/_static_multi_line_demo.dart index f72e6bd3b7..e615ad7daa 100644 --- a/super_editor/example/lib/demos/supertextfield/_static_multi_line_demo.dart +++ b/super_editor/example/lib/demos/supertextfield/_static_multi_line_demo.dart @@ -52,7 +52,7 @@ class _StaticMultiLineTextFieldDemoState extends State { label: 'Backspace emojis', onPressed: () { setState(() { - _demoBuilder = (_) => EmojisTextFieldDemo( + _demoBuilder = (_) => const EmojisTextFieldDemo( key: ValueKey('backspace'), direction: TextAffinity.upstream, ); @@ -84,7 +84,7 @@ class _TextFieldDemoState extends State { label: 'Delete emojis', onPressed: () { setState(() { - _demoBuilder = (_) => EmojisTextFieldDemo( + _demoBuilder = (_) => const EmojisTextFieldDemo( key: ValueKey('delete'), direction: TextAffinity.downstream, ); diff --git a/super_editor/example/lib/main.dart b/super_editor/example/lib/main.dart index 94189d7e9e..6725214e6d 100644 --- a/super_editor/example/lib/main.dart +++ b/super_editor/example/lib/main.dart @@ -27,11 +27,11 @@ class SuperEditorDemoApp extends StatelessWidget { primarySwatch: Colors.red, ), home: HomeScreen(), - supportedLocales: [ - const Locale('en', ''), - const Locale('es', ''), + supportedLocales: const [ + Locale('en', ''), + Locale('es', ''), ], - localizationsDelegates: [ + localizationsDelegates: const [ ...AppLocalizations.localizationsDelegates, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, @@ -98,7 +98,7 @@ class _HomeScreenState extends State { backgroundColor: Colors.transparent, elevation: 0, leading: IconButton( - icon: Icon(Icons.menu), + icon: const Icon(Icons.menu), color: Theme.of(context).colorScheme.onSurface, splashRadius: 24, onPressed: _toggleDrawer, @@ -126,7 +126,7 @@ class _HomeScreenState extends State { }, ), ], - SizedBox(height: 24), + const SizedBox(height: 24), ], ], ), @@ -253,8 +253,8 @@ class _DrawerHeader extends StatelessWidget { padding: const EdgeInsets.only(left: 16, bottom: 4), child: Text( title!, - style: TextStyle( - color: const Color(0xFF444444), + style: const TextStyle( + color: Color(0xFF444444), fontSize: 10, fontWeight: FontWeight.bold, ), @@ -302,11 +302,11 @@ class _DrawerButton extends StatelessWidget { onPressed: isSelected ? null : onPressed, child: Row( children: [ - SizedBox(width: 8), + const SizedBox(width: 8), Icon( icon, ), - SizedBox(width: 16), + const SizedBox(width: 16), Expanded( child: Text(title), ), diff --git a/super_editor/example/lib/marketing_video/main_marketing_video.dart b/super_editor/example/lib/marketing_video/main_marketing_video.dart index 4010f4f14f..eaef16b92a 100644 --- a/super_editor/example/lib/marketing_video/main_marketing_video.dart +++ b/super_editor/example/lib/marketing_video/main_marketing_video.dart @@ -235,9 +235,9 @@ TextStyle _textStyleBuilder(Set attributions) { return textStyle; } -final superlistBrandAttribution = NamedAttribution('superlist_brand'); -final titleAttribution = NamedAttribution('titleAttribution'); -final headerAttribution = NamedAttribution('header'); +const superlistBrandAttribution = NamedAttribution('superlist_brand'); +const titleAttribution = NamedAttribution('titleAttribution'); +const headerAttribution = NamedAttribution('header'); class DocumentEditingRobot { DocumentEditingRobot({ @@ -257,7 +257,7 @@ class DocumentEditingRobot { final DocumentComposer _composer; final CommonEditorOperations _editorOps; final _actionQueue = []; - final _random; + final Random _random; void placeCaret(DocumentPosition position) { _actionQueue.add( diff --git a/super_editor/example/pubspec.lock b/super_editor/example/pubspec.lock index 8659fc7886..0793b42fda 100644 --- a/super_editor/example/pubspec.lock +++ b/super_editor/example/pubspec.lock @@ -90,6 +90,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_lints: + dependency: transitive + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" flutter_localizations: dependency: "direct main" description: flutter @@ -135,6 +142,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.0.0" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" markdown: dependency: transitive description: @@ -237,7 +251,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: diff --git a/super_editor/example/test/spikes/editor_abstractions/attributed_spans_test.dart b/super_editor/example/test/spikes/editor_abstractions/attributed_spans_test.dart index d3f4d10d28..89608789fa 100644 --- a/super_editor/example/test/spikes/editor_abstractions/attributed_spans_test.dart +++ b/super_editor/example/test/spikes/editor_abstractions/attributed_spans_test.dart @@ -10,8 +10,10 @@ void main() { spans.addAttribution(newAttribution: 'bold', start: 0, end: 16); expect(spans.attributions.length, 2); - expect(spans.attributions[0], SpanMarker(attribution: 'bold', offset: 0, markerType: SpanMarkerType.start)); - expect(spans.attributions[1], SpanMarker(attribution: 'bold', offset: 16, markerType: SpanMarkerType.end)); + expect( + spans.attributions[0], const SpanMarker(attribution: 'bold', offset: 0, markerType: SpanMarkerType.start)); + expect( + spans.attributions[1], const SpanMarker(attribution: 'bold', offset: 16, markerType: SpanMarkerType.end)); }); test('applies attribution to beginning of span', () { @@ -20,8 +22,9 @@ void main() { spans.addAttribution(newAttribution: 'bold', start: 0, end: 7); expect(spans.attributions.length, 2); - expect(spans.attributions[0], SpanMarker(attribution: 'bold', offset: 0, markerType: SpanMarkerType.start)); - expect(spans.attributions[1], SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end)); + expect( + spans.attributions[0], const SpanMarker(attribution: 'bold', offset: 0, markerType: SpanMarkerType.start)); + expect(spans.attributions[1], const SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end)); }); test('applies attribution to inner span', () { @@ -30,8 +33,9 @@ void main() { spans.addAttribution(newAttribution: 'bold', start: 2, end: 7); expect(spans.attributions.length, 2); - expect(spans.attributions[0], SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start)); - expect(spans.attributions[1], SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end)); + expect( + spans.attributions[0], const SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start)); + expect(spans.attributions[1], const SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end)); }); test('applies attribution to end of span', () { @@ -40,8 +44,10 @@ void main() { spans.addAttribution(newAttribution: 'bold', start: 7, end: 16); expect(spans.attributions.length, 2); - expect(spans.attributions[0], SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.start)); - expect(spans.attributions[1], SpanMarker(attribution: 'bold', offset: 16, markerType: SpanMarkerType.end)); + expect( + spans.attributions[0], const SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.start)); + expect( + spans.attributions[1], const SpanMarker(attribution: 'bold', offset: 16, markerType: SpanMarkerType.end)); }); test('applies exotic span', () { @@ -65,8 +71,8 @@ void main() { final spans = AttributedSpans( length: 17, attributions: [ - SpanMarker(attribution: 'bold', offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: 'bold', offset: 16, markerType: SpanMarkerType.end) + const SpanMarker(attribution: 'bold', offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: 'bold', offset: 16, markerType: SpanMarkerType.end) ], ); @@ -79,8 +85,8 @@ void main() { final spans = AttributedSpans( length: 17, attributions: [ - SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start), - SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end) + const SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start), + const SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end) ], ); @@ -93,74 +99,80 @@ void main() { final spans = AttributedSpans( length: 17, attributions: [ - SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start), - SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end) + const SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start), + const SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end) ], ); spans.removeAttribution(attributionToRemove: 'bold', start: 2, end: 4); expect(spans.attributions.length, 2); - expect(spans.attributions[0], SpanMarker(attribution: 'bold', offset: 5, markerType: SpanMarkerType.start)); - expect(spans.attributions[1], SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end)); + expect( + spans.attributions[0], const SpanMarker(attribution: 'bold', offset: 5, markerType: SpanMarkerType.start)); + expect(spans.attributions[1], const SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end)); }); test('removes attribution from partial inner span', () { final spans = AttributedSpans( length: 17, attributions: [ - SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start), - SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end) + const SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start), + const SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end) ], ); spans.removeAttribution(attributionToRemove: 'bold', start: 4, end: 5); expect(spans.attributions.length, 4); - expect(spans.attributions[0], SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start)); - expect(spans.attributions[1], SpanMarker(attribution: 'bold', offset: 3, markerType: SpanMarkerType.end)); - expect(spans.attributions[2], SpanMarker(attribution: 'bold', offset: 6, markerType: SpanMarkerType.start)); - expect(spans.attributions[3], SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end)); + expect( + spans.attributions[0], const SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start)); + expect(spans.attributions[1], const SpanMarker(attribution: 'bold', offset: 3, markerType: SpanMarkerType.end)); + expect( + spans.attributions[2], const SpanMarker(attribution: 'bold', offset: 6, markerType: SpanMarkerType.start)); + expect(spans.attributions[3], const SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end)); }); test('removes attribution from partial ending span', () { final spans = AttributedSpans( length: 17, attributions: [ - SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start), - SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end) + const SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start), + const SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end) ], ); spans.removeAttribution(attributionToRemove: 'bold', start: 5, end: 7); expect(spans.attributions.length, 2); - expect(spans.attributions[0], SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start)); - expect(spans.attributions[1], SpanMarker(attribution: 'bold', offset: 4, markerType: SpanMarkerType.end)); + expect( + spans.attributions[0], const SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start)); + expect(spans.attributions[1], const SpanMarker(attribution: 'bold', offset: 4, markerType: SpanMarkerType.end)); }); test('applies attribution when mixed span is toggled', () { final spans = AttributedSpans( length: 17, attributions: [ - SpanMarker(attribution: 'bold', offset: 8, markerType: SpanMarkerType.start), - SpanMarker(attribution: 'bold', offset: 16, markerType: SpanMarkerType.end) + const SpanMarker(attribution: 'bold', offset: 8, markerType: SpanMarkerType.start), + const SpanMarker(attribution: 'bold', offset: 16, markerType: SpanMarkerType.end) ], ); spans.toggleAttribution(attribution: 'bold', start: 0, end: 16); expect(spans.attributions.length, 2); - expect(spans.attributions[0], SpanMarker(attribution: 'bold', offset: 0, markerType: SpanMarkerType.start)); - expect(spans.attributions[1], SpanMarker(attribution: 'bold', offset: 16, markerType: SpanMarkerType.end)); + expect( + spans.attributions[0], const SpanMarker(attribution: 'bold', offset: 0, markerType: SpanMarkerType.start)); + expect( + spans.attributions[1], const SpanMarker(attribution: 'bold', offset: 16, markerType: SpanMarkerType.end)); }); test('removes attribution when contiguous span is toggled', () { final spans = AttributedSpans( length: 17, attributions: [ - SpanMarker(attribution: 'bold', offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: 'bold', offset: 16, markerType: SpanMarkerType.end) + const SpanMarker(attribution: 'bold', offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: 'bold', offset: 16, markerType: SpanMarkerType.end) ], ); diff --git a/super_editor/example/test/spikes/editor_abstractions/attributed_text_test.dart b/super_editor/example/test/spikes/editor_abstractions/attributed_text_test.dart index 406eec3161..4ec966afa2 100644 --- a/super_editor/example/test/spikes/editor_abstractions/attributed_text_test.dart +++ b/super_editor/example/test/spikes/editor_abstractions/attributed_text_test.dart @@ -16,7 +16,7 @@ void main() { }); test('full-span style', () { - final text = AttributedText(text: 'abcdefghij', attributions: [ + final text = AttributedText(text: 'abcdefghij', attributions: const [ SpanMarker(attribution: 'bold', offset: 0, markerType: SpanMarkerType.start), SpanMarker(attribution: 'bold', offset: 9, markerType: SpanMarkerType.end), ]); @@ -28,7 +28,7 @@ void main() { }); test('single character style', () { - final text = AttributedText(text: 'abcdefghij', attributions: [ + final text = AttributedText(text: 'abcdefghij', attributions: const [ SpanMarker(attribution: 'bold', offset: 1, markerType: SpanMarkerType.start), SpanMarker(attribution: 'bold', offset: 1, markerType: SpanMarkerType.end), ]); @@ -44,7 +44,7 @@ void main() { }); test('single character style - reverse order', () { - final text = AttributedText(text: 'abcdefghij', attributions: [ + final text = AttributedText(text: 'abcdefghij', attributions: const [ // Notice that the markers are provided in reverse order: // end then start. Order shouldn't matter within a single // position index. This test ensures that. @@ -64,7 +64,7 @@ void main() { test('add single character style', () { final text = AttributedText(text: 'abcdefghij'); - text.addAttribution('bold', TextRange(start: 1, end: 1)); + text.addAttribution('bold', const TextRange(start: 1, end: 1)); final textSpan = text.computeTextSpan(_styleBuilder); expect(textSpan.text, null); @@ -77,7 +77,7 @@ void main() { }); test('partial style', () { - final text = AttributedText(text: 'abcdefghij', attributions: [ + final text = AttributedText(text: 'abcdefghij', attributions: const [ SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start), SpanMarker(attribution: 'bold', offset: 7, markerType: SpanMarkerType.end), ]); @@ -92,7 +92,7 @@ void main() { }); test('non-mingled varying styles', () { - final text = AttributedText(text: 'abcdefghij', attributions: [ + final text = AttributedText(text: 'abcdefghij', attributions: const [ SpanMarker(attribution: 'bold', offset: 0, markerType: SpanMarkerType.start), SpanMarker(attribution: 'bold', offset: 4, markerType: SpanMarkerType.end), SpanMarker(attribution: 'italics', offset: 5, markerType: SpanMarkerType.start), @@ -111,7 +111,7 @@ void main() { }); test('intermingled varying styles', () { - final text = AttributedText(text: 'abcdefghij', attributions: [ + final text = AttributedText(text: 'abcdefghij', attributions: const [ SpanMarker(attribution: 'bold', offset: 2, markerType: SpanMarkerType.start), SpanMarker(attribution: 'italics', offset: 4, markerType: SpanMarkerType.start), SpanMarker(attribution: 'bold', offset: 5, markerType: SpanMarkerType.end), diff --git a/super_editor/lib/src/core/document_editor.dart b/super_editor/lib/src/core/document_editor.dart index a93f2a35be..6c04fc4981 100644 --- a/super_editor/lib/src/core/document_editor.dart +++ b/super_editor/lib/src/core/document_editor.dart @@ -13,7 +13,7 @@ import 'document.dart'; /// can be event-sourced, allowing for undo/redo behavior. // TODO: design and implement comprehensive event-sourced editing API (#49) class DocumentEditor { - static final Uuid _uuid = Uuid(); + static const Uuid _uuid = Uuid(); /// Generates a new ID for a [DocumentNode]. /// @@ -267,7 +267,9 @@ class MutableDocument with ChangeNotifier implements Document { @override bool operator ==(Object other) => identical(this, other) || - other is MutableDocument && runtimeType == other.runtimeType && DeepCollectionEquality().equals(_nodes, nodes); + other is MutableDocument && + runtimeType == other.runtimeType && + const DeepCollectionEquality().equals(_nodes, nodes); @override int get hashCode => _nodes.hashCode; diff --git a/super_editor/lib/src/core/document_layout.dart b/super_editor/lib/src/core/document_layout.dart index 9efac1cb9a..201a7c984e 100644 --- a/super_editor/lib/src/core/document_layout.dart +++ b/super_editor/lib/src/core/document_layout.dart @@ -44,14 +44,12 @@ abstract class DocumentLayout { /// Returns a [Rect] that bounds the content selected between /// [basePosition] and [extentPosition]. - Rect? getRectForSelection( - DocumentPosition basePosition, DocumentPosition extentPosition); + Rect? getRectForSelection(DocumentPosition basePosition, DocumentPosition extentPosition); /// Returns a [DocumentSelection] that begins near [baseOffset] and extends /// to [extentOffset], or [null] if no document content sits between the /// provided points. - DocumentSelection? getDocumentSelectionInRegion( - Offset baseOffset, Offset extentOffset); + DocumentSelection? getDocumentSelectionInRegion(Offset baseOffset, Offset extentOffset); /// Returns the [MouseCursor] that's desired by the component at [documentOffset], or /// [null] if the document has no preference for the [MouseCursor] at the given @@ -64,13 +62,11 @@ abstract class DocumentLayout { /// Converts [ancestorOffset] from the [ancestor]'s coordinate space to the /// same location on the screen within this [DocumentLayout]'s coordinate space. - Offset getDocumentOffsetFromAncestorOffset( - Offset ancestorOffset, RenderObject ancestor); + Offset getDocumentOffsetFromAncestorOffset(Offset ancestorOffset, RenderObject ancestor); /// Converts [documentOffset] from this [DocumentLayout]'s coordinate space /// to the same location on the screen within the [ancestor]'s coordinate space. - Offset getAncestorOffsetFromDocumentOffset( - Offset documentOffset, RenderObject ancestor); + Offset getAncestorOffsetFromDocumentOffset(Offset documentOffset, RenderObject ancestor); } /// Contract for all widgets that operate as document components @@ -117,8 +113,7 @@ mixin DocumentComponent on State { /// /// See [Document] for more information about [DocumentNode]s and /// node positions. - Rect getRectForSelection( - NodePosition baseNodePosition, NodePosition extentNodePosition); + Rect getRectForSelection(NodePosition baseNodePosition, NodePosition extentNodePosition); /// Returns the node position that represents the "beginning" of /// the content within this component, such as the first character @@ -150,8 +145,7 @@ mixin DocumentComponent on State { /// Returns [null] if there is nowhere to move left within this /// component, such as when the [currentPosition] is the first /// character within a paragraph. - NodePosition? movePositionLeft(NodePosition currentPosition, - [Set movementModifiers]); + NodePosition? movePositionLeft(NodePosition currentPosition, [Set movementModifiers]); /// Returns a new position within this component's node that /// corresponds to the [currentPosition] moved right one unit, @@ -167,8 +161,7 @@ mixin DocumentComponent on State { /// Returns null if there is nowhere to move right within this /// component, such as when the [currentPosition] refers to the /// last character in a paragraph. - NodePosition? movePositionRight(NodePosition currentPosition, - [Set movementModifiers]); + NodePosition? movePositionRight(NodePosition currentPosition, [Set movementModifiers]); /// Returns a new position within this component's node that /// corresponds to the [currentPosition] moved up one unit, @@ -216,8 +209,7 @@ mixin DocumentComponent on State { /// /// The selection type depends on the type of [DocumentNode] that this /// component displays. - NodeSelection? getSelectionInRange( - Offset localBaseOffset, Offset localExtentOffset); + NodeSelection? getSelectionInRange(Offset localBaseOffset, Offset localExtentOffset); /// Returns a [NodeSelection] within this component's [DocumentNode] that /// is collapsed at the given [nodePosition] @@ -282,10 +274,7 @@ class MovementModifier { @override bool operator ==(Object other) => - identical(this, other) || - other is MovementModifier && - runtimeType == other.runtimeType && - id == other.id; + identical(this, other) || other is MovementModifier && runtimeType == other.runtimeType && id == other.id; @override int get hashCode => id.hashCode; diff --git a/super_editor/lib/src/default_editor/blockquote.dart b/super_editor/lib/src/default_editor/blockquote.dart index d76b64ba0d..64cefdda1a 100644 --- a/super_editor/lib/src/default_editor/blockquote.dart +++ b/super_editor/lib/src/default_editor/blockquote.dart @@ -16,6 +16,7 @@ import 'paragraph.dart'; import 'styles.dart'; import 'text.dart'; +// ignore: unused_element final _log = Logger(scope: 'blockquote.dart'); /// Displays a blockquote in a document. diff --git a/super_editor/lib/src/default_editor/box_component.dart b/super_editor/lib/src/default_editor/box_component.dart index 0e15451fec..1f9a8e7600 100644 --- a/super_editor/lib/src/default_editor/box_component.dart +++ b/super_editor/lib/src/default_editor/box_component.dart @@ -7,6 +7,7 @@ import 'package:super_editor/super_editor.dart'; import '../core/document.dart'; import '../core/document_layout.dart'; +// ignore: unused_element final _log = Logger(scope: 'box_component.dart'); /// Editor layout component that displays content that is either @@ -27,12 +28,12 @@ class BoxComponent extends StatefulWidget { class _BoxComponentState extends State with DocumentComponent { @override BinaryNodePosition getBeginningPosition() { - return BinaryNodePosition.included(); + return const BinaryNodePosition.included(); } @override BinaryNodePosition getBeginningPositionNearX(double x) { - return BinaryNodePosition.included(); + return const BinaryNodePosition.included(); } @override @@ -65,7 +66,7 @@ class _BoxComponentState extends State with DocumentComponent { throw Exception('The given nodePosition ($nodePosition) is not compatible with BoxComponent'); } - return BinarySelection.all(); + return const BinarySelection.all(); } @override @@ -75,12 +76,12 @@ class _BoxComponentState extends State with DocumentComponent { @override BinaryNodePosition getEndPosition() { - return BinaryNodePosition.included(); + return const BinaryNodePosition.included(); } @override BinaryNodePosition getEndPositionNearX(double x) { - return BinaryNodePosition.included(); + return const BinaryNodePosition.included(); } @override @@ -118,7 +119,7 @@ class _BoxComponentState extends State with DocumentComponent { @override BinaryNodePosition getPositionAtOffset(Offset localOffset) { - return BinaryNodePosition.included(); + return const BinaryNodePosition.included(); } @override @@ -130,17 +131,17 @@ class _BoxComponentState extends State with DocumentComponent { throw Exception('The given extentPosition ($extentPosition) is not compatible with BoxComponent'); } - return BinarySelection.all(); + return const BinarySelection.all(); } @override BinarySelection getSelectionInRange(Offset localBaseOffset, Offset localExtentOffset) { - return BinarySelection.all(); + return const BinarySelection.all(); } @override BinarySelection getSelectionOfEverything() { - return BinarySelection.all(); + return const BinarySelection.all(); } @override diff --git a/super_editor/lib/src/default_editor/common_editor_operations.dart b/super_editor/lib/src/default_editor/common_editor_operations.dart index a1db49081a..0753bd267a 100644 --- a/super_editor/lib/src/default_editor/common_editor_operations.dart +++ b/super_editor/lib/src/default_editor/common_editor_operations.dart @@ -35,12 +35,10 @@ final _log = Logger(scope: 'common_editor_operations.dart'); /// implemented within [CommonEditorOperations]. class CommonEditorOperations { CommonEditorOperations({ - required DocumentEditor editor, - required DocumentComposer composer, - required DocumentLayoutResolver documentLayoutResolver, - }) : editor = editor, - composer = composer, - documentLayoutResolver = documentLayoutResolver; + required this.editor, + required this.composer, + required this.documentLayoutResolver, + }); // Marked as protected for extension methods and subclasses @protected @@ -1029,7 +1027,7 @@ class CommonEditorOperations { // Assume that the node was replaced with an empty paragraph. newSelectionPosition = DocumentPosition( nodeId: newSelectionPosition.nodeId, - nodePosition: TextNodePosition(offset: 0), + nodePosition: const TextNodePosition(offset: 0), ); } } else { @@ -1042,7 +1040,7 @@ class CommonEditorOperations { // Assume that the node was replace with an empty paragraph. newSelectionPosition = DocumentPosition( nodeId: baseNode.id, - nodePosition: TextNodePosition(offset: 0), + nodePosition: const TextNodePosition(offset: 0), ); } else if (basePosition.nodePosition is TextNodePosition) { final baseOffset = (basePosition.nodePosition as TextNodePosition).offset; @@ -1337,7 +1335,7 @@ class CommonEditorOperations { composer.selection = DocumentSelection.collapsed( position: DocumentPosition( nodeId: node.id, - nodePosition: TextNodePosition(offset: 0), + nodePosition: const TextNodePosition(offset: 0), ), ); @@ -1383,7 +1381,7 @@ class CommonEditorOperations { // URL match, e.g., images, social, etc. _log.log('_convertParagraphIfDesired', 'Looking for URL match...'); final extractedLinks = linkify(node.text.text, - options: LinkifyOptions( + options: const LinkifyOptions( humanize: false, )); final int linkCount = extractedLinks.fold(0, (value, element) => element is UrlElement ? value + 1 : value); @@ -1587,7 +1585,7 @@ class CommonEditorOperations { composer.selection = DocumentSelection.collapsed( position: DocumentPosition( nodeId: newNodeId, - nodePosition: TextNodePosition(offset: 0), + nodePosition: const TextNodePosition(offset: 0), ), ); @@ -1633,7 +1631,7 @@ class CommonEditorOperations { final nodeIndex = editor.document.getNodeIndex(node); - var newSelection; + DocumentSelection newSelection; if (node.text.text.isEmpty) { // Convert empty paragraph to HR. final imageNode = ImageNode(id: nodeId, imageUrl: url); @@ -1728,7 +1726,7 @@ class CommonEditorOperations { final paragraphPosition = composer.selection!.extent.nodePosition as TextNodePosition; final endOfParagraph = node.endPosition; - var newSelection; + DocumentSelection newSelection; if (node.text.text.isEmpty) { // Convert empty paragraph to HR. final hrNode = HorizontalRuleNode(id: nodeId); @@ -1948,6 +1946,7 @@ class CommonEditorOperations { if (extentNode is ParagraphNode) { extentNode.metadata.remove('blockType'); // TODO: find a way to alter nodes that automatically notifies listeners + // ignore: invalid_use_of_protected_member, invalid_use_of_visible_for_testing_member extentNode.notifyListeners(); } else { final newParagraphNode = ParagraphNode( diff --git a/super_editor/lib/src/default_editor/document_interaction.dart b/super_editor/lib/src/default_editor/document_interaction.dart index 80b94d275c..957c49a500 100644 --- a/super_editor/lib/src/default_editor/document_interaction.dart +++ b/super_editor/lib/src/default_editor/document_interaction.dart @@ -60,7 +60,7 @@ class DocumentInteractor extends StatefulWidget { /// Paints some extra visual ornamentation to help with /// debugging, when true. - final showDebugPaint; + final bool showDebugPaint; @override _DocumentInteractorState createState() => _DocumentInteractorState(); @@ -619,7 +619,7 @@ class _DocumentInteractorState extends State with SingleTick document: widget.document, ), Positioned.fill( - child: widget.showDebugPaint ? _buildDragSelection() : SizedBox(), + child: widget.showDebugPaint ? _buildDragSelection() : const SizedBox(), ), ], ), @@ -703,7 +703,7 @@ class _DocumentInteractorState extends State with SingleTick }) { return SingleChildScrollView( controller: _scrollController, - physics: NeverScrollableScrollPhysics(), + physics: const NeverScrollableScrollPhysics(), child: Center( child: SizedBox( key: _documentWrapperKey, diff --git a/super_editor/lib/src/default_editor/document_keyboard_actions.dart b/super_editor/lib/src/default_editor/document_keyboard_actions.dart index 60fd21564f..b7ac444c30 100644 --- a/super_editor/lib/src/default_editor/document_keyboard_actions.dart +++ b/super_editor/lib/src/default_editor/document_keyboard_actions.dart @@ -401,7 +401,7 @@ DocumentPosition _getDocumentPositionAfterDeletion({ // Assume that the node was replaced with an empty paragraph. newSelectionPosition = DocumentPosition( nodeId: newSelectionPosition.nodeId, - nodePosition: TextNodePosition(offset: 0), + nodePosition: const TextNodePosition(offset: 0), ); } } else { @@ -414,7 +414,7 @@ DocumentPosition _getDocumentPositionAfterDeletion({ // Assume that the node was replace with an empty paragraph. newSelectionPosition = DocumentPosition( nodeId: baseNode.id, - nodePosition: TextNodePosition(offset: 0), + nodePosition: const TextNodePosition(offset: 0), ); } else if (basePosition.nodePosition is TextPosition) { final baseOffset = (basePosition.nodePosition as TextPosition).offset; diff --git a/super_editor/lib/src/default_editor/horizontal_rule.dart b/super_editor/lib/src/default_editor/horizontal_rule.dart index af1e03a855..f82a298e3c 100644 --- a/super_editor/lib/src/default_editor/horizontal_rule.dart +++ b/super_editor/lib/src/default_editor/horizontal_rule.dart @@ -18,10 +18,10 @@ class HorizontalRuleNode with ChangeNotifier implements DocumentNode { final String id; @override - BinaryNodePosition get beginningPosition => BinaryNodePosition.included(); + BinaryNodePosition get beginningPosition => const BinaryNodePosition.included(); @override - BinaryNodePosition get endPosition => BinaryNodePosition.included(); + BinaryNodePosition get endPosition => const BinaryNodePosition.included(); @override NodePosition selectUpstreamPosition(NodePosition position1, NodePosition position2) { @@ -56,7 +56,7 @@ class HorizontalRuleNode with ChangeNotifier implements DocumentNode { @required dynamic base, @required dynamic extent, }) { - return BinarySelection.all(); + return const BinarySelection.all(); } @override @@ -65,7 +65,7 @@ class HorizontalRuleNode with ChangeNotifier implements DocumentNode { throw Exception('HorizontalRuleNode can only copy content from a BinarySelection.'); } - return selection.position == BinaryNodePosition.included() ? '---' : null; + return selection.position == const BinaryNodePosition.included() ? '---' : null; } @override diff --git a/super_editor/lib/src/default_editor/image.dart b/super_editor/lib/src/default_editor/image.dart index fba183a4c1..4efb4907ca 100644 --- a/super_editor/lib/src/default_editor/image.dart +++ b/super_editor/lib/src/default_editor/image.dart @@ -38,10 +38,10 @@ class ImageNode with ChangeNotifier implements DocumentNode { } @override - BinaryNodePosition get beginningPosition => BinaryNodePosition.included(); + BinaryNodePosition get beginningPosition => const BinaryNodePosition.included(); @override - BinaryNodePosition get endPosition => BinaryNodePosition.included(); + BinaryNodePosition get endPosition => const BinaryNodePosition.included(); @override NodePosition selectUpstreamPosition(NodePosition position1, NodePosition position2) { @@ -76,7 +76,7 @@ class ImageNode with ChangeNotifier implements DocumentNode { @required dynamic base, @required dynamic extent, }) { - return BinarySelection.all(); + return const BinarySelection.all(); } @override @@ -85,7 +85,7 @@ class ImageNode with ChangeNotifier implements DocumentNode { throw Exception('ImageNode can only copy content from a BinarySelection.'); } - return selection.position == BinaryNodePosition.included() ? _imageUrl : null; + return selection.position == const BinaryNodePosition.included() ? _imageUrl : null; } @override diff --git a/super_editor/lib/src/default_editor/list_items.dart b/super_editor/lib/src/default_editor/list_items.dart index ca5f83c227..29e4c248f8 100644 --- a/super_editor/lib/src/default_editor/list_items.dart +++ b/super_editor/lib/src/default_editor/list_items.dart @@ -116,13 +116,13 @@ class UnorderedListItemComponent extends StatelessWidget { Widget build(BuildContext context) { final indentSpace = indentExtent * (indent + 1); final firstLineHeight = styleBuilder({}).fontSize; - final manualVerticalAdjustment = 2.0; + const manualVerticalAdjustment = 2.0; return Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( - margin: EdgeInsets.only(top: manualVerticalAdjustment), + margin: const EdgeInsets.only(top: manualVerticalAdjustment), decoration: BoxDecoration( border: Border.all(width: 1, color: showDebugPaint ? Colors.grey : Colors.transparent), ), @@ -203,7 +203,7 @@ class OrderedListItemComponent extends StatelessWidget { Widget build(BuildContext context) { final indentSpace = indentExtent * (indent + 1); final firstLineHeight = styleBuilder({}).fontSize!; - final manualVerticalAdjustment = 2.0; + const manualVerticalAdjustment = 2.0; final manualHeightAdjustment = firstLineHeight * 0.15; return Row( @@ -212,7 +212,7 @@ class OrderedListItemComponent extends StatelessWidget { Container( width: indentSpace, height: firstLineHeight + manualHeightAdjustment, - margin: EdgeInsets.only(top: manualVerticalAdjustment), + margin: const EdgeInsets.only(top: manualVerticalAdjustment), decoration: BoxDecoration( border: Border.all(width: 1, color: showDebugPaint ? Colors.grey : Colors.transparent), ), diff --git a/super_editor/lib/src/default_editor/styles.dart b/super_editor/lib/src/default_editor/styles.dart index 1390a9a5be..322c95fc73 100644 --- a/super_editor/lib/src/default_editor/styles.dart +++ b/super_editor/lib/src/default_editor/styles.dart @@ -3,11 +3,11 @@ import 'dart:ui'; /// The key in the `extensions` map that corresponds to the /// text style builder within the `ComponentContext` that /// is used to build each component in the document layout. -final String textStylesExtensionKey = 'editor.text_styles'; +const String textStylesExtensionKey = 'editor.text_styles'; /// The key in the `extensions` map that corresponds to the /// styles applied to selected content. -final String selectionStylesExtensionKey = 'editor.selection_styles'; +const String selectionStylesExtensionKey = 'editor.selection_styles'; class SelectionStyle { const SelectionStyle({ diff --git a/super_editor/lib/src/default_editor/super_editor.dart b/super_editor/lib/src/default_editor/super_editor.dart index 5380278a8f..b9d1740397 100644 --- a/super_editor/lib/src/default_editor/super_editor.dart +++ b/super_editor/lib/src/default_editor/super_editor.dart @@ -186,7 +186,7 @@ class SuperEditor extends StatefulWidget { /// Paints some extra visual ornamentation to help with /// debugging, when true. - final showDebugPaint; + final bool showDebugPaint; @override _SuperEditorState createState() => _SuperEditorState(); @@ -338,14 +338,14 @@ class _SuperEditorState extends State { } /// Default visual styles related to content selection. -final defaultSelectionStyle = const SelectionStyle( +const defaultSelectionStyle = SelectionStyle( textCaretColor: Colors.black, selectionColor: Color(0xFFACCEF7), ); /// Creates [TextStyles] for the standard [SuperEditor]. TextStyle defaultStyleBuilder(Set attributions) { - TextStyle newStyle = TextStyle( + TextStyle newStyle = const TextStyle( color: Colors.black, fontSize: 13, height: 1.4, diff --git a/super_editor/lib/src/default_editor/text.dart b/super_editor/lib/src/default_editor/text.dart index 98bfa8c768..bd7ed4b1eb 100644 --- a/super_editor/lib/src/default_editor/text.dart +++ b/super_editor/lib/src/default_editor/text.dart @@ -59,7 +59,7 @@ class TextNode with ChangeNotifier implements DocumentNode { Map get metadata => _metadata; @override - TextNodePosition get beginningPosition => TextNodePosition(offset: 0); + TextNodePosition get beginningPosition => const TextNodePosition(offset: 0); @override TextNodePosition get endPosition => TextNodePosition(offset: text.text.length); @@ -111,7 +111,7 @@ class TextNode with ChangeNotifier implements DocumentNode { @override bool hasEquivalentContent(DocumentNode other) { - return other is TextNode && text == other.text && DeepCollectionEquality().equals(metadata, other.metadata); + return other is TextNode && text == other.text && const DeepCollectionEquality().equals(metadata, other.metadata); } @override @@ -256,7 +256,7 @@ class _TextComponentState extends State with DocumentComponent im @override TextNodePosition getBeginningPosition() { - return TextNodePosition(offset: 0); + return const TextNodePosition(offset: 0); } @override @@ -526,7 +526,7 @@ class _TextComponentState extends State with DocumentComponent im key: _selectableTextKey, textSpan: richText, textAlign: widget.textAlign ?? TextAlign.left, - textSelection: widget.textSelection ?? TextSelection.collapsed(offset: -1), + textSelection: widget.textSelection ?? const TextSelection.collapsed(offset: -1), textSelectionDecoration: TextSelectionDecoration(selectionColor: widget.selectionColor), showCaret: widget.showCaret, textCaretFactory: TextCaretFactory(color: widget.caretColor), diff --git a/super_editor/lib/src/default_editor/text_tools.dart b/super_editor/lib/src/default_editor/text_tools.dart index b77a2162c8..5bb1bdd6ec 100644 --- a/super_editor/lib/src/default_editor/text_tools.dart +++ b/super_editor/lib/src/default_editor/text_tools.dart @@ -57,7 +57,7 @@ TextSelection expandPositionToWord({ required TextPosition textPosition, }) { if (text.isEmpty) { - return TextSelection.collapsed(offset: -1); + return const TextSelection.collapsed(offset: -1); } int start = min(textPosition.offset, text.length - 1); @@ -121,7 +121,7 @@ TextSelection expandPositionToParagraph({ required TextPosition textPosition, }) { if (text.isEmpty) { - return TextSelection.collapsed(offset: -1); + return const TextSelection.collapsed(offset: -1); } int start = min(textPosition.offset, text.length - 1); diff --git a/super_editor/lib/src/default_editor/unknown_component.dart b/super_editor/lib/src/default_editor/unknown_component.dart index 0470dd4739..cc12edde5b 100644 --- a/super_editor/lib/src/default_editor/unknown_component.dart +++ b/super_editor/lib/src/default_editor/unknown_component.dart @@ -10,7 +10,7 @@ Widget unknownComponentBuilder(ComponentContext componentContext) { key: componentContext.componentKey, width: double.infinity, height: 100, - child: Placeholder(), + child: const Placeholder(), ); } @@ -22,7 +22,7 @@ Widget unknownComponentBuilder(ComponentContext componentContext) { class UnknownComponent extends StatelessWidget { @override Widget build(BuildContext context) { - return SizedBox( + return const SizedBox( width: double.infinity, height: 54, child: Placeholder(), diff --git a/super_editor/lib/src/infrastructure/_platform_detector_web.dart b/super_editor/lib/src/infrastructure/_platform_detector_web.dart index 190b5399ee..0157067926 100644 --- a/super_editor/lib/src/infrastructure/_platform_detector_web.dart +++ b/super_editor/lib/src/infrastructure/_platform_detector_web.dart @@ -1,3 +1,4 @@ +// ignore: avoid_web_libraries_in_flutter import 'dart:html'; final _platform = window.navigator.platform ?? ''; diff --git a/super_editor/lib/src/infrastructure/attributed_spans.dart b/super_editor/lib/src/infrastructure/attributed_spans.dart index 914ae3f876..981bceb0a2 100644 --- a/super_editor/lib/src/infrastructure/attributed_spans.dart +++ b/super_editor/lib/src/infrastructure/attributed_spans.dart @@ -745,7 +745,7 @@ class AttributedSpans { // Re-insert any markers that are needed to retain // symmetry after the deletions above. - needToStartAttributions.forEach((attribution) { + for (final attribution in needToStartAttributions) { final offset = startOffset > 0 ? startOffset - 1 : 0; _log.log('contractAttributions', 'adding back a start marker at $offset'); contractedAttributions.add(SpanMarker( @@ -753,8 +753,8 @@ class AttributedSpans { offset: offset, markerType: SpanMarkerType.start, )); - }); - needToEndAttributions.forEach((attribution) { + } + for (final attribution in needToEndAttributions) { final offset = startOffset > 0 ? startOffset - 1 : 0; _log.log('contractAttributions', 'adding back an end marker at $offset'); contractedAttributions.add(SpanMarker( @@ -762,7 +762,7 @@ class AttributedSpans { offset: offset, markerType: SpanMarkerType.end, )); - }); + } // Add all remaining markers but with an `offset` // that is less by `count`. @@ -895,7 +895,7 @@ class AttributedSpans { identical(this, other) || other is AttributedSpans && runtimeType == other.runtimeType && - DeepCollectionEquality().equals(_attributions, other._attributions); + const DeepCollectionEquality().equals(_attributions, other._attributions); @override int get hashCode => _attributions.hashCode; diff --git a/super_editor/lib/src/infrastructure/super_selectable_text.dart b/super_editor/lib/src/infrastructure/super_selectable_text.dart index fdc85471fc..3de81ff01d 100644 --- a/super_editor/lib/src/infrastructure/super_selectable_text.dart +++ b/super_editor/lib/src/infrastructure/super_selectable_text.dart @@ -51,7 +51,7 @@ class SuperSelectableText extends StatefulWidget { super(key: key); /// [SuperSelectableText] that displays styled text. - SuperSelectableText({ + const SuperSelectableText({ Key? key, required TextSpan textSpan, this.textAlign = TextAlign.left, @@ -151,7 +151,7 @@ class SuperSelectableTextState extends State implements Tex @override TextPosition getPositionAtOffset(Offset localOffset) { if (_renderParagraph == null) { - return TextPosition(offset: -1); + return const TextPosition(offset: -1); } // TODO: bring back this condition by changing existing uses of @@ -166,7 +166,7 @@ class SuperSelectableTextState extends State implements Tex @override TextPosition getPositionNearestToOffset(Offset localOffset) { if (_renderParagraph == null) { - return TextPosition(offset: -1); + return const TextPosition(offset: -1); } return _renderParagraph!.getPositionForOffset(localOffset); @@ -206,7 +206,7 @@ class SuperSelectableTextState extends State implements Tex @override TextBox getCharacterBox(TextPosition position) { if (_renderParagraph == null) { - return TextBox.fromLTRBD(0, 0, 0, 0, TextDirection.ltr); + return const TextBox.fromLTRBD(0, 0, 0, 0, TextDirection.ltr); } return _renderParagraph! @@ -220,7 +220,7 @@ class SuperSelectableTextState extends State implements Tex @override TextPosition getPositionAtStartOfLine(TextPosition currentPosition) { if (_renderParagraph == null) { - return TextPosition(offset: -1); + return const TextPosition(offset: -1); } final renderParagraph = _renderParagraph!; @@ -234,7 +234,7 @@ class SuperSelectableTextState extends State implements Tex @override TextPosition getPositionAtEndOfLine(TextPosition currentPosition) { if (_renderParagraph == null) { - return TextPosition(offset: -1); + return const TextPosition(offset: -1); } final renderParagraph = _renderParagraph!; @@ -299,7 +299,7 @@ class SuperSelectableTextState extends State implements Tex @override TextPosition getPositionInLastLineAtX(double x) { if (_renderParagraph == null) { - return TextPosition(offset: -1); + return const TextPosition(offset: -1); } return getPositionAtOffset( @@ -309,7 +309,7 @@ class SuperSelectableTextState extends State implements Tex TextSelection getWordSelectionAt(TextPosition position) { if (_renderParagraph == null) { - return TextSelection.collapsed(offset: -1); + return const TextSelection.collapsed(offset: -1); } final wordRange = _renderParagraph!.getWordBoundary(position); @@ -369,7 +369,7 @@ class SuperSelectableTextState extends State implements Tex @override TextSelection getSelectionInRect(Offset baseOffset, Offset extentOffset) { if (_renderParagraph == null) { - return TextSelection.collapsed(offset: -1); + return const TextSelection.collapsed(offset: -1); } final renderParagraph = _renderParagraph!; @@ -427,7 +427,7 @@ class SuperSelectableTextState extends State implements Tex Widget _buildTextSelection() { if (_renderParagraph == null) { - return SizedBox(); + return const SizedBox(); } return widget.textSelectionDecoration.build( @@ -450,7 +450,7 @@ class SuperSelectableTextState extends State implements Tex Widget _buildTextCaret() { if (_renderParagraph == null) { - return SizedBox(); + return const SizedBox(); } return RepaintBoundary( @@ -507,7 +507,7 @@ class _TextSelectionPainter extends CustomPainter { final bool isTextEmpty; final RenderParagraph renderParagraph; final TextSelection selection; - final emptySelectionHeight; + final double emptySelectionHeight; // When true, an empty, collapsed selection will be highlighted // for the purpose of showing a highlighted empty line. final bool highlightWhenEmpty; @@ -520,7 +520,7 @@ class _TextSelectionPainter extends CustomPainter { //&& highlightWhenEmpty) { // This is an empty paragraph, which is selected. Paint a small selection. canvas.drawRect( - Rect.fromLTWH(0, 0, 5, 20), + const Rect.fromLTWH(0, 0, 5, 20), selectionPaint, ); } @@ -824,21 +824,21 @@ class _DebugSelectableTextDecoratorState extends State with final extentOffset = _text.getOffsetAtPosition(selection.extent); - final gutterExtent = 0; // _dragGutterExtent + const gutterExtent = 0; // _dragGutterExtent final myBox = context.findRenderObject() as RenderBox; final beyondLeftExtent = min(extentOffset.dx - widget.scrollController.offset - gutterExtent, 0).abs(); @@ -1006,7 +1006,7 @@ class SuperTextFieldScrollviewState extends State with final extentOffset = _text.getOffsetAtPosition(selection.extent); - final gutterExtent = 0; // _dragGutterExtent + const gutterExtent = 0; // _dragGutterExtent final extentLineIndex = (extentOffset.dy / widget.estimatedLineHeight).round(); final myBox = context.findRenderObject() as RenderBox; @@ -1123,7 +1123,7 @@ class SuperTextFieldScrollviewState extends State with height: widget.viewportHeight, child: SingleChildScrollView( controller: widget.scrollController, - physics: NeverScrollableScrollPhysics(), + physics: const NeverScrollableScrollPhysics(), scrollDirection: widget.isMultiline ? Axis.vertical : Axis.horizontal, child: Padding( padding: widget.padding, @@ -1446,7 +1446,7 @@ class AttributedTextEditingController with ChangeNotifier { AttributedText? text, TextSelection? selection, }) : _text = text ?? AttributedText(), - _selection = selection ?? TextSelection.collapsed(offset: -1); + _selection = selection ?? const TextSelection.collapsed(offset: -1); void updateTextAndSelection({ required AttributedText text, @@ -1496,7 +1496,7 @@ class AttributedTextEditingController with ChangeNotifier { void clear() { _text = AttributedText(); - _selection = TextSelection.collapsed(offset: -1); + _selection = const TextSelection.collapsed(offset: -1); } } diff --git a/super_editor/lib/src/infrastructure/text_layout.dart b/super_editor/lib/src/infrastructure/text_layout.dart index 651947be17..a43c722742 100644 --- a/super_editor/lib/src/infrastructure/text_layout.dart +++ b/super_editor/lib/src/infrastructure/text_layout.dart @@ -114,7 +114,10 @@ int getCharacterEndBounds(String text, int startingCodePointIndex) { // TODO: copy the implementation of nextCharacter to this package because // it's marked as visible for testing - final startOffset = RenderEditable.nextCharacter(startingCodePointIndex, text); + // ignore: invalid_use_of_visible_for_testing_member + final startOffset = + // ignore: invalid_use_of_visible_for_testing_member + RenderEditable.nextCharacter(startingCodePointIndex, text); return startOffset; } @@ -138,6 +141,9 @@ int getCharacterStartBounds(String text, int endingCodePointIndex) { // TODO: copy the implementation of previousCharacter to this package because // it's marked as visible for testing - final startOffset = RenderEditable.previousCharacter(endingCodePointIndex, text); + // ignore: invalid_use_of_visible_for_testing_member + final startOffset = + // ignore: invalid_use_of_visible_for_testing_member + RenderEditable.previousCharacter(endingCodePointIndex, text); return startOffset; } diff --git a/super_editor/lib/src/serialization/markdown.dart b/super_editor/lib/src/serialization/markdown.dart index 1987415db8..aed0891b6e 100644 --- a/super_editor/lib/src/serialization/markdown.dart +++ b/super_editor/lib/src/serialization/markdown.dart @@ -10,7 +10,7 @@ import 'package:markdown/markdown.dart' as md; // requires one. When the editing system matures, there should // be a way to return something here that is not concrete. MutableDocument deserializeMarkdownToDocument(String markdown) { - final markdownLines = LineSplitter().convert(markdown); + final markdownLines = const LineSplitter().convert(markdown); final markdownDoc = md.Document(); final blockParser = md.BlockParser(markdownLines, markdownDoc); diff --git a/super_editor/pubspec.lock b/super_editor/pubspec.lock index 0f8ded994b..fc320fb00e 100644 --- a/super_editor/pubspec.lock +++ b/super_editor/pubspec.lock @@ -93,7 +93,7 @@ packages: source: hosted version: "3.7.0" collection: - dependency: transitive + dependency: "direct main" description: name: collection url: "https://pub.dartlang.org" @@ -146,6 +146,13 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_lints: + dependency: "direct main" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.3" flutter_test: dependency: "direct dev" description: flutter @@ -179,6 +186,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.0.0" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" logging: dependency: transitive description: @@ -229,7 +243,7 @@ packages: source: hosted version: "1.8.0" pedantic: - dependency: "direct main" + dependency: transitive description: name: pedantic url: "https://pub.dartlang.org" @@ -260,7 +274,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: diff --git a/super_editor/pubspec.yaml b/super_editor/pubspec.yaml index 480d76c77a..2e807da6f6 100644 --- a/super_editor/pubspec.yaml +++ b/super_editor/pubspec.yaml @@ -17,7 +17,7 @@ dependencies: # TODO: move markdown serialization to a separate package and # then remove this dependency. markdown: ^4.0.0 - pedantic: ^1.11.0 + flutter_lints: ^1.0.0 uuid: ^3.0.3 dev_dependencies: diff --git a/super_editor/test/editor_smoke_tests/editor_entry_smoke_test.dart b/super_editor/test/editor_smoke_tests/editor_entry_smoke_test.dart index 374170014e..5589bc737c 100644 --- a/super_editor/test/editor_smoke_tests/editor_entry_smoke_test.dart +++ b/super_editor/test/editor_smoke_tests/editor_entry_smoke_test.dart @@ -35,7 +35,7 @@ void main() { ); final composer = DocumentComposer(); final layoutKey = GlobalKey(); - final documentLayoutResolver = () => layoutKey.currentState as DocumentLayout; + DocumentLayout documentLayoutResolver() => layoutKey.currentState as DocumentLayout; final commonOps = CommonEditorOperations( editor: documentEditor, composer: composer, @@ -58,17 +58,17 @@ void main() { composer.selection = DocumentSelection.collapsed( position: DocumentPosition( nodeId: documentEditor.document.nodes.first.id, - nodePosition: TextNodePosition(offset: 0), + nodePosition: const TextNodePosition(offset: 0), )); - final header = 'Smoke Test'; + const header = 'Smoke Test'; for (final character in header.characters) { commonOps.insertCharacter(character); } commonOps.insertBlockLevelNewline(); - final p1 = + const p1 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus sed sagittis urna. Aenean mattis ante justo, quis sollicitudin metus interdum id.'; for (final character in p1.characters) { commonOps.insertCharacter(character); diff --git a/super_editor/test/serialization/markdown_test.dart b/super_editor/test/serialization/markdown_test.dart index 8d3d6ec918..10704e893a 100644 --- a/super_editor/test/serialization/markdown_test.dart +++ b/super_editor/test/serialization/markdown_test.dart @@ -42,8 +42,8 @@ void main() { text: 'My Header', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: boldAttribution, offset: 3, markerType: SpanMarkerType.start), - SpanMarker(attribution: boldAttribution, offset: 8, markerType: SpanMarkerType.end), + const SpanMarker(attribution: boldAttribution, offset: 3, markerType: SpanMarkerType.start), + const SpanMarker(attribution: boldAttribution, offset: 8, markerType: SpanMarkerType.end), ], ), ), @@ -74,8 +74,8 @@ void main() { text: 'This is a blockquote', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: boldAttribution, offset: 10, markerType: SpanMarkerType.start), - SpanMarker(attribution: boldAttribution, offset: 19, markerType: SpanMarkerType.end), + const SpanMarker(attribution: boldAttribution, offset: 10, markerType: SpanMarkerType.start), + const SpanMarker(attribution: boldAttribution, offset: 19, markerType: SpanMarkerType.end), ], ), ), @@ -123,8 +123,8 @@ This is some code text: 'This is a paragraph.', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: boldAttribution, offset: 5, markerType: SpanMarkerType.start), - SpanMarker(attribution: boldAttribution, offset: 8, markerType: SpanMarkerType.end), + const SpanMarker(attribution: boldAttribution, offset: 5, markerType: SpanMarkerType.start), + const SpanMarker(attribution: boldAttribution, offset: 8, markerType: SpanMarkerType.end), ], ), ), @@ -142,10 +142,10 @@ This is some code text: 'This is a paragraph.', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: boldAttribution, offset: 5, markerType: SpanMarkerType.start), - SpanMarker(attribution: boldAttribution, offset: 8, markerType: SpanMarkerType.end), - SpanMarker(attribution: italicsAttribution, offset: 5, markerType: SpanMarkerType.start), - SpanMarker(attribution: italicsAttribution, offset: 8, markerType: SpanMarkerType.end), + const SpanMarker(attribution: boldAttribution, offset: 5, markerType: SpanMarkerType.start), + const SpanMarker(attribution: boldAttribution, offset: 8, markerType: SpanMarkerType.end), + const SpanMarker(attribution: italicsAttribution, offset: 5, markerType: SpanMarkerType.start), + const SpanMarker(attribution: italicsAttribution, offset: 8, markerType: SpanMarkerType.end), ], ), ), @@ -163,10 +163,10 @@ This is some code text: 'This is a paragraph.', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: boldAttribution, offset: 5, markerType: SpanMarkerType.start), - SpanMarker(attribution: boldAttribution, offset: 8, markerType: SpanMarkerType.end), - SpanMarker(attribution: codeAttribution, offset: 5, markerType: SpanMarkerType.start), - SpanMarker(attribution: codeAttribution, offset: 8, markerType: SpanMarkerType.end), + const SpanMarker(attribution: boldAttribution, offset: 5, markerType: SpanMarkerType.start), + const SpanMarker(attribution: boldAttribution, offset: 8, markerType: SpanMarkerType.end), + const SpanMarker(attribution: codeAttribution, offset: 5, markerType: SpanMarkerType.start), + const SpanMarker(attribution: codeAttribution, offset: 8, markerType: SpanMarkerType.end), ], ), ), @@ -249,8 +249,8 @@ This is some code text: 'Unordered 1', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: boldAttribution, offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: boldAttribution, offset: 8, markerType: SpanMarkerType.end), + const SpanMarker(attribution: boldAttribution, offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: boldAttribution, offset: 8, markerType: SpanMarkerType.end), ], ), ), @@ -311,8 +311,8 @@ This is some code text: 'Ordered 1', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: boldAttribution, offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: boldAttribution, offset: 6, markerType: SpanMarkerType.end), + const SpanMarker(attribution: boldAttribution, offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: boldAttribution, offset: 6, markerType: SpanMarkerType.end), ], ), ), @@ -440,7 +440,7 @@ This is some code }); test('single unstyled paragraph', () { - final markdown = 'This is some unstyled text to parse as markdown'; + const markdown = 'This is some unstyled text to parse as markdown'; final document = deserializeMarkdownToDocument(markdown); @@ -452,7 +452,7 @@ This is some code }); test('single styled paragraph', () { - final markdown = 'This is **some *styled*** text to parse as markdown'; + const markdown = 'This is **some *styled*** text to parse as markdown'; final document = deserializeMarkdownToDocument(markdown); @@ -470,7 +470,7 @@ This is some code }); test('unordered list', () { - final markdown = ''' + const markdown = ''' * list item 1 * list item 2 * list item 2.1 @@ -493,7 +493,7 @@ This is some code }); test('ordered list', () { - final markdown = ''' + const markdown = ''' 1. list item 1 1. list item 2 1. list item 2.1 @@ -549,7 +549,7 @@ This is some code }); } -final exampleMarkdownDoc1 = ''' +const exampleMarkdownDoc1 = ''' # Example 1 --- This is an example doc that has various types of nodes. diff --git a/super_editor/test/src/_document_test_tools.dart b/super_editor/test/src/_document_test_tools.dart index f77eb51c3c..569c19c1b9 100644 --- a/super_editor/test/src/_document_test_tools.dart +++ b/super_editor/test/src/_document_test_tools.dart @@ -15,7 +15,7 @@ EditContext createEditContext({ CommonEditorOperations? commonOps, }) { final editor = documentEditor ?? DocumentEditor(document: document); - final layoutResolver = () => documentLayout ?? FakeDocumentLayout(); + DocumentLayout layoutResolver() => documentLayout ?? FakeDocumentLayout(); final composer = documentComposer ?? DocumentComposer(); return EditContext( diff --git a/super_editor/test/src/default_editor/attributions_test.dart b/super_editor/test/src/default_editor/attributions_test.dart index cecc44121d..3360424ac7 100644 --- a/super_editor/test/src/default_editor/attributions_test.dart +++ b/super_editor/test/src/default_editor/attributions_test.dart @@ -16,7 +16,7 @@ void main() { // Add link across "one two" text.addAttribution( LinkAttribution(url: Uri.parse('https://flutter.dev')), - TextRange(start: 0, end: 6), + const TextRange(start: 0, end: 6), ); // Try to add a different link across "two three" and expect @@ -24,7 +24,7 @@ void main() { expect(() { text.addAttribution( LinkAttribution(url: Uri.parse('https://pub.dev')), - TextRange(start: 4, end: 12), + const TextRange(start: 4, end: 12), ); }, throwsA(isA())); }); @@ -39,12 +39,12 @@ void main() { // Add link across "one two" text.addAttribution( linkAttribution, - TextRange(start: 0, end: 6), + const TextRange(start: 0, end: 6), ); text.addAttribution( LinkAttribution(url: Uri.parse('https://flutter.dev')), - TextRange(start: 4, end: 12), + const TextRange(start: 4, end: 12), ); expect(text.spans.hasAttributionsWithin(attributions: {linkAttribution}, start: 0, end: 12), true); diff --git a/super_editor/test/src/default_editor/document_keyboard_actions_test.dart b/super_editor/test/src/default_editor/document_keyboard_actions_test.dart index e22eb4c95d..a9fbd74fca 100644 --- a/super_editor/test/src/default_editor/document_keyboard_actions_test.dart +++ b/super_editor/test/src/default_editor/document_keyboard_actions_test.dart @@ -30,7 +30,7 @@ void main() { final _editContext = createEditContext(document: MutableDocument()); var result = selectAllWhenCmdAIsPressed( editContext: _editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.meta, physicalKey: PhysicalKeyboardKey.keyC, @@ -56,7 +56,7 @@ void main() { final _editContext = createEditContext(document: MutableDocument()); var result = selectAllWhenCmdAIsPressed( editContext: _editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, physicalKey: PhysicalKeyboardKey.keyA, @@ -82,7 +82,7 @@ void main() { final _editContext = createEditContext(document: MutableDocument()); var result = selectAllWhenCmdAIsPressed( editContext: _editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.meta, physicalKey: PhysicalKeyboardKey.keyA, @@ -116,7 +116,7 @@ void main() { ); var result = selectAllWhenCmdAIsPressed( editContext: _editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.meta, physicalKey: PhysicalKeyboardKey.keyA, @@ -130,14 +130,14 @@ void main() { expect(result, ExecutionInstruction.haltExecution); expect( _editContext.composer.selection!.base, - DocumentPosition( + const DocumentPosition( nodeId: 'paragraph', nodePosition: TextNodePosition(offset: 0), ), ); expect( _editContext.composer.selection!.extent, - DocumentPosition( + const DocumentPosition( nodeId: 'paragraph', nodePosition: TextNodePosition(offset: 'This is some text'.length), ), @@ -167,7 +167,7 @@ void main() { ); var result = selectAllWhenCmdAIsPressed( editContext: _editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.meta, physicalKey: PhysicalKeyboardKey.keyA, @@ -181,14 +181,14 @@ void main() { expect(result, ExecutionInstruction.haltExecution); expect( _editContext.composer.selection!.base, - DocumentPosition( + const DocumentPosition( nodeId: 'paragraph_1', nodePosition: TextNodePosition(offset: 0), ), ); expect( _editContext.composer.selection!.extent, - DocumentPosition( + const DocumentPosition( nodeId: 'paragraph_2', nodePosition: TextNodePosition(offset: 'This is some text'.length), ), @@ -222,7 +222,7 @@ void main() { ); var result = selectAllWhenCmdAIsPressed( editContext: _editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.meta, physicalKey: PhysicalKeyboardKey.keyA, @@ -236,14 +236,14 @@ void main() { expect(result, ExecutionInstruction.haltExecution); expect( _editContext.composer.selection!.base, - DocumentPosition( + const DocumentPosition( nodeId: 'image_1', nodePosition: BinaryNodePosition.included(), ), ); expect( _editContext.composer.selection!.extent, - DocumentPosition( + const DocumentPosition( nodeId: 'image_2', nodePosition: BinaryNodePosition.included(), ), diff --git a/super_editor/test/src/default_editor/text_test.dart b/super_editor/test/src/default_editor/text_test.dart index fa2060d301..d39ff6d91c 100644 --- a/super_editor/test/src/default_editor/text_test.dart +++ b/super_editor/test/src/default_editor/text_test.dart @@ -33,11 +33,11 @@ void main() { final command = ToggleTextAttributionsCommand( documentSelection: DocumentSelection( - base: DocumentPosition( + base: const DocumentPosition( nodeId: 'paragraph', nodePosition: TextNodePosition(offset: 1), ), - extent: DocumentPosition( + extent: const DocumentPosition( nodeId: 'paragraph', // IMPORTANT: we want to end the bold at the 'd' character but // the TextPosition indexes the ' ' after the 'd'. This is because @@ -67,7 +67,7 @@ void main() { // Press just the meta key. var result = anyCharacterToInsertInTextContent( editContext: editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.meta, physicalKey: PhysicalKeyboardKey.metaLeft, @@ -83,7 +83,7 @@ void main() { // Press "a" + meta key result = anyCharacterToInsertInTextContent( editContext: editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, physicalKey: PhysicalKeyboardKey.keyA, @@ -103,7 +103,7 @@ void main() { // Try to type a character. var result = anyCharacterToInsertInTextContent( editContext: editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, physicalKey: PhysicalKeyboardKey.keyA, @@ -128,11 +128,11 @@ void main() { // Select multiple characters in the paragraph editContext.composer.selection = DocumentSelection( - base: DocumentPosition( + base: const DocumentPosition( nodeId: 'paragraph', nodePosition: TextNodePosition(offset: 0), ), - extent: DocumentPosition( + extent: const DocumentPosition( nodeId: 'paragraph', nodePosition: TextNodePosition(offset: 1), ), @@ -141,7 +141,7 @@ void main() { // Try to type a character. var result = anyCharacterToInsertInTextContent( editContext: editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, physicalKey: PhysicalKeyboardKey.keyA, @@ -162,7 +162,7 @@ void main() { ); // Select the horizontal rule node. - editContext.composer.selection = DocumentSelection.collapsed( + editContext.composer.selection = const DocumentSelection.collapsed( position: DocumentPosition( nodeId: 'horizontal_rule', nodePosition: BinaryNodePosition.notIncluded(), @@ -172,7 +172,7 @@ void main() { // Try to type a character. var result = anyCharacterToInsertInTextContent( editContext: editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, physicalKey: PhysicalKeyboardKey.keyA, @@ -196,7 +196,7 @@ void main() { ); // Select multiple characters in the paragraph - editContext.composer.selection = DocumentSelection.collapsed( + editContext.composer.selection = const DocumentSelection.collapsed( position: DocumentPosition( nodeId: 'paragraph', nodePosition: TextNodePosition(offset: 0), @@ -206,7 +206,7 @@ void main() { // Press the "alt" key var result = anyCharacterToInsertInTextContent( editContext: editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( character: null, data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.alt, @@ -222,7 +222,7 @@ void main() { // Press the "enter" key result = anyCharacterToInsertInTextContent( editContext: editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( character: '', // Empirically, pressing enter sends '' as the character instead of null data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.enter, @@ -247,7 +247,7 @@ void main() { ); // Select multiple characters in the paragraph - editContext.composer.selection = DocumentSelection.collapsed( + editContext.composer.selection = const DocumentSelection.collapsed( position: DocumentPosition( nodeId: 'paragraph', nodePosition: TextNodePosition(offset: 0), @@ -257,7 +257,7 @@ void main() { // Press the "a" key var result = anyCharacterToInsertInTextContent( editContext: editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( character: 'a', data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, @@ -286,7 +286,7 @@ void main() { ); // Select multiple characters in the paragraph - editContext.composer.selection = DocumentSelection.collapsed( + editContext.composer.selection = const DocumentSelection.collapsed( position: DocumentPosition( nodeId: 'paragraph', nodePosition: TextNodePosition(offset: 0), @@ -296,7 +296,7 @@ void main() { // Type a non-English character var result = anyCharacterToInsertInTextContent( editContext: editContext, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( character: 'ß', data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, diff --git a/super_editor/test/src/infrastructure/attributed_spans_test.dart b/super_editor/test/src/infrastructure/attributed_spans_test.dart index 7935d337b7..54eed0c3e1 100644 --- a/super_editor/test/src/infrastructure/attributed_spans_test.dart +++ b/super_editor/test/src/infrastructure/attributed_spans_test.dart @@ -2,9 +2,9 @@ import 'package:super_editor/src/infrastructure/attributed_spans.dart'; import 'package:flutter_test/flutter_test.dart'; // Attributions used throughout this test suite. -final bold = NamedAttribution('bold'); -final italics = NamedAttribution('italics'); -final strikethrough = NamedAttribution('strikethrough'); +const bold = NamedAttribution('bold'); +const italics = NamedAttribution('italics'); +const strikethrough = NamedAttribution('strikethrough'); void main() { group('Spans', () { @@ -16,7 +16,7 @@ void main() { expect( expandedSpan, equals( - AttributionSpan( + const AttributionSpan( attribution: bold, start: 3, end: 16, @@ -39,7 +39,7 @@ void main() { expect( attributionSpans.first, equals( - AttributionSpan( + const AttributionSpan( attribution: bold, start: 5, end: 10, @@ -62,7 +62,7 @@ void main() { expect( attributionSpans.first, equals( - AttributionSpan( + const AttributionSpan( attribution: bold, start: 3, end: 7, @@ -72,7 +72,7 @@ void main() { expect( attributionSpans.last, equals( - AttributionSpan( + const AttributionSpan( attribution: bold, start: 10, end: 15, @@ -93,7 +93,7 @@ void main() { expect( attributionSpans.first, equals( - AttributionSpan( + const AttributionSpan( attribution: bold, start: 0, end: 10, @@ -117,7 +117,7 @@ void main() { expect( attributionSpans.first, equals( - AttributionSpan( + const AttributionSpan( attribution: bold, start: 5, end: 7, @@ -127,7 +127,7 @@ void main() { expect( attributionSpans.last, equals( - AttributionSpan( + const AttributionSpan( attribution: bold, start: 10, end: 12, @@ -149,7 +149,7 @@ void main() { expect( attributionSpans.first, equals( - AttributionSpan( + const AttributionSpan( attribution: bold, start: 3, end: 8, @@ -196,8 +196,8 @@ void main() { test('removes attribution from full span', () { final spans = AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 16, markerType: SpanMarkerType.end) + const SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 16, markerType: SpanMarkerType.end) ], )..removeAttribution(attributionToRemove: bold, start: 0, end: 16); @@ -207,8 +207,8 @@ void main() { test('removes attribution from inner text span', () { final spans = AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 2, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 7, markerType: SpanMarkerType.end) + const SpanMarker(attribution: bold, offset: 2, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 7, markerType: SpanMarkerType.end) ], )..removeAttribution(attributionToRemove: bold, start: 2, end: 7); @@ -218,8 +218,8 @@ void main() { test('removes attribution from partial beginning span', () { final spans = AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 2, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 7, markerType: SpanMarkerType.end) + const SpanMarker(attribution: bold, offset: 2, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 7, markerType: SpanMarkerType.end) ], )..removeAttribution(attributionToRemove: bold, start: 2, end: 4); @@ -229,8 +229,8 @@ void main() { test('removes attribution from partial inner span', () { final spans = AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 2, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 7, markerType: SpanMarkerType.end) + const SpanMarker(attribution: bold, offset: 2, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 7, markerType: SpanMarkerType.end) ], )..removeAttribution(attributionToRemove: bold, start: 4, end: 5); @@ -241,8 +241,8 @@ void main() { test('removes attribution from partial ending span', () { final spans = AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 2, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 7, markerType: SpanMarkerType.end) + const SpanMarker(attribution: bold, offset: 2, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 7, markerType: SpanMarkerType.end) ], )..removeAttribution(attributionToRemove: bold, start: 5, end: 7); @@ -252,8 +252,8 @@ void main() { test('applies attribution when mixed span is toggled', () { final spans = AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 8, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 16, markerType: SpanMarkerType.end) + const SpanMarker(attribution: bold, offset: 8, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 16, markerType: SpanMarkerType.end) ], )..toggleAttribution(attribution: bold, start: 0, end: 16); @@ -263,8 +263,8 @@ void main() { test('removes attribution when contiguous span is toggled', () { final spans = AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 16, markerType: SpanMarkerType.end) + const SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 16, markerType: SpanMarkerType.end) ], )..toggleAttribution(attribution: bold, start: 0, end: 16); @@ -386,8 +386,8 @@ void main() { test('single continuous attribution', () { final collapsedSpans = AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 16, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 16, markerType: SpanMarkerType.end), ], ).collapseSpans(contentLength: 17); @@ -401,10 +401,10 @@ void main() { test('single fractured attribution', () { final collapsedSpans = AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 3, markerType: SpanMarkerType.end), - SpanMarker(attribution: bold, offset: 7, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 10, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 3, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 7, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 10, markerType: SpanMarkerType.end), ], ).collapseSpans(contentLength: 17); @@ -428,10 +428,10 @@ void main() { test('multiple non-overlapping attributions', () { final collapsedSpans = AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 3, markerType: SpanMarkerType.end), - SpanMarker(attribution: italics, offset: 7, markerType: SpanMarkerType.start), - SpanMarker(attribution: italics, offset: 10, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 3, markerType: SpanMarkerType.end), + const SpanMarker(attribution: italics, offset: 7, markerType: SpanMarkerType.start), + const SpanMarker(attribution: italics, offset: 10, markerType: SpanMarkerType.end), ], ).collapseSpans(contentLength: 17); @@ -455,10 +455,10 @@ void main() { test('multiple overlapping attributions', () { final collapsedSpans = AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 8, markerType: SpanMarkerType.end), - SpanMarker(attribution: italics, offset: 6, markerType: SpanMarkerType.start), - SpanMarker(attribution: italics, offset: 16, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 8, markerType: SpanMarkerType.end), + const SpanMarker(attribution: italics, offset: 6, markerType: SpanMarkerType.start), + const SpanMarker(attribution: italics, offset: 16, markerType: SpanMarkerType.end), ], ).collapseSpans(contentLength: 17); diff --git a/super_editor/test/src/infrastructure/attributed_text_test.dart b/super_editor/test/src/infrastructure/attributed_text_test.dart index 7613819724..b3f3d1f7a0 100644 --- a/super_editor/test/src/infrastructure/attributed_text_test.dart +++ b/super_editor/test/src/infrastructure/attributed_text_test.dart @@ -4,9 +4,9 @@ import 'package:super_editor/src/infrastructure/attributed_text.dart'; import 'package:flutter_test/flutter_test.dart'; // Attributions used throughout this test suite. -final bold = NamedAttribution('bold'); -final italics = NamedAttribution('italics'); -final strikethrough = NamedAttribution('strikethrough'); +const bold = NamedAttribution('bold'); +const italics = NamedAttribution('italics'); +const strikethrough = NamedAttribution('strikethrough'); void main() { group('Attributed Text', () { @@ -25,8 +25,8 @@ void main() { text: 'abcdefghij', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 9, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 9, markerType: SpanMarkerType.end), ], ), ); @@ -42,8 +42,8 @@ void main() { text: 'abcdefghij', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 1, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 1, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 1, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 1, markerType: SpanMarkerType.end), ], ), ); @@ -66,8 +66,8 @@ void main() { // Notice that the markers are provided in reverse order: // end then start. Order shouldn't matter within a single // position index. This test ensures that. - SpanMarker(attribution: bold, offset: 1, markerType: SpanMarkerType.end), - SpanMarker(attribution: bold, offset: 1, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 1, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 1, markerType: SpanMarkerType.start), ], ), ); @@ -84,7 +84,7 @@ void main() { test('add single character style', () { final text = AttributedText(text: 'abcdefghij'); - text.addAttribution(bold, TextRange(start: 1, end: 1)); + text.addAttribution(bold, const TextRange(start: 1, end: 1)); final textSpan = text.computeTextSpan(_styleBuilder); expect(textSpan.text, null); @@ -101,8 +101,8 @@ void main() { text: 'abcdefghij', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 2, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 7, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 2, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 7, markerType: SpanMarkerType.end), ], ), ); @@ -121,8 +121,8 @@ void main() { text: 'abcdefghij', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 9, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 9, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 9, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 9, markerType: SpanMarkerType.end), ], ), ); @@ -131,8 +131,8 @@ void main() { text: 'k', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.end), ], ), )); @@ -156,8 +156,8 @@ void main() { text: 'abcdefghij', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 9, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 9, markerType: SpanMarkerType.end), ], ), ); @@ -170,7 +170,7 @@ void main() { expect(newText.text, 'aabcdefghij'); expect( - newText.hasAttributionsWithin(attributions: {bold}, range: TextRange(start: 0, end: 10)), + newText.hasAttributionsWithin(attributions: {bold}, range: const TextRange(start: 0, end: 10)), true, ); }); @@ -180,10 +180,10 @@ void main() { text: 'abcdefghij', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 4, markerType: SpanMarkerType.end), - SpanMarker(attribution: italics, offset: 5, markerType: SpanMarkerType.start), - SpanMarker(attribution: italics, offset: 9, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 0, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 4, markerType: SpanMarkerType.end), + const SpanMarker(attribution: italics, offset: 5, markerType: SpanMarkerType.start), + const SpanMarker(attribution: italics, offset: 9, markerType: SpanMarkerType.end), ], ), ); @@ -204,10 +204,10 @@ void main() { text: 'abcdefghij', spans: AttributedSpans( attributions: [ - SpanMarker(attribution: bold, offset: 2, markerType: SpanMarkerType.start), - SpanMarker(attribution: italics, offset: 4, markerType: SpanMarkerType.start), - SpanMarker(attribution: bold, offset: 5, markerType: SpanMarkerType.end), - SpanMarker(attribution: italics, offset: 7, markerType: SpanMarkerType.end), + const SpanMarker(attribution: bold, offset: 2, markerType: SpanMarkerType.start), + const SpanMarker(attribution: italics, offset: 4, markerType: SpanMarkerType.start), + const SpanMarker(attribution: bold, offset: 5, markerType: SpanMarkerType.end), + const SpanMarker(attribution: italics, offset: 7, markerType: SpanMarkerType.end), ], ), ); @@ -244,7 +244,7 @@ void main() { listenerCalled = true; }); - text.addAttribution(bold, TextRange(start: 1, end: 1)); + text.addAttribution(bold, const TextRange(start: 1, end: 1)); expect(listenerCalled, isTrue); }); diff --git a/super_editor/test/src/infrastructure/super_textfield_test.dart b/super_editor/test/src/infrastructure/super_textfield_test.dart index deb7f1c03f..9377831935 100644 --- a/super_editor/test/src/infrastructure/super_textfield_test.dart +++ b/super_editor/test/src/infrastructure/super_textfield_test.dart @@ -22,7 +22,7 @@ void main() { // Note: this is a widget test because we access the Clipboard. final controller = AttributedTextEditingController( text: AttributedText(text: 'This is some text'), - selection: TextSelection( + selection: const TextSelection( baseOffset: 5, extentOffset: 12, ), @@ -40,7 +40,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.copyTextWhenCmdCIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyC, physicalKey: PhysicalKeyboardKey.keyC, @@ -63,7 +63,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.copyTextWhenCmdCIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyC, physicalKey: PhysicalKeyboardKey.keyC, @@ -85,7 +85,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.copyTextWhenCmdCIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyC, physicalKey: PhysicalKeyboardKey.keyC, @@ -106,7 +106,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.copyTextWhenCmdCIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.metaLeft, physicalKey: PhysicalKeyboardKey.metaLeft, @@ -129,7 +129,7 @@ void main() { // Note: this is a widget test because we access the Clipboard. final controller = AttributedTextEditingController( text: AttributedText(text: 'This is some text'), - selection: TextSelection( + selection: const TextSelection( baseOffset: 5, extentOffset: 12, ), @@ -147,7 +147,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.copyTextWhenCmdCIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyC, physicalKey: PhysicalKeyboardKey.keyC, @@ -170,7 +170,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.copyTextWhenCmdCIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyC, physicalKey: PhysicalKeyboardKey.keyC, @@ -192,7 +192,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.copyTextWhenCmdCIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyC, physicalKey: PhysicalKeyboardKey.keyC, @@ -213,7 +213,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.copyTextWhenCmdCIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.metaLeft, physicalKey: PhysicalKeyboardKey.metaLeft, @@ -238,7 +238,7 @@ void main() { // Note: this is a widget test because we access the Clipboard. final controller = AttributedTextEditingController( text: AttributedText(text: 'Pasted content: '), - selection: TextSelection.collapsed(offset: 16), + selection: const TextSelection.collapsed(offset: 16), ); // The Clipboard requires a platform response, which doesn't exist @@ -254,7 +254,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.pasteTextWhenCmdVIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyV, physicalKey: PhysicalKeyboardKey.keyV, @@ -284,7 +284,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.pasteTextWhenCmdVIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyV, physicalKey: PhysicalKeyboardKey.keyV, @@ -306,7 +306,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.pasteTextWhenCmdVIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyV, physicalKey: PhysicalKeyboardKey.keyV, @@ -328,7 +328,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.pasteTextWhenCmdVIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.metaLeft, physicalKey: PhysicalKeyboardKey.metaLeft, @@ -351,7 +351,7 @@ void main() { // Note: this is a widget test because we access the Clipboard. final controller = AttributedTextEditingController( text: AttributedText(text: 'Pasted content: '), - selection: TextSelection.collapsed(offset: 16), + selection: const TextSelection.collapsed(offset: 16), ); // The Clipboard requires a platform response, which doesn't exist @@ -367,7 +367,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.pasteTextWhenCmdVIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyV, physicalKey: PhysicalKeyboardKey.keyV, @@ -397,7 +397,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.pasteTextWhenCmdVIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyV, physicalKey: PhysicalKeyboardKey.keyV, @@ -419,7 +419,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.pasteTextWhenCmdVIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyV, physicalKey: PhysicalKeyboardKey.keyV, @@ -441,7 +441,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.pasteTextWhenCmdVIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.metaLeft, physicalKey: PhysicalKeyboardKey.metaLeft, @@ -465,12 +465,12 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'this is some text'), - selection: TextSelection.collapsed(offset: 5), + selection: const TextSelection.collapsed(offset: 5), ); final result = DefaultSuperTextFieldKeyboardHandlers.selectAllTextFieldWhenCmdAIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, physicalKey: PhysicalKeyboardKey.keyA, @@ -494,7 +494,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.selectAllTextFieldWhenCmdAIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, physicalKey: PhysicalKeyboardKey.keyA, @@ -516,7 +516,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.selectAllTextFieldWhenCmdAIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, physicalKey: PhysicalKeyboardKey.keyA, @@ -538,7 +538,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.selectAllTextFieldWhenCmdAIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.metaLeft, physicalKey: PhysicalKeyboardKey.metaLeft, @@ -560,12 +560,12 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'this is some text'), - selection: TextSelection.collapsed(offset: 5), + selection: const TextSelection.collapsed(offset: 5), ); final result = DefaultSuperTextFieldKeyboardHandlers.selectAllTextFieldWhenCmdAIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, physicalKey: PhysicalKeyboardKey.keyA, @@ -589,7 +589,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.selectAllTextFieldWhenCmdAIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, physicalKey: PhysicalKeyboardKey.keyA, @@ -611,7 +611,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.selectAllTextFieldWhenCmdAIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyA, physicalKey: PhysicalKeyboardKey.keyA, @@ -633,7 +633,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.selectAllTextFieldWhenCmdAIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.metaLeft, physicalKey: PhysicalKeyboardKey.metaLeft, @@ -655,7 +655,7 @@ void main() { testWidgets('it does nothing at beginning of text blob', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 0), + selection: const TextSelection.collapsed(offset: 0), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -664,7 +664,7 @@ void main() { final characterResult = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -681,7 +681,7 @@ void main() { final wordResult = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -699,7 +699,7 @@ void main() { final lineResult = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -717,7 +717,7 @@ void main() { testWidgets('it moves left by character', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 2), + selection: const TextSelection.collapsed(offset: 2), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -725,7 +725,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -744,7 +744,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 18), + selection: const TextSelection.collapsed(offset: 18), ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -752,7 +752,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -775,14 +775,14 @@ void main() { // We give a tiny bit of wiggle room on the value because when this test // is run on Windows and Linux CI, there is some kind of precision error // that results in a tiny positive number instead of zero. - expect(selectableTextState.getCharacterBox(TextPosition(offset: 16)).top, lessThan(0.1)); - expect(selectableTextState.getCharacterBox(TextPosition(offset: 16)).top, greaterThanOrEqualTo(0)); + expect(selectableTextState.getCharacterBox(const TextPosition(offset: 16)).top, lessThan(0.1)); + expect(selectableTextState.getCharacterBox(const TextPosition(offset: 16)).top, greaterThanOrEqualTo(0)); }); testWidgets('it expands left by character', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 2), + selection: const TextSelection.collapsed(offset: 2), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -790,7 +790,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -809,7 +809,7 @@ void main() { testWidgets('it moves left by word', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 10), + selection: const TextSelection.collapsed(offset: 10), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -817,7 +817,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -835,7 +835,7 @@ void main() { testWidgets('it expands left by word', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 10), + selection: const TextSelection.collapsed(offset: 10), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -843,7 +843,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -865,7 +865,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 10), + selection: const TextSelection.collapsed(offset: 10), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -873,7 +873,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -895,7 +895,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 10), + selection: const TextSelection.collapsed(offset: 10), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -903,7 +903,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -925,7 +925,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 10), + selection: const TextSelection.collapsed(offset: 10), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -933,7 +933,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -957,7 +957,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 10), + selection: const TextSelection.collapsed(offset: 10), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -965,7 +965,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -987,7 +987,7 @@ void main() { testWidgets('it collapses downstream selection on left side', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection( + selection: const TextSelection( baseOffset: 6, extentOffset: 10, ), @@ -998,7 +998,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -1015,7 +1015,7 @@ void main() { testWidgets('it collapses upstream selection on left side', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection( + selection: const TextSelection( baseOffset: 10, extentOffset: 6, ), @@ -1026,7 +1026,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowLeft, physicalKey: PhysicalKeyboardKey.arrowLeft, @@ -1045,7 +1045,7 @@ void main() { testWidgets('it does nothing at end of text blob', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 16), + selection: const TextSelection.collapsed(offset: 16), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1054,7 +1054,7 @@ void main() { final characterResult = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1071,7 +1071,7 @@ void main() { final wordResult = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1089,7 +1089,7 @@ void main() { final lineResult = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1107,7 +1107,7 @@ void main() { testWidgets('it moves right by character', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 2), + selection: const TextSelection.collapsed(offset: 2), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1115,7 +1115,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1134,7 +1134,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 17), + selection: const TextSelection.collapsed(offset: 17), ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1142,7 +1142,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1158,13 +1158,13 @@ void main() { // We should have gone from line 1 to line 2. Make double sure by // checking that the bounding box for the character that's now selected // does not sit at the top of the text box. - expect(selectableTextState.getCharacterBox(TextPosition(offset: 18)).top, isNonZero); + expect(selectableTextState.getCharacterBox(const TextPosition(offset: 18)).top, isNonZero); }); testWidgets('it expands right by character', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 2), + selection: const TextSelection.collapsed(offset: 2), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1172,7 +1172,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1191,7 +1191,7 @@ void main() { testWidgets('it moves right by word', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 6), + selection: const TextSelection.collapsed(offset: 6), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1199,7 +1199,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1217,7 +1217,7 @@ void main() { testWidgets('it expands right by word', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 6), + selection: const TextSelection.collapsed(offset: 6), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1225,7 +1225,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1247,7 +1247,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 6), + selection: const TextSelection.collapsed(offset: 6), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1255,7 +1255,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1277,7 +1277,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 6), + selection: const TextSelection.collapsed(offset: 6), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1285,7 +1285,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1307,7 +1307,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 6), + selection: const TextSelection.collapsed(offset: 6), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1315,7 +1315,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1339,7 +1339,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection.collapsed(offset: 6), + selection: const TextSelection.collapsed(offset: 6), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1347,7 +1347,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1369,7 +1369,7 @@ void main() { testWidgets('it collapses downstream selection on right side', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection( + selection: const TextSelection( baseOffset: 6, extentOffset: 10, ), @@ -1380,7 +1380,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1397,7 +1397,7 @@ void main() { testWidgets('it collapses upstream selection on right side', (tester) async { final controller = AttributedTextEditingController( text: AttributedText(text: 'super text field'), - selection: TextSelection( + selection: const TextSelection( baseOffset: 10, extentOffset: 6, ), @@ -1408,7 +1408,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowRight, physicalKey: PhysicalKeyboardKey.arrowRight, @@ -1429,7 +1429,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 5), + selection: const TextSelection.collapsed(offset: 5), ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1437,7 +1437,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowUp, physicalKey: PhysicalKeyboardKey.arrowUp, @@ -1456,7 +1456,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 18), + selection: const TextSelection.collapsed(offset: 18), ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1464,7 +1464,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowUp, physicalKey: PhysicalKeyboardKey.arrowUp, @@ -1483,7 +1483,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 18), + selection: const TextSelection.collapsed(offset: 18), ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1491,7 +1491,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowUp, physicalKey: PhysicalKeyboardKey.arrowUp, @@ -1512,7 +1512,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 23), + selection: const TextSelection.collapsed(offset: 23), ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1520,7 +1520,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowUp, physicalKey: PhysicalKeyboardKey.arrowUp, @@ -1541,7 +1541,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 50), + selection: const TextSelection.collapsed(offset: 50), ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1549,7 +1549,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowDown, physicalKey: PhysicalKeyboardKey.arrowDown, @@ -1568,7 +1568,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 0), + selection: const TextSelection.collapsed(offset: 0), ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1576,7 +1576,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowDown, physicalKey: PhysicalKeyboardKey.arrowDown, @@ -1595,7 +1595,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 0), + selection: const TextSelection.collapsed(offset: 0), ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1603,7 +1603,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowDown, physicalKey: PhysicalKeyboardKey.arrowDown, @@ -1624,7 +1624,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 5), + selection: const TextSelection.collapsed(offset: 5), ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1632,7 +1632,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.moveUpDownLeftAndRightWithArrowKeys( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.arrowDown, physicalKey: PhysicalKeyboardKey.arrowDown, @@ -1657,7 +1657,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 28), // midway through 2nd line + selection: const TextSelection.collapsed(offset: 28), // midway through 2nd line ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1666,7 +1666,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -1691,7 +1691,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 31, affinity: TextAffinity.upstream), // end of 2nd line + selection: const TextSelection.collapsed(offset: 31, affinity: TextAffinity.upstream), // end of 2nd line ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1700,7 +1700,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -1723,7 +1723,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'This is line 1\nThis is line 2\nThis is line 3'), - selection: TextSelection.collapsed(offset: 23), // midway through 2nd line + selection: const TextSelection.collapsed(offset: 23), // midway through 2nd line ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1732,7 +1732,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -1755,7 +1755,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'This is line 1\nThis is line 2\nThis is line 3'), - selection: TextSelection.collapsed(offset: 29, affinity: TextAffinity.upstream), // end of 2nd line + selection: const TextSelection.collapsed(offset: 29, affinity: TextAffinity.upstream), // end of 2nd line ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1764,7 +1764,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -1787,7 +1787,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'This is some text that doesn\'t matter for this test.'), - selection: TextSelection( + selection: const TextSelection( baseOffset: 0, extentOffset: 10, ), @@ -1799,7 +1799,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -1819,7 +1819,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'This is some text that doesn\'t matter for this test.'), - selection: TextSelection.collapsed(offset: -1), + selection: const TextSelection.collapsed(offset: -1), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1828,7 +1828,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -1850,7 +1850,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 18), // start of 2nd line + selection: const TextSelection.collapsed(offset: 18), // start of 2nd line ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1859,7 +1859,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -1883,7 +1883,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 28), // midway through 2nd line + selection: const TextSelection.collapsed(offset: 28), // midway through 2nd line ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1892,7 +1892,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -1917,7 +1917,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 31, affinity: TextAffinity.upstream), // end of 2nd line + selection: const TextSelection.collapsed(offset: 31, affinity: TextAffinity.upstream), // end of 2nd line ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -1926,7 +1926,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -1949,7 +1949,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'This is line 1\nThis is line 2\nThis is line 3'), - selection: TextSelection.collapsed(offset: 23), // midway through 2nd line + selection: const TextSelection.collapsed(offset: 23), // midway through 2nd line ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1958,7 +1958,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -1981,7 +1981,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'This is line 1\nThis is line 2\nThis is line 3'), - selection: TextSelection.collapsed(offset: 29, affinity: TextAffinity.upstream), // end of 2nd line + selection: const TextSelection.collapsed(offset: 29, affinity: TextAffinity.upstream), // end of 2nd line ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -1990,7 +1990,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -2013,7 +2013,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'This is some text that doesn\'t matter for this test.'), - selection: TextSelection( + selection: const TextSelection( baseOffset: 0, extentOffset: 10, ), @@ -2025,7 +2025,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -2045,7 +2045,7 @@ void main() { final controller = AttributedTextEditingController( text: AttributedText(text: 'This is some text that doesn\'t matter for this test.'), - selection: TextSelection.collapsed(offset: -1), + selection: const TextSelection.collapsed(offset: -1), ); final selectableTextState = await _pumpAndReturnSelectableText(tester, controller.text.text); @@ -2054,7 +2054,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -2076,7 +2076,7 @@ void main() { // the layout width and the text content must be precise. final controller = AttributedTextEditingController( text: AttributedText(text: _multilineLayoutText), - selection: TextSelection.collapsed(offset: 18), // start of 2nd line + selection: const TextSelection.collapsed(offset: 18), // start of 2nd line ); final selectableTextState = await _pumpMultilineLayout(tester); @@ -2085,7 +2085,7 @@ void main() { DefaultSuperTextFieldKeyboardHandlers.deleteTextOnLineBeforeCaretWhenShortcutKeyAndBackspaceIsPressed( controller: controller, selectableTextState: selectableTextState, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -2106,12 +2106,12 @@ void main() { test('it does nothing when text is empty', () { final controller = AttributedTextEditingController( text: AttributedText(text: ''), - selection: TextSelection.collapsed(offset: 0), + selection: const TextSelection.collapsed(offset: 0), ); final result = DefaultSuperTextFieldKeyboardHandlers.deleteTextWhenBackspaceOrDeleteIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -2129,12 +2129,12 @@ void main() { test('it does nothing at beginning of text', () { final controller = AttributedTextEditingController( text: AttributedText(text: 'this is some text'), - selection: TextSelection.collapsed(offset: 0), + selection: const TextSelection.collapsed(offset: 0), ); final result = DefaultSuperTextFieldKeyboardHandlers.deleteTextWhenBackspaceOrDeleteIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -2152,12 +2152,12 @@ void main() { test('it deletes the previous character', () { final controller = AttributedTextEditingController( text: AttributedText(text: 'this is some text'), - selection: TextSelection.collapsed(offset: 2), + selection: const TextSelection.collapsed(offset: 2), ); final result = DefaultSuperTextFieldKeyboardHandlers.deleteTextWhenBackspaceOrDeleteIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -2175,7 +2175,7 @@ void main() { test('it deletes selected text', () { final controller = AttributedTextEditingController( text: AttributedText(text: 'this is some text'), - selection: TextSelection( + selection: const TextSelection( baseOffset: 8, extentOffset: 13, ), @@ -2183,7 +2183,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.deleteTextWhenBackspaceOrDeleteIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.backspace, physicalKey: PhysicalKeyboardKey.backspace, @@ -2203,12 +2203,12 @@ void main() { test('it does nothing when text is empty', () { final controller = AttributedTextEditingController( text: AttributedText(text: ''), - selection: TextSelection.collapsed(offset: 0), + selection: const TextSelection.collapsed(offset: 0), ); final result = DefaultSuperTextFieldKeyboardHandlers.deleteTextWhenBackspaceOrDeleteIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.delete, physicalKey: PhysicalKeyboardKey.delete, @@ -2226,12 +2226,12 @@ void main() { test('it does nothing at beginning of text', () { final controller = AttributedTextEditingController( text: AttributedText(text: 'this is some text'), - selection: TextSelection.collapsed(offset: 17), + selection: const TextSelection.collapsed(offset: 17), ); final result = DefaultSuperTextFieldKeyboardHandlers.deleteTextWhenBackspaceOrDeleteIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.delete, physicalKey: PhysicalKeyboardKey.delete, @@ -2249,12 +2249,12 @@ void main() { test('it deletes the next character', () { final controller = AttributedTextEditingController( text: AttributedText(text: 'this is some text'), - selection: TextSelection.collapsed(offset: 2), + selection: const TextSelection.collapsed(offset: 2), ); final result = DefaultSuperTextFieldKeyboardHandlers.deleteTextWhenBackspaceOrDeleteIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.delete, physicalKey: PhysicalKeyboardKey.delete, @@ -2272,7 +2272,7 @@ void main() { test('it deletes selected text', () { final controller = AttributedTextEditingController( text: AttributedText(text: 'this is some text'), - selection: TextSelection( + selection: const TextSelection( baseOffset: 8, extentOffset: 13, ), @@ -2280,7 +2280,7 @@ void main() { final result = DefaultSuperTextFieldKeyboardHandlers.deleteTextWhenBackspaceOrDeleteIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.delete, physicalKey: PhysicalKeyboardKey.delete, @@ -2300,12 +2300,12 @@ void main() { test('inserts newline in middle of text', () { final controller = AttributedTextEditingController( text: AttributedText(text: 'this is some text'), - selection: TextSelection.collapsed(offset: 8), + selection: const TextSelection.collapsed(offset: 8), ); final result = DefaultSuperTextFieldKeyboardHandlers.insertNewlineWhenEnterIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.enter, physicalKey: PhysicalKeyboardKey.enter, @@ -2323,12 +2323,12 @@ void main() { test('inserts newline at beginning of text', () { final controller = AttributedTextEditingController( text: AttributedText(text: 'this is some text'), - selection: TextSelection.collapsed(offset: 0), + selection: const TextSelection.collapsed(offset: 0), ); final result = DefaultSuperTextFieldKeyboardHandlers.insertNewlineWhenEnterIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.enter, physicalKey: PhysicalKeyboardKey.enter, @@ -2346,12 +2346,12 @@ void main() { test('inserts newline at end of text', () { final controller = AttributedTextEditingController( text: AttributedText(text: 'this is some text'), - selection: TextSelection.collapsed(offset: 17), + selection: const TextSelection.collapsed(offset: 17), ); final result = DefaultSuperTextFieldKeyboardHandlers.insertNewlineWhenEnterIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.enter, physicalKey: PhysicalKeyboardKey.enter, @@ -2371,12 +2371,12 @@ void main() { test('inserts character in empty text', () { final controller = AttributedTextEditingController( text: AttributedText(text: ''), - selection: TextSelection.collapsed(offset: 0), + selection: const TextSelection.collapsed(offset: 0), ); final result = DefaultSuperTextFieldKeyboardHandlers.insertCharacterWhenKeyIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyF, physicalKey: PhysicalKeyboardKey.keyF, @@ -2394,12 +2394,12 @@ void main() { test('inserts character in middle of text', () { final controller = AttributedTextEditingController( text: AttributedText(text: '--><--'), - selection: TextSelection.collapsed(offset: 3), + selection: const TextSelection.collapsed(offset: 3), ); final result = DefaultSuperTextFieldKeyboardHandlers.insertCharacterWhenKeyIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyF, physicalKey: PhysicalKeyboardKey.keyF, @@ -2417,12 +2417,12 @@ void main() { test('inserts character at end of text', () { final controller = AttributedTextEditingController( text: AttributedText(text: '-->'), - selection: TextSelection.collapsed(offset: 3), + selection: const TextSelection.collapsed(offset: 3), ); final result = DefaultSuperTextFieldKeyboardHandlers.insertCharacterWhenKeyIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyF, physicalKey: PhysicalKeyboardKey.keyF, @@ -2440,12 +2440,12 @@ void main() { test('replaces selected text with character', () { final controller = AttributedTextEditingController( text: AttributedText(text: '-->REPLACE<--'), - selection: TextSelection(baseOffset: 3, extentOffset: 10), + selection: const TextSelection(baseOffset: 3, extentOffset: 10), ); final result = DefaultSuperTextFieldKeyboardHandlers.insertCharacterWhenKeyIsPressed( controller: controller, - keyEvent: FakeRawKeyEvent( + keyEvent: const FakeRawKeyEvent( data: FakeRawKeyEventData( logicalKey: LogicalKeyboardKey.keyF, physicalKey: PhysicalKeyboardKey.keyF, @@ -2464,7 +2464,7 @@ void main() { }); } -final _multilineLayoutText = 'this text is long enough to be multiline in the available space'; +const _multilineLayoutText = 'this text is long enough to be multiline in the available space'; // Based on experiments, the text is laid out as follows: // @@ -2506,7 +2506,7 @@ Future _pumpAndReturnSelectableText( final selectableText = SuperSelectableText.plain( key: textKey, text: text, - style: TextStyle(), + style: const TextStyle(), ); final decoratedText = decorator == null ? selectableText : decorator(selectableText);