Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter different size of gridview item

I want to create a category selector with a gridview. And I want them to have different sizes (Wrapping each).

To make gridview like below, What should I use.

Sorry for my English, and Thanks for your help.

.

like image 907
HyeonSeok Avatar asked Oct 20 '25 10:10

HyeonSeok


1 Answers

use Wrap

enter image description here

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        body: SafeArea(
          child: MyHomePage(),
        ),
      ),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var elements = [
      'Android',
      'Ios',
      'Web front',
      'Sever',
      'Embedded Sofware',
      'Design'
    ];
    return Wrap(
      children: elements.map((el) => _MyButton(name: el)).toList(),
    );
  }
}

class _MyButton extends StatelessWidget {
  _MyButton({Key key, this.name}) : super(key: key);

  final String name;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.all(5),
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(10),
        border: Border.all(
          color: Colors.black,
          width: 1,
          style: BorderStyle.solid,
        ),
      ),
      padding: EdgeInsets.all(20),
      child: Text(name),
    );
  }
}
like image 59
Kherel Avatar answered Oct 23 '25 02:10

Kherel