どうも、ちょげ(@chogetarou)です。
AnimationControllerのインスタンスを作ろうとした際に、「 vsync not defined」が出る場合があります。
もしくは、「this」でつまづく場合もあります。
この記事では、これらを解決する方法を紹介します。
方法

これらを解決するには、まず「State」のクラス名の後ろに以下のコードを追加します。
class _SampleState extends State<Sample> with SingleTickerProviderStateMixin {
・・・
}
「with SingleTickerProviderStateMixin」は、AnimationControllerを使う上では必須のものです。
あとは、AnimationControllerの引数に「vsync : this」を指定します。
_controller = AnimationController(vsync: this);
これでエラーが解決されるはずです。
コメント