【问题标题】:Flutter - type 'BoxDecoration' is not a subtype of type 'Widget'Flutter - 'BoxDecoration' 类型不是 'Widget' 类型的子类型
【发布时间】:2020-10-28 23:16:31
【问题描述】:
 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();
                          },
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ],
        );
      }
    },
  ),

整个身体在FutureBuilder(从 Firebase 获取数据到 snapShot)

错误是

════════小部件库捕获的异常═════════════════════════════════════ ═

type 'BoxDecoration' 不是 type 'Widget' 的子类型 相关的导致错误的小部件是 未来建造者 lib\mainScreens\Profile.dart:37 ══════════════════════════════════════════════════ ══════════════════════════

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    Pranavan BoxDecoration 不是一个由Container 包装的小部件,如下所示:

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

    【讨论】:

      猜你喜欢
      • 2020-04-07
      • 2019-08-18
      • 2020-10-19
      • 2021-05-17
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多