What i have ? :
Now i can enter text into blue section, after click on it keyboard shows and every widget adjust to another (by mainAxisAlignment: MainAxisAlignment.spaceAround).
What i want to have ? :
I want the same thing as i have but i want to be able to click on red section to show up keyboard. (while keeping adjusting widgets)
shortened version of
main.dart
:
import 'package:flutter/material.dart';
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
GestureDetector(
child: const TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Enter Word",
),
),
),
SizedBox(
width: MediaQuery.of(context).size.width,
child: const CustomPaint(
// foregroundPainter: LinePainter(),
),
),
const Text(
"Nie ma takowego słowa",
textAlign: TextAlign.center,
),
])));
}
To do this, you can wrap your
TextField
in anExpanded
widget, which will expand to fill its parent and then set theexpanded
parameter of theTextField
totrue
andmaxLines
tonull
. This will allow theTextField
to expand to match its parent's (theExpanded
widget's) height:If you do not want your textfield itself to expand, you need to use a
and use the
focusNode
of theTextField
to request focus for it when tapping theGestureDetector
. Example here: https://docs.flutter.dev/cookbook/forms/focus. This will require using aStatefulWidget
, as the focusNode is long-lived state.