【发布时间】:2020-09-28 08:56:32
【问题描述】:
【问题讨论】:
标签: flutter dart flutter-layout flutter-animation
【问题讨论】:
标签: flutter dart flutter-layout flutter-animation
您想使用Flexible 小部件:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Scaffold(
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Flexible(
flex: 3, // 30%
child: Container(
color: Colors.green,
height: 20,
),
),
Flexible(
flex: 2, // 20%
child: Container(
color: Colors.yellow,
height: 20,
),
),
Flexible(
flex: 5, // 50%
child: Container(
color: Colors.cyan,
height: 20,
),
),
],
),
],
)),
),
);
}
}
看起来是这样的:
【讨论】:
简单的方法是使用支持水平堆叠条形图的图表库。
更难的方法是使用行和扩展小部件创建您自己的小部件。 像这样的:
Row(
children: <Widget>[
Expanded(
flex: 2,
child: Container(
color: Colors.amber,
height: 100,
),
),
Expanded(
flex: 2,
child: Container(
color: Colors.red,
height: 100,
),
),
Expanded(
flex: 1,
child: Container(
color: Colors.green,
height: 100,
),
),
],
),
【讨论】: