Макет флаттера для отображения изображений - PullRequest
0 голосов
/ 02 сентября 2018

Может кто-нибудь посоветовать, как создать макет, как показано ниже, используя флаттер для отображения изображения. 1 большой квадрат с 5 маленькими квадратами и должен измениться в соответствии с шириной экрана.

layout

Ответы [ 2 ]

0 голосов
/ 02 сентября 2018

В этом случае вы можете использовать пакет flutter_staggered_grid_view .

импортировать пакет в pubspec.yaml .

dependencies:

 ...

   flutter_staggered_grid_view: ^0.2.2

Следуйте следующему коду, чтобы получить вид сетки в шахматном порядке.

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

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new HomePage(),
    );
  }
}


class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        title: new Text("Demo"),
      ),
      body: new Padding(
          padding: const EdgeInsets.only(top: 12.0),
          child: new StaggeredGridView.count(
            crossAxisCount: 3,
            staggeredTiles: _staggeredTiles,
            children: _tiles,
            mainAxisSpacing: 4.0,
            crossAxisSpacing: 4.0,
            padding: const EdgeInsets.all(4.0),
          )
      )
    );
  }
}


List<StaggeredTile> _staggeredTiles = const <StaggeredTile>[
  const StaggeredTile.count(2, 2),
  const StaggeredTile.count(1, 1),
  const StaggeredTile.count(1, 1),
  const StaggeredTile.count(1, 1),
  const StaggeredTile.count(1, 1),
  const StaggeredTile.count(1, 1),
];

List<Widget> _tiles = const <Widget>[
  const _Example01Tile(Colors.green, Icons.widgets),
  const _Example01Tile(Colors.lightBlue, Icons.wifi),
  const _Example01Tile(Colors.amber, Icons.panorama_wide_angle),
  const _Example01Tile(Colors.brown, Icons.map),
  const _Example01Tile(Colors.deepOrange, Icons.send),
  const _Example01Tile(Colors.indigo, Icons.airline_seat_flat),
];



class _Example01Tile extends StatelessWidget {
  const _Example01Tile(this.backgroundColor, this.iconData);

  final Color backgroundColor;
  final IconData iconData;

  @override
  Widget build(BuildContext context) {
    return new Card(
      color: backgroundColor,
      child: new InkWell(
        onTap: () {},
        child: new Center(
          child: new Padding(
            padding: const EdgeInsets.all(4.0),
            child: new Icon(
              iconData,
              color: Colors.white,
            ),
          ),
        ),
      ),
    );
  }
}
0 голосов
/ 02 сентября 2018
Widget build(BuildContext context) {
final width = MediaQuery.of(context).size.width;

return new Container(
  child: new Column(
    children: <Widget>[
      new Row(children: <Widget>[
        new Container(
          width: 2*width/4,
          height: 2*width/4,
          color: Colors.lightGreen,
        ),
        new Column(children: <Widget>[
          new Container(
            width: width/4,
            height: width/4,
            color: Colors.redAccent,
          ),
          new Container(
            width: width/4,
            height: width/4,
            color: Colors.red,
          )
        ],)
      ],),
      new Row(children: <Widget>[
        new Container(
          width: width/4,
          height: width/4,
          color: Colors.black54,
        ),
        new Container(
          width: width/4,
          height: width/4,
          color: Colors.redAccent,
        ),
        new Container(
          width: width/4,
          height: width/4,
          color: Colors.green,
        ),
      ],)
    ],
  ),
);
}
...