Flutter   发布时间:2022-03-30  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了dart – Flutter – 键入文本动画大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
对于我的每个文本小部件,我实际上希望文本输入而不是立即显示它.有没有比使用变量更简单的方法并在setState()中添加它?

谢谢

解决方法

这可能是AnimatedBuilder的一个很好的用例.这将允许您更轻松地控制键入动画的持续时间,并仅在长度更改时重建窗口小部件.这是一个如何做到这一点的例子.

dart – Flutter – 键入文本动画

import 'package:Flutter/material.dart';

void main() {
  runApp(new MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',theme: new ThemeData(
        pri@R_673_11035@Color: const color.fromARGB(255,199,0),accentColor: const color.fromARGB(255,222,233,226),brightness: Brightness.dark,canvasColor: Colors.black,),home: new MyHomePage(),debugShowcheckedModeBAnner: false,);
  }
}

class MyHomePage extends StatefulWidget {
  @override
  State createState() => new MyHomePageState();
}

class MyHomePageState extends State<MyHomePage> with TickerProviderStatemixin {

  Animation<int> _characterCount;

  int _StringIndex;
  static const List<String> _kStrings = const <String>[
    'Call trans opt: received. 2-19-98 13:24:18 REC:Log>','Trace program running.','[312]555-0690',];
  String get _currentString => _kStrings[_StringIndex % _kStrings.length];

  @override
  Widget build(BuildContext context) {
    ThemeData theme = Theme.of(context);
    TextStyle textStyle = theme.textTheme.title.copyWith(
      fontFamily: 'Courier New',color: theme.pri@R_673_11035@Color,);
    return new Scaffold(
      floaTingActionButton: new FloaTingActionButton(
        child: new Icon(Icons.navigate_next),onPressed: () async {
          AnimationController controller = new AnimationController(
            duration: const Duration(milliseconds: 4000),vsync: this,);
          setState(() {
            _StringIndex = _StringIndex == null ? 0 : _StringIndex + 1;
            _characterCount = new StepTween(begin: 0,end: _currentString.length)
              .animate(new CurvedAnimation(parent: controller,curve: Curves.easeIn));
          });
          await controller.forWARD();
          controller.dispose();
        },body: new Container(
        margin: new EdgeInsets.symmetric(vertical: 50.0,horizontal: 10.0),child: _characterCount == null ? null : new AnimatedBuilder(
          animation: _characterCount,builder: (BuildContext context,Widget child) {
            String text = _currentString.subString(0,_characterCount.value);
            return new Text(text,style: textStylE);
          },);
  }
}

如果您计划大量使用此动画文本小部件,则可以使用AnimatedWidget将其重构为单独的类.

大佬总结

以上是大佬教程为你收集整理的dart – Flutter – 键入文本动画全部内容,希望文章能够帮你解决dart – Flutter – 键入文本动画所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。