Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter Listview使应用程序崩溃_Flutter_Dart - Fatal编程技术网

Flutter Listview使应用程序崩溃

Flutter Listview使应用程序崩溃,flutter,dart,Flutter,Dart,当我从列表视图小部件或应用程序中注释一行时,它会工作,但当我取消注释它时,它根本不会出现 它是一个listview,用于呈现通过api收到的通知列表,api在未来的生成器中正常工作,但当我添加listbuilder时,它停止工作 代码 import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; import 'package:mais_mob/src/shared/models/notif

当我从列表视图小部件或应用程序中注释一行时,它会工作,但当我取消注释它时,它根本不会出现

它是一个listview,用于呈现通过api收到的通知列表,api在未来的生成器中正常工作,但当我添加listbuilder时,它停止工作

代码


import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
import 'package:mais_mob/src/shared/models/notifications_model.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:transparent_image/transparent_image.dart';

class ProfilePage extends StatefulWidget {
  @override
  _ProfilePageState createState() => _ProfilePageState();
}

class _ProfilePageState extends State<ProfilePage> {
  String _search;
  int _page = 0;
  Future<List<NotificationModel>> _getGifs() async {
    http.Response response;

    response = await http.get(
        "http://127.0.0.1:8001/api/v1/notifications/get/f331dfd0-cae4-410d-9700-b9ec72c48d7c");
    List myModels;
    myModels = (json.decode(response.body) as List)
        .map((i) => NotificationModel.fromJson(i))
        .toList();

    return myModels;
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(body: _future());
  }

  _future() {
    return FutureBuilder(
        future: _getGifs(),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            return SingleChildScrollView(
              child: Column(
                // mainAxisAlignment: MainAxisAlignment.start,
                // crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Stack(
                    children: <Widget>[
                      Container(
                        width: double.infinity,
                        height: 280.0,
                        decoration: BoxDecoration(
                            color: Color.fromRGBO(162, 56, 0, 1),
                            borderRadius: BorderRadius.only(
                                bottomLeft: Radius.circular(30.0),
                                bottomRight: Radius.circular(30.0))),
                      ),
                      Padding(
                        padding: const EdgeInsets.only(top: 60.0, left: 20.0),
                        child: InkWell(
                            onTap: () {
                              Navigator.of(context).pop();
                            },
                            child: Icon(
                              Icons.arrow_back,
                              color: Colors.white,
                            )),
                      ),
                      Padding(
                        padding: const EdgeInsets.only(top: 150.0),
                        child: Center(
                          child: Container(
                            height: 200.0,
                            width: 310.0,
                            decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius:
                                    BorderRadius.all(Radius.circular(20.0)),
                                boxShadow: [
                                  BoxShadow(
                                      color: Colors.black12.withOpacity(0.1)),
                                ]),
                            child: Column(
                              children: <Widget>[
                                Padding(
                                  padding: const EdgeInsets.only(top: 20.0),
                                  child: Container(
                                    height: 100.0,
                                    width: 100.0,
                                    decoration: BoxDecoration(
                                        image: DecorationImage(
                                            image: AssetImage(
                                                "assets/image/profile/profile3.jpg"),
                                            fit: BoxFit.cover),
                                        color: Colors.white,
                                        borderRadius: BorderRadius.all(
                                          Radius.circular(50.0),
                                        ),
                                        boxShadow: [
                                          BoxShadow(
                                              color: Colors.black12
                                                  .withOpacity(0.2),
                                              blurRadius: 10.0,
                                              spreadRadius: 2.0)
                                        ]),
                                  ),
                                ),
                                SizedBox(
                                  height: 5.0,
                                ),
                                Text(
                                  "user['name']",
                                  style: TextStyle(
                                      color: Colors.black,
                                      fontFamily: "Sofia",
                                      fontWeight: FontWeight.w700,
                                      fontSize: 20.0),
                                ),
                                Text(
                                  "user['email']",
                                  style: TextStyle(
                                      color: Colors.black38,
                                      fontFamily: "Sofia",
                                      fontWeight: FontWeight.w300,
                                      fontSize: 16.0),
                                ),
                              ],
                            ),
                          ),
                        ),
                      )
                    ],
                  ),
                  Padding(
                    padding: const EdgeInsets.only(
                        left: 25.0, top: 40.0, bottom: 10.0),
                    child: Text(
                      "Notificações",
                      style: TextStyle(
                          fontFamily: "Sofia",
                          fontWeight: FontWeight.w700,
                          fontSize: 16.0),
                    ),
                  ),
                  // ListView.builder(
                  //     itemCount: 1,
                  //     itemBuilder: (context, index) {
                  //       return ListTile(
                  //         title: Text(snapshot.data[index].id),
                  //         subtitle: Text('x'),
                  //       );
                  //     }),
                  SizedBox(
                    height: 20.0,
                  )
                ],
              ),
            );
          } else {
            return Center(
              child: CircularProgressIndicator(),
            );
          }
        });
  }
}

