繁体   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