実現したいこと
Flutterでシンプルなメモアプリを作りたいので、
TextFieldを使って日本語を入力したい。
発生している問題・分からないこと
TextFieldで日本語が入力できない。
日本語の文字列のペーストはできるが、入力はできない。
該当のソースコード
Dart
1import 'package:flutter/material.dart'; 2 3void main() { 4 runApp(const MyApp()); 5} 6 7class MyApp extends StatelessWidget { 8 const MyApp({super.key}); 9 10 // This widget is the root of your application. 11 12 Widget build(BuildContext context) { 13 return MaterialApp( 14 title: 'simple_memo', 15 theme: ThemeData( 16 // This is the theme of your application. 17 // 18 // TRY THIS: Try running your application with "flutter run". You'll see 19 // the application has a purple toolbar. Then, without quitting the app, 20 // try changing the seedColor in the colorScheme below to Colors.green 21 // and then invoke "hot reload" (save your changes or press the "hot 22 // reload" button in a Flutter-supported IDE, or press "r" if you used 23 // the command line to start the app). 24 // 25 // Notice that the counter didn't reset back to zero; the application 26 // state is not lost during the reload. To reset the state, use hot 27 // restart instead. 28 // 29 // This works for code too, not just values: Most code changes can be 30 // tested with just a hot reload. 31 colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple), 32 useMaterial3: true, 33 ), 34 home: const MyHomePage(title: 'simple_memo'), 35 ); 36 } 37} 38 39class MyHomePage extends StatefulWidget { 40 const MyHomePage({super.key, required this.title}); 41 42 // This widget is the home page of your application. It is stateful, meaning 43 // that it has a State object (defined below) that contains fields that affect 44 // how it looks. 45 46 // This class is the configuration for the state. It holds the values (in this 47 // case the title) provided by the parent (in this case the App widget) and 48 // used by the build method of the State. Fields in a Widget subclass are 49 // always marked "final". 50 51 final String title; 52 53 54 State<MyHomePage> createState() => _MyHomePageState(); 55} 56 57class _MyHomePageState extends State<MyHomePage> { 58 59 Widget build(BuildContext context) { 60 // This method is rerun every time setState is called, for instance as done 61 // by the _incrementCounter method above. 62 // 63 // The Flutter framework has been optimized to make rerunning build methods 64 // fast, so that you can just rebuild anything that needs updating rather 65 // than having to individually change instances of widgets. 66 return Scaffold( 67 appBar: AppBar( 68 // TRY THIS: Try changing the color here to a specific color (to 69 // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar 70 // change color while the other colors stay the same. 71 backgroundColor: Theme.of(context).colorScheme.inversePrimary, 72 // Here we take the value from the MyHomePage object that was created by 73 // the App.build method, and use it to set our appbar title. 74 title: Text(widget.title), 75 ), 76 body: const Center( 77 // Center is a layout widget. It takes a single child and positions it 78 // in the middle of the parent. 79 child: Column( 80 // Column is also a layout widget. It takes a list of children and 81 // arranges them vertically. By default, it sizes itself to fit its 82 // children horizontally, and tries to be as tall as its parent. 83 // 84 // Column has various properties to control how it sizes itself and 85 // how it positions its children. Here we use mainAxisAlignment to 86 // center the children vertically; the main axis here is the vertical 87 // axis because Columns are vertical (the cross axis would be 88 // horizontal). 89 // 90 // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint" 91 // action in the IDE, or press "p" in the console), to see the 92 // wireframe for each widget. 93 mainAxisAlignment: MainAxisAlignment.center, 94 children: <Widget>[ 95 Text( 96 'なんか適当にメモしてね!!!!!', 97 ), 98 TextField( 99 keyboardType: TextInputType.multiline, 100 maxLines: null, 101 ), 102 ], 103 ), 104 ), 105 ); 106 } 107} 108
試したこと・調べたこと
- teratailやGoogle等で検索した
- ソースコードを自分なりに変更した
- 知人に聞いた
- その他
上記の詳細・結果
調べて出た情報でpubspec.yamlに
flutter_localizations:
sdk: flutter
を追加したり、
import 'package:flutter_localizations/flutter_localizations.dart';
を追加したが、変わらず。
また、return MaterialAppに
localizationsDelegates: const [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
],
supportedLocales: const [
Locale('ja', ''), // 日本語
Locale('en', ''), // 英語
],
を追加したが、変わらず。
補足
Windows 11 23H2
WSL 2.2.4.0
Ubuntu 22.04.3 LTS
FVM 3.1.7
Flutter 3.22.2
Dart 3.4.3
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。