进口“包装:颤振/材料.省道”;
将“package:http/http.dart”导入为http;
导入“包:mais_mob/src/shared/models/notifications_model.dart”;
导入“package:shared_preferences/shared_preferences.dart”;
导入“package:transparent_image/transparent_image.dart”;
类ProfilePage扩展了StatefulWidget{
@凌驾
_ProfilePageState createState()=>\u ProfilePageState();
}
类_ProfilePageState扩展状态{
字符串搜索;
int _page=0;
Future\u getGifs()异步{
http.响应;
response=wait http.get(
"http://127.0.0.1:8001/api/v1/notifications/get/f331dfd0-cae4-410d-9700-b9ec72c48d7c”);
列出我的模型;
myModels=(json.decode(response.body)作为列表)
.map((i)=>NotificationModel.fromJson(i))
.toList();
返回myModels;
}
@凌驾
void initState(){
//TODO:实现initState
super.initState();
}
@凌驾
小部件构建(构建上下文){
返回脚手架(主体:_future());
}
_未来(){
回归未来建设者(
未来:_getGifs(),
生成器:(上下文,快照){
if(snapshot.hasData){
返回SingleChildScrollView(
子:列(
//mainAxisAlignment:mainAxisAlignment.start,
//crossAxisAlignment:crossAxisAlignment.start,
儿童:[
堆叠(
儿童:[
容器(
宽度:double.infinity,
身高:280.0,
装饰:盒子装饰(
颜色:颜色。来自RGBO(162,56,0,1),
borderRadius:仅限borderRadius(
左下角:半径。圆形(30.0),
右下角:半径.圆形(30.0)),
),
填充物(
填充:仅限常量边集(顶部:60.0,左侧:20.0),
孩子:InkWell(
onTap:(){
Navigator.of(context.pop();
},
子:图标(
Icons.arrow_back,
颜色:颜色,白色,
)),
),
填充物(
填充:仅限常量边集(顶部:150.0),
儿童:中心(
子:容器(
高度:200.0,
宽度:310.0,
装饰:盒子装饰(
颜色:颜色,白色,
边界半径:
边界半径所有(半径圆形(20.0)),
boxShadow:[
箱形阴影(
颜色:颜色。黑色12。不透明度(0.1)),
]),
子:列(
儿童:[
填充物(
填充:仅限常量边集(顶部:20.0),
子:容器(
高度:100.0,
宽度:100.0,
装饰:盒子装饰(
图像:装饰图像(
图片:资产评估(
“assets/image/profile/profile3.jpg”),
安装:BoxFit.盖),
颜色:颜色,白色,
borderRadius:borderRadius.all(
圆形半径(50.0),
),
boxShadow:[
箱形阴影(
颜色:颜色
.不透明度(0.2),
半径:10.0,
扩展半径:2.0)
]),
),
),
大小盒子(
身高:5.0,
),
正文(
“用户['name']”,
样式:TextStyle(
颜色:颜色,黑色,
fontFamily:“索菲亚”,
fontWeight:fontWeight.w700,
字体大小:20.0),
),
正文(
“用户['email']”,
样式:TextStyle(
颜色:颜色。黑色38,
fontFamily:“索菲亚”,
fontWeight:fontWeight.w300,
字体大小:16.0),
),
],
),
),
),
)
],
Container(
      // give it your desired height here
      height: 500,
      // give it your desired height here
      width: MediaQuery.of(context).size.width,
      child: ListView.builder(
        itemCount: 1,
        itemBuilder: (context, index) {
          return ListTile(
            title: Text(snapshot.data[index].id),
            subtitle: Text('x'),
          );
        },
      ),
    );
Expanded(
 child:ListView.Builder(...)
)
Expanded( 
    child: ListView()
)
SizedBox(
    height: 150,
    child: ListView()
)
ListView(
    shrinkWrap: true
)