简体   繁体   中英

How to make Flutter ListView with border radius like a picture

Hi I am making a project but I need to customize listview box like in picture which I included. I tried many options but I could not do that.

在此处输入图片说明

class Butgerlist extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    final title = 'Grid List';

    return MaterialApp(
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        body: GridView.count(
          crossAxisCount: 2,
          children: <Widget>[
            Container(
              child: const Center(
                child: (Text("box1")),
              ),
              color: Colors.red,
            ),
            Container(
              child: Text("box2"),
              color: Colors.yellow,
            ),
            Container(
              child: Text("box3"),
              color: Colors.orange,
            ),
            Container(
              child: Text("box4"),
              color: Colors.blue,
            ),
          ],
        ),
      ),
    );
  }
}

I want to make my listview like this. If you have any suggestions please let me know. thank you.

在此处输入图片说明

Instead of Container you should have used Card and wrapped it with Padding widget.

This should work for you:

class MyApp extends StatelessWidget {
  static const title = 'Title';
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    final border = RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(10.0),
    );
    final padding = const EdgeInsets.all(4.0);
    return MaterialApp(
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        body: GridView.count(
          crossAxisCount: 2,
          children: <Widget>[
            Padding(
              padding: padding,
              child: Card(
                shape: border,
                color: Colors.red,
                child: const Center(child: (Text("box1"))),
              ),
            ),
            Padding(
              padding: padding,
              child: Card(
                shape: border,
                child: Text("box2"),
                color: Colors.yellow,
              ),
            ),
            Padding(
              padding: padding,
              child: Card(
                shape: border,
                child: Text("box3"),
                color: Colors.orange,
              ),
            ),
            Padding(
              padding: padding,
              child: Card(
                shape: border,
                child: Text("box4"),
                color: Colors.blue,
              ),
            ),
          ],
        ),
      ),
    );
  }
}

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM