実現したいこと
- type 'List,dynamic>' is not a subtype of type 'List<Widget>'を解消し、Dart及びFlutterの知見を得て、期待している挙動を得たい。
前提
Flutter × Firebase開発を学習中です。
Firestore emulatorで表示されているものを画面に描画させるときに以下のメッセージが発生しました。
発生している問題・エラーメッセージ
type 'List,dynamic>' is not a subtype of type 'List<Widget>'
該当のソースコード
chats.dart
1import 'package:cloud_firestore/cloud_firestore.dart'; 2import 'package:flutter/cupertino.dart'; 3 4class Chats extends StatelessWidget { 5 const Chats({super.key}); 6 7 @override 8 Widget build(BuildContext context) { 9 return StreamBuilder( 10 stream: FirebaseFirestore.instance.collection("chats").snapshots(), 11 builder: (BuildContext context, AsyncSnapshot snapshot) { 12 if (snapshot.hasError) { 13 return const Center( 14 child: Text("Something went wrong"), 15 ); 16 } 17 18 if (snapshot.connectionState == ConnectionState.waiting) { 19 return const Center( 20 child: Text("Loading"), 21 ); 22 } 23 24 if (snapshot.hasData) { 25 return CustomScrollView( 26 slivers: [ 27 const CupertinoSliverNavigationBar( 28 largeTitle: Text("Chats"), 29 ), 30 SliverList( 31 delegate: SliverChildListDelegate( 32 snapshot.data!.docs.map((DocumentSnapshot document) { 33 Map<String, dynamic> data = 34 document.data()! as dynamic; //as dynamicを追加 35 return CupertinoListTile( 36 title: Text(data["title"]), 37 subtitle: const Text("title"), //subtitleを追加 38 ); 39 }).toList())) 40 ], 41 ); 42 } 43 return Container(); 44 }); 45 } 46 47 // @override 48 // Widget build(BuildContext context) { 49 // return CustomScrollView( 50 // slivers: [ 51 // const CupertinoSliverNavigationBar( 52 // largeTitle: Text("Chats"), 53 // ), 54 // SliverList( 55 // delegate: (SliverChildListDelegate( 56 // [ 57 // const CupertinoListTile( 58 // title: Text("Chat1"), 59 // ), 60 // const CupertinoListTile( 61 // title: Text("Chat2"), 62 // ), 63 // const CupertinoListTile( 64 // title: Text("Chat3"), 65 // ), 66 // ], 67 // )), 68 // ), 69 // ], 70 // ); 71 // } 72} 73
試したこと
type 'List,dynamic>' is not a subtype of type 'List<Widget>'を和訳したところ、
型 'List<dynamic>' のサブタイプではありません。
タイプ 'List<Widget>' のサブタイプではありません。という意味であることが判明。
type 'List,dynamic>' is not a subtype of type 'List<Widget>'でググると以下のページにヒット。
https://stackoverflow.com/questions/49603021/type-listdynamic-is-not-a-subtype-of-type-listwidget
上記のページを参考にしてchats.dartの37行目にsubtitleを追加。しかしエラー解決せず。
15分ほど調べてみても、なぜか?どこをどうするべきかというのがわからなかったので有識者の方にご教示していただきたいと考えました。何か追記依頼などがあればコメントにお願いします。
補足情報(FW/ツールのバージョンなど)
[✓] Flutter (Channel stable, 3.3.10, on macOS 13.0.1
22A400 darwin-x64, locale ja-JP)
[✓] Android toolchain - develop for Android devices
(Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.2)
[✓] VS Code (version 1.74.3)
[✓] Connected device (3 available)
[✓] HTTP Host Availability
参考にしている動画
https://youtu.be/zRRCY9mJNNE
追記
回答1件
あなたの回答
tips
プレビュー