Paddiing 组件
作者:互联网
一、Flutter Paddiing 组件
在 html 中常见的布局标签都有 padding 属性,但是 Flutter 中很多 Widget 是没有 padding 属性。这个时候我们可以用 Padding 组件处理容器与子元素直接的间距。
属性 | 说明 |
padding | padding 值, EdgeInsetss 设置填充的值 |
child | 子组件 |
class LayoutDemo extends StatelessWidget { @override Widget build(BuildContext context) { return Padding( padding: EdgeInsets.fromLTRB(0, 0, 10, 0), child: GridView.count( crossAxisCount: 2, childAspectRatio: 1.5, children: <Widget>[ Padding( padding: EdgeInsets.fromLTRB(10, 10, 0, 0), child: Image.network('https://www.itying.com/images/flutter/1.png', fit: BoxFit.cover), ), Padding( padding: EdgeInsets.fromLTRB(10, 10, 0, 0), child: Image.network('https://www.itying.com/images/flutter/2.png', fit: BoxFit.cover), ), Padding( padding: EdgeInsets.fromLTRB(10, 10, 0, 0), child: Image.network('https://www.itying.com/images/flutter/3.png', fit: BoxFit.cover), ), Padding( padding: EdgeInsets.fromLTRB(10, 10, 0, 0), child: Image.network('https://www.itying.com/images/flutter/4.png', fit: BoxFit.cover), ), Padding( padding: EdgeInsets.fromLTRB(10, 10, 0, 0), child: Image.network('https://www.itying.com/images/flutter/5.png', fit: BoxFit.cover), ), Padding( padding: EdgeInsets.fromLTRB(10, 10, 0, 0), child: Image.network('https://www.itying.com/images/flutter/6.png', fit: BoxFit.cover), ), ], ), ); } }
二、Flutter Row 水平布局组件
属性 | 说明 |
mainAxisAlignment | 主轴的排序方式 |
crossAxisAlignment | 次轴的排序方式 |
children | 组件子元素 |
import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: Text('FlutterDemo')), body: LayoutDemo(), , )); } } class LayoutDemo extends StatelessWidget { @override Widget build(BuildContext context) { return Container( height: 700, width: 500, color: Colors.black26, child: Row( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.spaceEvenly, // crossAxisAlignment: CrossAxisAlignment.center, children: <Widget>[ IconContainer(Icons.home, color: Colors.red), IconContainer(Icons.search, color: Colors.blue), IconContainer(Icons.send, color: Colors.orange), ], ), ); } } class IconContainer extends StatelessWidget { double size; IconData icon; Color color; IconContainer(this.icon, {this.size, this.color = Colors.blue}) { this.size = 32.0; } @override Widget build(BuildContext context) { return Container( width: this.size+60, height: this.size+60, color:this.color, child: Center( child: Icon(this.icon,color:Colors.white,size:this.size) ) ); } }
标签:10,color,Paddiing,EdgeInsets,padding,child,组件,Padding 来源: https://www.cnblogs.com/jiefangzhe/p/15521348.html