[英]Create a bar like github languages bar in flutter
簡單的方法是使用支持水平堆疊條形圖的圖表庫。
更難的方法是使用行和擴展小部件創建自己的小部件。 像這樣的東西:
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,
),
),
],
),
你想使用一個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,
),
),
],
),
],
)),
),
);
}
}
這是它的樣子:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.