flutter开发过程bug(不断更新)

1.

class ListFormState extends State {
    List products = ["Test1", "Test2", "Test3"];
    @override
    Widget build(BuildContext context) {
      return new Container(
        child: new Center(
          child: new Column(
            children: [
              new Row(
                children: [
                  new ListView.builder(
                    itemCount: products.length,
                    itemBuilder: (BuildContext ctxt, int index) {
                      return new Text(products[index]);
                    }
                  ),
                  new IconButton(
                    icon: Icon(Icons.remove_circle),
                    onPressed: () { },
                  )
                ],
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
              ),
              new TextField(

 [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: Cannot hit test a render box with no size.
    The hitTest() method was called on this RenderBox:

解答:The problem is that you are placing the ListView inside a Column/Row. The text in the exception gives a good explanation of the error.

To avoid the error you need to provide a size to the ListView inside.

I propose you this code that uses an Expanded to inform the horizontal size (maximum available) and the SizedBox (Could be a Container) for the height:

new Row(
      children: [
        Expanded(
          child: SizedBox(
            height: 200.0,
            child: new ListView.builder(
              scrollDirection: Axis.horizontal,
              itemCount: products.length,
              itemBuilder: (BuildContext ctxt, int index) {
                return new Text(products[index]);
              },
            ),
          ),
        ),
        new IconButton(
          icon: Icon(Icons.remove_circle),
          onPressed: () {},
        ),
      ],
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
    )

 

你可能感兴趣的:(flutter)