Font Awesome 旋转器图标不会在颤动中旋转

Ish*_*dra 2 flutter

我使用如下所示的旋转图标,但我不知道为什么它不旋转。它就像普通图标一样工作。

import 'package:font_awesome_flutter/font_awesome_flutter.dart';

class MyWidget extends StatelessWidget {
  Widget build(BuildContext context) {
    return new IconButton(
      // Use the FontAwesomeIcons class for the IconData
      icon: new Icon(FontAwesomeIcons.spinner), 
      onPressed: () { print("Pressed"); }
     );
  }
}
Run Code Online (Sandbox Code Playgroud)

mir*_*cal 5

目前,该包仅提供图标,但这些图标本身不会旋转或动画。使用 flutter 的动画功能来旋转它。这是来自Brian Egan的示例小部件。

class Spinner extends StatefulWidget {
  final IconData icon;
  final Duration duration;

  const Spinner({
    Key key,
    @required this.icon,
    this.duration = const Duration(milliseconds: 1800),
  }) : super(key: key);

  @override
  _SpinnerState createState() => _SpinnerState();
}

class _SpinnerState extends State<Spinner> with SingleTickerProviderStateMixin {
  AnimationController _controller;
  Widget _child;

  @override
  void initState() {
    _controller = AnimationController(
      vsync: this,
      duration: Duration(milliseconds: 2000),
    )..repeat();
    _child = Icon(widget.icon);

    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return RotationTransition(
      turns: _controller,
      child: _child,
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

用法

Spinner(
  icon: FontAwesomeIcons.spinner,
)
Run Code Online (Sandbox Code Playgroud)

github上的相关问题