簡體   English   中英

動畫從左到右水平播放,但我想要垂直(從上到下)

[英]Animation going horizontally from left to right but I want vertical (top to bottom)

在此處輸入圖片說明

在這個項目中,我的動畫在容器中從左到右,但我想在這個容器中從上到下動畫。 我還附上了此執行的屏幕截圖以了解我的問題。

 import 'package:flutter/material.dart';
class Trackorder extends StatefulWidget {
  Trackorder({Key key}) : super(key: key);
  static const String routename = 'Trackorder';
  @override
  _TrackorderState createState() => _TrackorderState();
}

class _TrackorderState extends State<Trackorder> with TickerProviderStateMixin {
  AnimationController animationController;
  @override
  void initState() {
    super.initState();
    animationController = AnimationController(
      duration: Duration(milliseconds: 8800),
      vsync: this,
    );
    animationController.forward();
  }

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('trackorder'),
        centerTitle: true,
      ),
      body: AnimatedBar(controller: animationController),
    );
  }
}

class AnimatedBar extends StatelessWidget {
  final dotsize = 20.0;
  final AnimationController controller;
  final Animation<Color> dotOneColor;
  final Animation<TextStyle> textOneStyle;
  final Animation<double> progressBarOne;
  final Animation<Color> dotTwoColor;
  final Animation<TextStyle> textTwoStyle;
  final Animation<double> progressBarTwo;

  AnimatedBar({Key key, this.controller})
      : dotOneColor = ColorTween(
          begin: Colors.grey,
          end: Colors.yellow,
        ).animate(
          CurvedAnimation(
            parent: controller,
            curve: Interval(
              0.000,
              0.000,
              curve: Curves.linear,
            ),
          ),
        ),
        textOneStyle = TextStyleTween(
          begin: TextStyle(
              fontWeight: FontWeight.w400, color: Colors.grey, fontSize: 12),
          end: TextStyle(
              fontWeight: FontWeight.w600, color: Colors.black87, fontSize: 12),
        ).animate(
          CurvedAnimation(
              parent: controller,
              curve: Interval(0.000, 0.000, curve: Curves.linear)),
        ),
        progressBarOne = Tween(begin: 0.0, end: 1.0).animate(
          CurvedAnimation(
            parent: controller,
            curve: Interval(0.100, 0.200, curve: Curves.linear),
          ),
        ),
        dotTwoColor = ColorTween(
          begin: Colors.grey,
          end: Colors.yellow,
        ).animate(
          CurvedAnimation(
            parent: controller,
            curve: Interval(
              0.000, 0.000, // 0.450,
              // 0.550,
              curve: Curves.linear,
            ),
          ),
        ),
        textTwoStyle = TextStyleTween(
          begin: TextStyle(
              fontWeight: FontWeight.w400, color: Colors.grey, fontSize: 12),
          end: TextStyle(
              fontWeight: FontWeight.w600, color: Colors.black87, fontSize: 12),
        ).animate(
          CurvedAnimation(
              parent: controller,
              curve: Interval(0.000, 0.000, curve: Curves.linear)),
        ),
        progressBarTwo = Tween(begin: 0.0, end: 1.0).animate(
          CurvedAnimation(
            parent: controller,
            curve: Interval(0.200, 0.300, curve: Curves.linear),
          ),
        ),
        // 
        super(key: key);
  @override
  Widget build(BuildContext context) {
    final devicesize = MediaQuery.of(context).size;
    return Container(
      child: AnimatedBuilder(
        animation: controller,
        builder: (BuildContext context, Widget child) => Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Text(
              "Order No.001",
              style: Theme.of(context).textTheme.subtitle1,
            ),
            Text(
              "Order confirrmed ready to pick",
              style: TextStyle(color: Colors.grey, fontSize: 15.0),
            ),
            Padding(
              padding: const EdgeInsets.symmetric(vertical: 15.0),
              child: Divider(
                height: 1.0,
                color: Colors.grey,
              ),
            ),
            Container(
              // width: devicesize.width / 1.3,
              height: devicesize.height * 0.50,
              margin: EdgeInsets.only(top: 10),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Container(
                    width: dotsize,
                    height: dotsize,
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(dotsize / 2),
                        color: dotOneColor.value),
                  ),
                  SizedBox(
                    height: 10,
                  ),
                  Expanded(
                    flex: 1,
                    child: Container(
                      width: 30,
                      // child: RotationTransition(
                      //   turns: AlwaysStoppedAnimation(90 / 360),
                      child: LinearProgressIndicator(
                        backgroundColor: Colors.grey,
                        value: progressBarOne.value,
                        valueColor:
                            AlwaysStoppedAnimation<Color>(Colors.yellow),
                      ),
                      // ),
                    ),
                  ),
                  // SizedBox(width: 10),
                  SizedBox(height: 10),

                  Container(
                    width: dotsize,
                    height: dotsize,
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(dotsize / 2),
                        color: dotTwoColor.value),
                  ),
                  // SizedBox(width: 10),
                  SizedBox(height: 10),
                  Expanded(
                    flex: 1,
                    child: Container(
                      // height: 2,
                      width: 30[![enter image description here][1]][1],
                      child: LinearProgressIndicator(
                        backgroundColor: Colors.grey,
                        value: progressBarTwo.value,
                        valueColor:
                            AlwaysStoppedAnimation<Color>(Colors.yellow),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}

您可以將 LinearProgressIndicator 放在 RotatedBox 中:

RotatedBox(
      quarterTurns: 1,
      child: LinearProgressIndicator(
      backgroundColor: Colors.grey,
      value: progressBarOne.value,
      valueColor:
      AlwaysStoppedAnimation<Color>(Colors.yellow),
      ),
    ),

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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