简体   繁体   English

flutter layout, Listview builder 导致错误的相关小部件是:ListView

[英]flutter layout, Listview builder The relevant error-causing widget was: ListView

my code in listview, alredy add shrinkWrap: true, The following assertion was thrown during performLayout(): Assertion failed: constraints.hasBoundedWidth is not true The relevant error-causing widget was: ListView When the exception was thrown, this was the stack:我在 listview 中的代码,alredy 添加 shrinkWrap: true, The following assertion was thrown during performLayout(): Assertion failed: constraints.hasBoundedWidth is not true The relevant error-causing widget was: ListView 当抛出异常时,这是堆栈:


class MyHomePage extends StatefulWidget {
  MyHomePage({Key? key}) : super(key: key);

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool _isLoading = true;
  @override
  void didChangeDependencies() {
    // ignore: todo
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
    WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
      Provider.of<HomeViewModel>(context, listen: false).getWisatas();
      setState(() {
        _isLoading = false;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    final modelView = Provider.of<HomeViewModel>(context, listen: true);
    return Scaffold(
      backgroundColor: cPrimary1,
      body: _isLoading
          ? const Center(child: CircularProgressIndicator())
          : SafeArea(
              top: true,
              bottom: true,
              child: Column(
                children: <Widget>[
                  Expanded(
                    flex: 2,
                    child: Stack(
                      children: [
                        Container(
                          height: 220,
                          decoration: BoxDecoration(
                            border: Border(
                                bottom: BorderSide(width: 5, color: CSeccond)),
                            image: DecorationImage(
                                image: AssetImage("assets/tugumangga.jpeg"),
                                fit: BoxFit.fill,
                                alignment: Alignment.bottomCenter),
                          ),
                        ),
                        Positioned(
                          top: 30,
                          left: 20,
                          child: RichText(
                            text: TextSpan(
                              text: "Selamat\nDatang",
                              style: TextStyle(
                                fontSize: 36,
                                color: Colors.white,
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  Expanded(
                      flex: 5,
                      child: Padding(
                        padding: EdgeInsets.only(right: 20, left: 20),
                        child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text(
                              'Wisata Alam',
                              style: TextStyle(
                                fontSize: 18,
                                color: Colors.white,
                              ),
                            ),
                            SizedBox(
                              height: 8,
                            ),
                            SingleChildScrollView(
                              scrollDirection: Axis.horizontal,
                              child: Row(
                                mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  ListView.builder(
                                      itemCount: modelView.wisatalist.length,
                                      physics: BouncingScrollPhysics(),
                                      shrinkWrap: true,
                                      itemBuilder: (context, index) {
                                        return GestureDetector(
                                            child: BoxWisata(
                                              h: 100,
                                              w: 100,
                                              fs: 13,
                                              title: 'wisata',
                                              img: 'assets/tugumangga.jpeg',
                                            ),
                                            onTap: () => {
                                                  //   Navigator.push(
                                                  //       context,
                                                  //       MaterialPageRoute(
                                                  //         builder: (context) =>
                                                  //             DetailScreen(
                                                  //           nama: modelView
                                                  //               .wisatalist[index]
                                                  //               .nama,
                                                  //           img: [],
                                                  //         ),
                                                  //       ))
                                                });
                                      }),
                                  // BoxWisata(
                                  //   h: 100,
                                  //   w: 100,
                                  //   fs: 13,
                                  //   title: 'wisata',
                                  //   img: 'assets/tugumangga.jpeg',
                                  // ),
                                  // BoxWisata(
                                  //     h: 100,
                                  //     w: 100,
                                  //     fs: 13,
                                  //     title: 'wisata',
                                  //     img: 'assets/tugumangga.jpeg'),
                                  // BoxWisata(
                                  //     h: 100,
                                  //     w: 100,
                                  //     fs: 13,
                                  //     title: 'wisata',
                                  //     img: 'assets/tugumangga.jpeg'),
                                  // BoxWisata(
                                  //     h: 100,
                                  //     w: 100,
                                  //     fs: 13,
                                  //     title: 'wisata',
                                  //     img: 'assets/tugumangga.jpeg'),
                                  // BoxWisata(
                                  //     h: 100,
                                  //     w: 100,
                                  //     fs: 13,
                                  //     title: 'wisata',
                                  //     img: 'assets/tugumangga.jpeg'),
                                ],
                              ),
                            ),
                          ],
                        ),
                      )),
                ],
              ),
            ),
    );
  }
}

my widget box我的小部件框

import 'package:flutter/material.dart';

class BoxWisata extends StatelessWidget {
  final String title;
  final String img;
  final double h;
  final double w;
  final double fs;

  BoxWisata({
    Key? key,
    required this.title,
    required this.img,
    required this.h,
    required this.w,
    required this.fs,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
      width: w,
      height: h,
      decoration: BoxDecoration(
        color: Colors.black,
        borderRadius: BorderRadius.circular(25),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.6),
            offset: const Offset(
              0.0,
              10.0,
            ),
            blurRadius: 10.0,
            spreadRadius: -6.0,
          ),
        ],
        image: DecorationImage(
          image: AssetImage(img),
          fit: BoxFit.cover,
        ),
      ),
      child: Stack(children: [
        Align(
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 10),
            child: Text(
              title,
              style: TextStyle(
                  fontSize: fs,
                  color: Colors.black,
                  fontWeight: FontWeight.bold),
              overflow: TextOverflow.ellipsis,
              maxLines: 2,
              textAlign: TextAlign.center,
            ),
          ),
          alignment: Alignment.center,
        )
      ]),
    );
  }
}

errorcode错误代码

he following assertion was thrown during performLayout(): Assertion failed: constraints.hasBoundedWidth is not true The relevant error-causing widget was: ListView When the exception was thrown, this was the stack:在 performLayout() 期间抛出了以下断言:断言失败:constraints.hasBoundedWidth 不是真的导致错误的相关小部件是:ListView 当抛出异常时,这是堆栈:

This might help这可能有帮助

Column(
  children: <Widget>[
    Stack(
      children: [
        Container(
          height: 220,
          decoration: const BoxDecoration(
            border: Border(
              bottom: BorderSide(width: 5, color: Colors.green),
            ),
            image: DecorationImage(
              image: NetworkImage("https://picsum.photos/200/300"),
              fit: BoxFit.fill,
              alignment: Alignment.bottomCenter,
            ),
          ),
        ),
        Positioned(
          top: 30,
          left: 20,
          child: RichText(
            text: const TextSpan(
              text: "Selamat\nDatang",
              style: TextStyle(
                fontSize: 36,
                color: Colors.white,
              ),
            ),
          ),
        ),
      ],
    ),
    const Text(
      'Wisata Alam',
      style: TextStyle(
        fontSize: 18,
        color: Colors.white,
      ),
    ),
    const SizedBox(height: 8),
    Expanded(
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        shrinkWrap: true,
        itemCount: 100,
        physics: const BouncingScrollPhysics(),
        itemBuilder: (context, index) {
          return GestureDetector(
            child: Container(
              padding: const EdgeInsets.all(12),
              alignment: Alignment.center,
              color: Colors
                  .primaries[Random().nextInt(Colors.primaries.length)],
              child: Text('wisata $index'),
            ),
            onTap: () => {},
          );
        },
      ),
    ),
  ],
);

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

