[Flutter]GridViewサンプル

要素を均等に並べたい時はGridView

画像1

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';

class Grid extends HookWidget {
 final List<IconData> icons = [
   Icons.add_call,
   Icons.airplay,
   Icons.battery_charging_full,
   Icons.casino,
   Icons.calendar_today,
   Icons.dangerous,
   Icons.download_rounded,
   Icons.favorite,
   Icons.games,
 ];
 
 @override
 Widget build(BuildContext context) {
   return Scaffold(
     body: GridView.count(
       crossAxisCount: 4,
       children: [
         for (int i = 0; i < icons.length; i++) Icon(icons[i], size: 50),
       ],
     ),
   );
 }
}

いいなと思ったら応援しよう!