Created
December 7, 2018 01:07
-
-
Save kitoko552/7202df23e3bb1e8af0b82c6499a90443 to your computer and use it in GitHub Desktop.
WA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class _MyHomePageState extends State<MyHomePage> { | |
TextEditingController controllerA = TextEditingController(); | |
TextEditingController controllerB = TextEditingController(); | |
FocusNode nodeA = FocusNode(); | |
FocusNode nodeB = FocusNode(); | |
@override | |
void initState() { | |
super.initState(); | |
nodeA.addListener(() { | |
if (!nodeA.hasFocus) { | |
// focusが外れる時にテキストを確定状態にする | |
controllerA.value = controllerA.value.copyWith( | |
composing: TextRange(start: 0, end: 0), | |
); | |
} | |
}); | |
nodeB.addListener(() { | |
if (!nodeB.hasFocus) { | |
// focusが外れる時にテキストを確定状態にする | |
controllerB.value = controllerB.value.copyWith( | |
composing: TextRange(start: 0, end: 0), | |
); | |
} | |
}); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text('Debug')), | |
body: Center( | |
child: Column( | |
children: [ | |
_buildComposer(controllerA, nodeA), | |
_buildComposer(controllerB, nodeB), | |
], | |
), | |
), | |
); | |
} | |
Widget _buildComposer(TextEditingController controller, FocusNode node) { | |
return Container( | |
margin: const EdgeInsets.symmetric(horizontal: 88.0), | |
child: TextField( | |
controller: controller, | |
focusNode: node, | |
style: TextStyle( | |
color: Colors.black, | |
fontSize: 16.0, | |
), | |
keyboardType: TextInputType.multiline, | |
maxLines: 1, | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment