简体   繁体   English

Flutter - 类型“BoxDecoration”不是类型“小部件”的子类型

[英]Flutter - type 'BoxDecoration' is not a subtype of type 'Widget'

 FutureBuilder(
    //UserData from DB
    future: getUserData(),
    builder: (BuildContext context, AsyncSnapshot<FirebaseUser> snapshot) {
      if (snapshot.hasData) {
        return new Column(
          children: <Widget>[
            Container(
              height: 200.0,
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.topCenter,
                  end: Alignment.bottomCenter,
                  colors: [Color(0xFF051622), Color(0xFF1BA098)],
                ),
                borderRadius: BorderRadius.only(
                  bottomLeft: Radius.circular(15.0),
                  bottomRight: Radius.circular(15.0),
                ),
              ),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Row(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      Padding(
                        padding:
                            const EdgeInsets.only(top: 18.0, left: 12.0),
                        child: GestureDetector(
                          child: CircleAvatar(
                            radius: 30.0,
                            backgroundColor: Colors.white,
                            child: (_imageFile != null)
                                ? BoxDecoration(///This is where error happens
                                    shape: BoxShape.circle,
                                    image: DecorationImage(
                                        image: FileImage(_imageFile),
                                        fit: BoxFit.fill),
                                  )
                                : Icon(Icons.add_a_photo),//Replace with Image From DB
                          ),
                          onTap: () {
                            _getImage();
                          },
                        ),
                      ),
                      Expanded(
                        child: Padding(
                          padding: const EdgeInsets.only(
                              left: 20.0, right: 75.0, top: 20.0),
                          child: TextField(
                            decoration: InputDecoration(
                              enabledBorder: UnderlineInputBorder(
                                borderSide: BorderSide(
                                  color: Color(0xFF1BA098),
                                ),
                              ),
                              focusedBorder: UnderlineInputBorder(
                                borderSide: BorderSide(
                                  color: Color(0xFFDEB992),
                                ),
                              ),
                              hintText:
                                  "${snapshot.data.displayName}", //Name comes from db as displayName
                              hintStyle: TextStyle(
                                  color: Colors.white, fontSize: 18.0),
                            ),
                            style: TextStyle(
                                color: Colors.white, fontSize: 18.0),
                            controller: newName,
                          ),
                        ),
                      ),
                    ],
                  ),
                  Padding(
                    padding: const EdgeInsets.only(top: 12.0, left: 20.0),
                    child: Text(
                      "${snapshot.data.email}", //Email from DB as email
                      style: TextStyle(
                          color: Colors.white,
                          fontSize: 16.0,
                          fontWeight: FontWeight.bold),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.only(top: 7.0, left: 18.0),
                    child: Text(
                      "${snapshot.data.phoneNumber}", //Number from DB as phoneNumber
                      style: TextStyle(
                          color: Colors.white,
                          fontSize: 16.0,
                          fontWeight: FontWeight.bold),
                    ),
                  ),
                  Row(
                    children: <Widget>[
                      Padding(
                        padding:
                            const EdgeInsets.only(top: 10.0, left: 18.0),
                        child: Icon(
                          Icons.star_border,
                          size: 30.0,
                          color: Colors.amber,
                        ),
                      ),
                      Padding(
                        padding:
                            const EdgeInsets.only(top: 15.0, left: 2.0),
                        child: Text(
                          "0.0", //Rating from db for user
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 15.0,
                              fontWeight: FontWeight.bold,
                              fontStyle: FontStyle.italic),
                        ),
                      ),
                      Padding(
                        padding: const EdgeInsets.only(
                            top: 8.0,
                            left:
                                200.0), 
                       child: ArgonTimerButton(
                          borderRadius: 50.0,
                          color: Colors.greenAccent,
                          height: 35.0,
                          width: 100.0,
                          child: Text(
                            "Update",
                            style: TextStyle(
                              fontSize: 15.0,
                              fontWeight: FontWeight.w700,
                              color: Colors.black,
                            ),
                          ),
                          loader: (time) {
                            return Container(
                              padding: EdgeInsets.all(10.0),
                              child: SpinKitRing(
                                color: Color(0xFF1BA098),
                                lineWidth: 3.0,
                                size: 20.0,
                              ),
                            );
                          },
                          onTap: (startTimer, btnState) {
                            startTimer(6);
                            verifyDetails();
                          },
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ],
        );
      }
    },
  ),

The Whole body is on FutureBuilder (To get data from Firebase into snapShot)整个身体在FutureBuilder (从 Firebase 获取数据到 snapShot 中)

And the error is错误是

════════ Exception caught by widgets library ═══════════════════════════════════ ════════ 小部件库捕获的异常═════════════════════════════␕══

type 'BoxDecoration' is not a subtype of type 'Widget' The relevant error-causing widget was FutureBuilder lib\mainScreens\Profile.dart:37 ════════════════════════════════════════════════════════════════════════════ 'BoxDecoration' 类型不是 'Widget' 类型的子类型 相关的导致错误的小部件是 FutureBuilder lib\mainScreens\Profile.dart:37 ════════════╕══␐════════════════════ ══════════════════════════════════════════════════ ══════

Pranavan BoxDecoration isn't a widget wrap it by a Container as follow: Pranavan BoxDecoration不是由Container包装的小部件,如下所示:

Container(
   decoration: BoxDecoration( ///This is where error happens
   shape: BoxShape.circle,
   image: DecorationImage(
          image: FileImage("_imageFile"), fit: BoxFit.fill),
       ),
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Flutter:输入“列表”<widget> ' 不是 'Widget' 类型的子类型</widget> - Flutter: type 'List<Widget>' is not a subtype of type 'Widget' Flutter:小部件不是“ObstructingPreferredSizeWidget”类型的子类型 - Flutter: Widget is not a subtype of type 'ObstructingPreferredSizeWidget' Flutter:FutureBuilder类型“ FormatException”不是类型“ Widget”的子类型 - Flutter: FutureBuilder type 'FormatException' is not a subtype of type 'Widget' “字符串”类型不是 FLUTTER 中“小部件”类型的子类型 - Type 'String' is not a subtype of type 'Widget' in FLUTTER Flutter - 型号列表<dynamic>不是 Widget 类型的子类型</dynamic> - Flutter - Type List<Dynamic> is not subtype of type Widget Flutter:输入“ Future” <dynamic> &#39;不是&#39;Widget&#39;类型的子类型 - Flutter: type 'Future<dynamic>' is not a subtype of type 'Widget' 颤振:&#39;未来<PDFDocument> &#39; 不是 &#39;Widget&#39; 类型的子类型 - Flutter: 'Future<PDFDocument>' is not a subtype of type 'Widget' 颤振类型&#39;列表<Future<Widget> &gt;&#39; 不是 &#39;List 类型的子类型<Widget> &#39; - Flutter type 'List<Future<Widget>>' is not a subtype of type 'List<Widget>' Flutter GridView“类型”列表<widget>不是 Widget 类型的子类型”</widget> - Flutter GridView “type 'List<Widget> is not a subtype of type Widget” “_Type”不是“Widget”类型的子类型 - '_Type' is not a subtype of type 'Widget'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM