Flutter-LinearProgressIndicator中的文本

时间:2019-10-23 07:58:44

标签: flutter flutter-layout

在Flutter中,我有 LinearProgressIndicator 。可以,但是我想在此栏中添加文本(进度)。

我尝试这样的事情

SafeArea(
  child: Row(children: <Widget>[
  Center(
    child: Text(DateFormat.ms()
                .format(DateTime.fromMillisecondsSinceEpoch(
                 minuteSecond * 1000))
                 .toString())),
           Expanded(
             child: LinearProgressIndicator(
                     semanticsLabel: (animation.value * 100.0).toStringAsFixed(1).toString(),                
                     semanticsValue:  (animation.value * 100.0).toStringAsFixed(1).toString(),   
                     value: animation.value,
                     backgroundColor: Colors.white,
                     valueColor:
                              AlwaysStoppedAnimation<Color>(Colors.red))),
])),

但是很明显,这会将文本添加到条的同一行中,而不是内部。

因此:有人知道如何在此栏中添加中心(居中)?使用 stack 元素?

更新

任何人都知道如何在ProgressBar内垂直对齐文本吗?

Not center

3 个答案:

答案 0 :(得分:3)

您将必须使用(defun test (a b) (loop for x in '(a b) collect ; X unused ((setf a (+ a b)) ; error: not a function, too many parentheses (loop for y in '(a b) ; Y unused (setf a (+ a b)) ; error: no DO (loop for z in '(a b) ; z unused (setf a (+ a b)))) ; error: no DO (list a b)))) ,请尝试以下操作:

为简单起见,我将Stack值硬编码,您可以在其中使用0.6

animation.value

截屏:

enter image description here

答案 1 :(得分:1)

像这样使用,我增加了进度指示器的高度,因为文本不合适。

       Stack(
          children: <Widget>[
            SizedBox(
              height: 18,
              child: LinearProgressIndicator(
                valueColor: AlwaysStoppedAnimation<Color>(Theme.of(context).primaryColor),
                backgroundColor: Theme.of(context).primaryColorLight,
              ),
            ),
            Positioned(
              child: Center(
                child: Text('Some Text'),
              ),
            ),
          ],
        ),

答案 2 :(得分:1)

回答您的最新帖子:

enter image description here


import { Directive, HostListener, Output, EventEmitter, ElementRef, Inject } from '@angular/core';


@Directive({
  selector: '[ScrollListener]'
})
export class ScrollListenerDirective {
  previousScrollContainerScrollTop = 0;

  @Output() scroll = new EventEmitter<boolean>();

  constructor(private el: ElementRef) {
    document.addEventListener('scroll', (event) => {
      this.onListenerTriggered(event);
    }, true);  // This is so we can use a UseCapture event listener.  Document scrolls do not bubble back up to the document level
  }

  onListenerTriggered(event): void {
    let currentScrollTop: number;
    let elementHeight: number;

    const scrollContainerScrollTop = this.el.nativeElement.offsetParent.scrollTop;
    elementHeight = this.el.nativeElement.offsetHeight;
    currentScrollTop = scrollContainerScrollTop;

    if (this.previousScrollContainerScrollTop < currentScrollTop && scrollContainerScrollTop > elementHeight + elementHeight) {
      this.scroll.emit(true);
    } else if (this.previousScrollContainerScrollTop > currentScrollTop && !(scrollContainerScrollTop <= elementHeight)) {
      this.scroll.emit(false);
    }

    this.previousScrollContainerScrollTop = currentScrollTop;

  }
}