flutter 繪制時間軸控件

先上圖

難點 繪制時間軸與文字等高

正兒八經(jīng)的方案計算每一個text的高度和 設(shè)置分割線的高度早龟,方案3為取巧的可行方案
final text = 'Hello, world!';
final style = TextStyle(fontSize: 20);
final textSpan = TextSpan(text: text, style: style);
final textPainter = TextPainter(
  text: textSpan,
  textDirection: TextDirection.ltr,
);
textPainter.layout();
final height = textPainter.size.height;

1. 使用布局ListView>IntrinsicHeight>Row>ExpandableText
======== Exception caught by rendering library =====================================================
The following _CastError was thrown during performLayout():
Null check operator used on a null value

The relevant error-causing widget was: 
  ListView ListView:file:///D:/working/timelines/example/lib/main.dart:137:15
When the exception was thrown, this was the stack: 
#0      RenderSliverEdgeInsetsPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:149:63)
#1      RenderSliverPadding.performLayout (package:flutter/src/rendering/sliver_padding.dart:371:11)

2.ListView設(shè)置分割線  貌似只有水平的生效 垂直無效
ListView.separated(
  separatorBuilder: (BuildContext context, int index) => const VerticalDivider(),
  itemCount: 25,
  itemBuilder: (BuildContext context, int index) {
    return ListTile(title: Text('Item $index'));
  },
);

3.給item加邊框繪制分割線
class ExamplePage extends StatelessWidget {
  List itemList = ['1', '2', '3'];

  @override
  Widget build(BuildContext context) {
    return TimelineTheme(
      data: TimelineThemeData(
        indicatorTheme: IndicatorThemeData(size: 15.0),
      ),
      child: Scaffold(
        appBar: AppBar(
          title: Text('Timelines Example'),
        ),
        body: ListView(
          padding: EdgeInsets.all(20.0),
          children: [
            Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Stack(
                  children: [
                    Container(
                      width: 6.5,
                      height: 6.5,
                      margin: EdgeInsets.only(top: 3.5),
                      decoration: BoxDecoration(
                          shape: BoxShape.circle,
                          border: Border.all(
                            color: Color(0xFF999999),
                            width: 1,
                          )),
                    ),
                    Padding(
                      padding: EdgeInsets.only(left: 10),
                      child: Text("20230703",
                          style: TextStyle(
                              color: Color(0xFF999999), fontSize: 12)),
                    )
                  ],
                ),
                Container(
                    padding: EdgeInsets.symmetric(horizontal: 6),
                    margin: EdgeInsets.only(left: 3),
                    decoration: BoxDecoration(
                        border: Border(
                      left: BorderSide(width: 1, color: Color(0xFFEEEEEE)),
                    )),
                    child: TimeLinesItem3()),
              ],
            ),
          ],
        ),
      ),
    );
  }

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'expandable_text.dart';

//
class TimeLinesItem3 extends StatefulWidget {


  @override
  State<StatefulWidget> createState() {
    return LinesItemState();
  }
}

class LinesItemState extends State<TimeLinesItem3> {

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return
      Column(
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Padding(
              padding: EdgeInsets.symmetric(vertical: 10),
              child: Text("AAAA Title",
                  maxLines: 2,
                  style: TextStyle(
                      color: Color(0xFF333333),
                      fontSize: 16,
                      height: 1.5,
                      fontWeight: FontWeight.bold))),
          ExpandableText(
            "AAAA Content在Flutter中凫海,您可以使用Column組件來垂直排列子控件。默認(rèn)情況下亩码,子控件是居中對齊的震蒋。如果您想要左對齊茸塞,可以使用crossAxisAlignment屬性。例如",
            expandText: 'aaaa',
            maxLines: 2,
            expandOnTextTap: true,
            collapseOnTextTap: true,
          ),
          Container(
            margin: EdgeInsets.only(top: 14, bottom: 6),
            padding: EdgeInsets.all(6),
            decoration: BoxDecoration(
              gradient: LinearGradient(
                colors: [Color(0x14FF3737), Color(0x05E93030)],
                begin: Alignment.topLeft,
                end: Alignment.bottomRight,
              ),
              borderRadius: BorderRadius.circular(4),
            ),
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Text('普利特',
                    style: TextStyle(color: Color(0xFF333333), fontSize: 12)),
                Padding(padding: EdgeInsets.only(right: 10)),
                Text('4.08%',
                    style: TextStyle(color: Color(0xFFE93030), fontSize: 12)),
              ],
            ),
          ),
        ],
      );

  }

}


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末查剖,一起剝皮案震驚了整個濱河市钾虐,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌笋庄,老刑警劉巖效扫,帶你破解...
    沈念sama閱讀 216,402評論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件倔监,死亡現(xiàn)場離奇詭異,居然都是意外死亡荡短,警方通過查閱死者的電腦和手機丐枉,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,377評論 3 392
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來掘托,“玉大人瘦锹,你說我怎么就攤上這事∩量” “怎么了弯院?”我有些...
    開封第一講書人閱讀 162,483評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長泪掀。 經(jīng)常有香客問我听绳,道長,這世上最難降的妖魔是什么异赫? 我笑而不...
    開封第一講書人閱讀 58,165評論 1 292
  • 正文 為了忘掉前任椅挣,我火速辦了婚禮,結(jié)果婚禮上塔拳,老公的妹妹穿的比我還像新娘鼠证。我一直安慰自己,他們只是感情好靠抑,可當(dāng)我...
    茶點故事閱讀 67,176評論 6 388
  • 文/花漫 我一把揭開白布量九。 她就那樣靜靜地躺著,像睡著了一般颂碧。 火紅的嫁衣襯著肌膚如雪荠列。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,146評論 1 297
  • 那天载城,我揣著相機與錄音肌似,去河邊找鬼。 笑死个曙,一個胖子當(dāng)著我的面吹牛锈嫩,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播垦搬,決...
    沈念sama閱讀 40,032評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼呼寸,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了猴贰?” 一聲冷哼從身側(cè)響起对雪,我...
    開封第一講書人閱讀 38,896評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎米绕,沒想到半個月后瑟捣,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體馋艺,經(jīng)...
    沈念sama閱讀 45,311評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,536評論 2 332
  • 正文 我和宋清朗相戀三年迈套,在試婚紗的時候發(fā)現(xiàn)自己被綠了捐祠。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,696評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡桑李,死狀恐怖踱蛀,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情贵白,我是刑警寧澤率拒,帶...
    沈念sama閱讀 35,413評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站禁荒,受9級特大地震影響猬膨,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜呛伴,卻給世界環(huán)境...
    茶點故事閱讀 41,008評論 3 325
  • 文/蒙蒙 一勃痴、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧热康,春花似錦召耘、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽剖踊。三九已至庶弃,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間德澈,已是汗流浹背歇攻。 一陣腳步聲響...
    開封第一講書人閱讀 32,815評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留梆造,地道東北人缴守。 一個月前我還...
    沈念sama閱讀 47,698評論 2 368
  • 正文 我出身青樓,卻偏偏與公主長得像镇辉,于是被迫代替她去往敵國和親屡穗。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,592評論 2 353

推薦閱讀更多精彩內(nèi)容