LinearProgressIndicator Flutter Usage

前端 未结 4 1658
天涯浪人
天涯浪人 2021-02-20 11:06

I am learning Flutter allthought i dont know if it is right decition or not. Any way i want to use LinearProgressIndicator Component from Material Librery but i didnt get how t

相关标签:
4条回答
  • 2021-02-20 11:47

    The Solution for this Problem was Switching the Flutter Channel from beta to master channel and then the code above worked

    0 讨论(0)
  • 2021-02-20 11:52

    Try this :

    Instead of

    value: _controller.value,
    

    Use

    value: _controller.value ?? 0.0,
    

    You can also use the package that I created , it has animation:

    https://pub.dartlang.org/packages/percent_indicator

    0 讨论(0)
  • 2021-02-20 11:58

    You are not using animation object.

    import 'dart:async';
    import 'package:flutter/material.dart';
    
    void main() {
      runApp(new MaterialApp(
        debugShowCheckedModeBanner: false,
        home: new MyApp(),
      ));
    }
    
    class MyApp extends StatefulWidget {
      @override
      MyAppState createState() => new MyAppState();
    }
    
    class MyAppState extends State<MyApp> {
      @override
      Widget build(BuildContext context) {
        return new Scaffold(
          appBar: new AppBar(
            title: new Text('Slider Demo'),
          ),
          body: new Container(
            color: Colors.blueAccent,
            padding: new EdgeInsets.all(32.0),
            child: new ProgressIndicatorDemo(),
          ),
        );
      }
    }
    
    class ProgressIndicatorDemo extends StatefulWidget {
    
      @override
      _ProgressIndicatorDemoState createState() =>
          new _ProgressIndicatorDemoState();
    }
    
    class _ProgressIndicatorDemoState extends State<ProgressIndicatorDemo>
        with SingleTickerProviderStateMixin {
      AnimationController controller;
      Animation<double> animation;
    
      @override
      void initState() {
        super.initState();
        controller = AnimationController(
            duration: const Duration(milliseconds: 2000), vsync: this);
        animation = Tween(begin: 0.0, end: 1.0).animate(controller)
          ..addListener(() {
            setState(() {
              // the state that has changed here is the animation object’s value
            });
          });
        controller.repeat();
      }
    
    
      @override
      void dispose() {
        controller.stop();
        super.dispose();
      }
    
      @override
      Widget build(BuildContext context) {
        return new Center(
            child: new Container(
              child:  LinearProgressIndicator( value:  animation.value,),
    
            )
        );
      }
    
    }
    
    0 讨论(0)
  • 2021-02-20 12:01

    You can use AlwaysStoppedAnimation simply for valueColor,

    LinearProgressIndicator(
        backgroundColor: Colors.red,
        valueColor: AlwaysStoppedAnimation<Color>(Colors.amber,),
        value: 0.8,
    ),
    
    0 讨论(0)
提交回复
热议问题