相关问题 为什么我不能将 Listview 添加到 Flutter? (相关的导致错误的小部件是 Column) - Why cant i add Listview to Flutter ? (The relevant error-causing widget was Column) Flutter dart 错误(相关的导致错误的小部件是...) - Flutter dart error (The relevant error-causing widget was ...) flutter 错误,相关的导致错误的小部件是 Scaffold - flutter error , The relevant error-causing widget was Scaffold 相关的导致错误的小部件是 Scaffold - The relevant error-causing widget was Scaffold 导致错误的相关小部件是:FutureBuilder<firebaseapp></firebaseapp> - The relevant error-causing widget was: FutureBuilder<FirebaseApp> 相关的导致错误的小部件是:Scaffold - The relevant error-causing widget was: Scaffold 导致错误的相关小部件是 TextField - The relevant error-causing widget was TextField 错误:RenderPhysicalModel object 在布局期间被赋予无限大小。 导致错误的相关小部件是 Scaffold - Error: RenderPhysicalModel object was given an infinite size during layout. The relevant error-causing widget was Scaffold FLUTTER MOBX:构建函数返回 null。 相关的导致错误的小部件是观察者 - FLUTTER MOBX: A build function returned null. The relevant error-causing widget was Observer Flutter 导致错误的相关小部件是 Scaffold lib\main.dart:14 - Flutter The relevant error-causing widget was Scaffold lib\main.dart:14
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM