flutter+margin
时间: 2023-12-13 20:04:37 浏览: 44
Flutter中的Margin是一个widget,用于在其子widget周围创建空白区域。Margin可以通过EdgeInsets类来定义,该类定义了四个方向的偏移量。以下是一个简单的例子,演示如何在Flutter中使用Margin:
```dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Margin Example',
home: Scaffold(
appBar: AppBar(
title: Text('Margin Example'),
),
body: Center(
child: Container(
width: 200,
height: 200,
color: Colors.blue,
child: Container(
margin: EdgeInsets.all(20),
color: Colors.white,
),
),
),
),
);
}
}
```
在上面的例子中,我们创建了一个蓝色的Container,然后在其中添加了一个白色的Container,并使用margin属性将其与蓝色Container的边缘分离20个逻辑像素。