Привет, я новичок во Flutter, хочу создать бегущий Border, но анимация не работает, помогите пожалуйста
Вокруг контейнера должна гулять цветовая палитра. Когда обворачиваю Container в AnimatedBuilder анимация не работает, хотя код написан правильно.
import 'dart:math';
import 'package:flutter/material.dart';
class AniContainer extends StatefulWidget {
const AniContainer({Key? key}) : super(key: key);
@override
State<AniContainer> createState() => _AniContainerState();
}
class _AniContainerState extends State<AniContainer>
with SingleTickerProviderStateMixin {
late AnimationController controller;
@override
void initState() {
super.initState();
controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 1),
animationBehavior: AnimationBehavior.normal);
controller.repeat();
// controller.forward();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: AnimatedBuilder(
animation: controller,
builder: (context, child) => Container(
width: 64,
height: 64,
decoration: BoxDecoration(
gradient: SweepGradient(
transform: GradientRotation(controller.value * (pi / 0.5)),
colors: const [
Colors.white,
Colors.red,
Colors.green,
Colors.blue,
],
),
),
child: Container(
decoration: const BoxDecoration(color: Colors.white),
margin: const EdgeInsets.all(2),
width: 64,
height: 64,
child: const Icon(Icons.home_rounded),
),
),
),
),
);
}
}
Не могу найти причину, почему не работает, кто может помочь?
Возможно требуется разрешение в pubspec.yaml?