homePage.dart 1.4 KB
import 'package:flutter/material.dart';

class homePage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() => StateFulhomePageState();

}

class StateFulhomePageState extends State<homePage> {

  List<Container> buildGridTitleList(int count){
    return new List<Container>.generate(count, (int index) => new Container(
      child:
        Container(
            width: 64,
            height: 64,
            alignment: Alignment.center,
            // child: Image.asset("images/a.jpeg",
            // fit:BoxFit.cover,
            // ),
            child: Image.asset("images/projectManager.png",
              fit:BoxFit.cover,
            ),
         ),
    ));
  }
  Widget buildGrid(){
    return new GridView.count(
      //水平子Widget之间间距
      crossAxisSpacing: 10.0,
      //垂直子Widget之间间距
      mainAxisSpacing: 30.0,
      //GridView内边距
      padding: EdgeInsets.all(10.0),
      //一行的Widget数量
      crossAxisCount: 4,
      //子Widget宽高比例
      childAspectRatio: 2.0,
      children: buildGridTitleList(5),
    );
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text("首页"),
          centerTitle: true, // 标题居中
        ),
        body: new Center(
          child: buildGrid(),
        ),
      ),
    );
  }

}