Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ class OnscreenKeyboardTextFormField extends StatefulWidget {
EditableText.defaultStylusHandwritingEnabled,
this.canRequestFocus = true,
this.hintLocales,
});
}) : assert(
initialValue == null || controller == null,
'Should not provide both an initialValue and a controller',
);

/// This key is used to identify the form field when it is attached to the
/// onscreen keyboard.
Expand Down Expand Up @@ -719,7 +722,8 @@ class _OnscreenKeyboardTextFormFieldState
implements OnscreenKeyboardFieldState {
/// The [TextEditingController] for the text field.
TextEditingController get _effectiveController =>
widget.controller ?? (_controller ??= TextEditingController());
widget.controller ??
(_controller ??= TextEditingController(text: widget.initialValue));
TextEditingController? _controller;

/// The [FocusNode] for the text field.
Expand Down Expand Up @@ -779,7 +783,6 @@ class _OnscreenKeyboardTextFormFieldState
groupId: widget.groupId,
controller: _effectiveController,
focusNode: _effectiveFocusNode,
initialValue: widget.initialValue,
forceErrorText: widget.forceErrorText,
decoration: widget.decoration,
// prevent the keyboard from opening
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,46 @@ void main() {
expect(state.validate(), false);
},
);

test(
'should throw assertion error if '
'initialValue and controller are provided',
() {
expect(
() => OnscreenKeyboardTextFormField(
initialValue: 'initial',
controller: TextEditingController(),
),
throwsA(
predicate(
(e) =>
e is AssertionError &&
e.message ==
// ignore: lines_longer_than_80_chars
'Should not provide both an initialValue and a controller',
),
),
);
},
);

testWidgets(
'initialValue in OnscreenKeyboardTextFormField',
(tester) async {
await tester.pumpWidget(
MaterialApp(
builder: OnscreenKeyboard.builder(width: (_) => 200),
home: const Scaffold(
body: OnscreenKeyboardTextFormField(
initialValue: 'initial value',
),
),
),
);

await tester.pumpAndSettle();
expect(find.text('initial value'), findsOneWidget);
},
);
});
}