0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Flutter】No Material widget found. TextField widgets requre a Material widget ancestor with in the closest LookupBoundary 以下略

Posted at

操作

  • @override buildメソッドからextensionに切り出したcustomTextFieldのみを呼び出してextensionのUIの表示確認をしようとした。

エラー

  • 画面が呼び出されるタイミングでレッドスクリーンエラーが発生してしまった。
No Material widget found. TextField widgets requre a Material widget ancestor with in the closest LookupBoundary 

試したこと

  • メモリリーク対策
    • TextFieldControllerはメモリリーク対策でdispose()しなければならない。
edit_title_view.dart
  @override
  void dispose() {
    // TextEditingControllerは明示的に破棄しないとメモリリークの原因になる
    _titleController.dispose();
    super.dispose();
  }

解決策

  • やっぱりMaterialがないと言われているから、何かしら土台を作る必要があると思いScaffoldcustomTextField()をラップした。
edit_title_view.dart
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('タイトル編集'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: customTextField()
      ),
    );
  }
  • うまくいった。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?