前提
FlutterのUI構築の仕方を勉強するにあたり、Youtubeの動画を真似して勉強しています。
実現したいこと
- The element type 'Type' can't be assigned to the list type 'Widget'.を解決させて正常な挙動にする。
発生している問題・エラーメッセージ
The element type 'Type' can't be assigned to the list type 'Widget'.
該当のソースコード
body.dart
1import 'package:flutter/material.dart'; 2import 'package:flutter_svg/svg.dart'; 3import 'package:plant_app/constants.dart'; 4 5class Body extends StatelessWidget { 6 @override 7 Widget build(BuildContext context) { 8 Size size = MediaQuery.of(context).size; 9 return Column( 10 children: <Widget>[ 11 SizedBox( 12 height: size.height * 0.8, 13 child: Row( 14 children: <Widget>[ 15 Expanded( 16 child: Padding( 17 padding: 18 const EdgeInsets.symmetric(vertical: kDefaultPadding * 3), 19 child: Column( 20 children: <Widget>[ 21 Align( 22 alignment: Alignment.topLeft, 23 child: IconButton( 24 padding: 25 EdgeInsets.symmetric(horizontal: kDefaultPadding), 26 onPressed: () { 27 Navigator.pop(context); 28 }, 29 icon: SvgPicture.asset( 30 "/Users/ユーザー/Flutter/plant_app/plant_app/assets/icons/back_arrow.svg"), 31 ), 32 ), 33 Spacer(), 34 ], 35 ), 36 ), 37 ), 38 Container( 39 height: size.height * 0.8, 40 width: size.width * 0.75, 41 decoration: BoxDecoration( 42 borderRadius: BorderRadius.only( 43 topLeft: Radius.circular(63), 44 bottomLeft: Radius.circular(63), 45 ), 46 boxShadow: [ 47 BoxShadow( 48 offset: Offset(0, 10), 49 blurRadius: 60, 50 color: kPrimaryColor.withOpacity(0.29), 51 ), 52 ], 53 image: DecorationImage( 54 alignment: Alignment.centerLeft, 55 fit: BoxFit.cover, 56 image: AssetImage( 57 "/Users/ユーザー/Flutter/plant_app/plant_app/assets/images/img.png"), 58 ), 59 ), 60 ), 61 ], 62 ), 63 ) 64 ], 65 ); 66 } 67} 68
試したこと
The element type 'Type' can't be assigned to the list type 'Widget'.を和訳したところ、
要素タイプ「Type」をリストタイプ「Widget」に割り当てることはできません。という意味だと判明。
The element type 'Type' can't be assigned to the list type 'Widget'.でググったところ、以下のページに行き着く。
https://www.fluttercampus.com/guide/335/expansionpanel-cant-be-assigned-to-the-list-type-widget/
<Widget>はリストタイプなので、リストタイプではない要素Typeを割り当てられないということは分かりましたが、動画だと何もエラーなく進んでいるのでこちら側でコードをいじる必要が出ました。
ですが、現在FlutterのUIの構築のやり方を勉強するという段階なので何をどうすれば良いかがわからない状況です。
補足情報(FW/ツールのバージョンなど)
Youtubeの動画
https://www.youtube.com/watch?v=LN668OAUrK4
回答1件