[英]Create a bar like github languages bar in flutter
The easy way is to use a chart library which supports horizontal stacked bar charts.简单的方法是使用支持水平堆叠条形图的图表库。
The somewhat harder way is to create your own widget with rows and Expanded widgets.更难的方法是使用行和扩展小部件创建自己的小部件。 Something like this:
像这样的东西:
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,
),
),
],
),
https://api.flutter.dev/flutter/widgets/Expanded-class.html https://api.flutter.dev/flutter/widgets/Expanded-class.html
You'd want to use a Flexible
widget:你想使用一个
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,
),
),
],
),
],
)),
),
);
}
}
Here's what that looks like:这是它的样子:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.