簡體   English   中英

在flutter中創建一個類似於github語言欄的欄

[英]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,
              ),
            ),
          ],
        ),

https://api.flutter.dev/flutter/widgets/Expanded-class.html

你想使用一個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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM