我想同時擴大&正方形的「單元」,但在layout tutorial或源代碼中找不到某種類似的東西。可能嗎?如何製作擴展和正方形的img部件
import 'package:flutter/material.dart';
import 'model.dart';
import 'package:flutter/painting.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.title),
),
drawer: new Menu(),
body: new Container(
child: new Center(
child: new G()
),
padding: const EdgeInsets.all(5.0),
),
);
}
}
class Menu extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new Drawer(
child: new ListView(
children: <Widget>[
new DrawerHeader(
child: new Text('Header'),
),
new ListTile(
title: new Text('Play'),
onTap:() {},
),
new ListTile(
title: new Text('Do some'),
onTap:() {},
),
new ListTile(
title: new Text('Exit'),
onTap:() {
Navigator.pop(context);
},
),
],
),
elevation: 2.0,
);
}
}
class G extends StatefulWidget {
@override
State createState() => new GState();
}
class Cell extends StatelessWidget {
final Color background;
Cell(this.background):super();
@override
Widget build(BuildContext context) {
return
new ConstrainedBox(
constraints: new BoxConstraints.expand(),
child: new DecoratedBox(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage('images/r_w2.png'),
fit: BoxFit.scaleDown,
),
border: new Border.all(color: Colors.purple),
boxShadow: <BoxShadow>[new BoxShadow(color: background)],
),
),
);
}
}
class GState extends State<G>{
final ChessModel chessModel = new ChessModel();
final Color grey = Colors.blueGrey;
final Color white = Colors.white12;
@override
Widget build(BuildContext context) {
int size = ChessModel.FIELD_SIZE;
List<Widget> columns = generateList(size, (int i) => new Expanded(child: buildColumn(i, size)));
return new Row(
mainAxisSize: MainAxisSize.min,
children: columns,
);
}
List<Widget> generateList (int size, f) {
return new List<Widget>.from(new List<int>.generate(size, (i) => i+1).map(f));
}
Color getBGColorByIndexes(int y, int x) {
return (y%2 == 0 && x%2 != 0) || (y%2 != 0 && x%2 == 0) ? grey: white;
}
Column buildColumn(int indexX, int size) {
List<Widget> cells = generateList(size, (int indexY) => new Expanded(child: new Cell(getBGColorByIndexes(indexY, indexX))));
return new Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: cells
);
}
}
P.S.S:有上撲(>〜5K線)任何大的開源項目?
在嘗試提出更多問題之前,請閱讀[我如何提出一個好問題?](http://stackoverflow.com/help/how-to-ask)。 –
在嘗試提出更多問題之前,請閱讀[我應避免詢問什麼類型的問題?](http://stackoverflow.com/help/dont-ask)。 –
請閱讀[爲什麼「有人可以幫助我?」不是一個實際的問題?](https://meta.stackoverflow.com/questions/284236/why-is-can-someone-help-me-not-an-實際問題),然後再試圖提出更多問題。 –