// Copyright 2023 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; /// TickingBuilder is for ambient animation to be run /// on each frame. class TickingBuilder extends StatefulWidget { const TickingBuilder({super.key, required this.builder}); final Widget Function(BuildContext context, double time) builder; @override State createState() => _TickingBuilderState(); } class _TickingBuilderState extends State with SingleTickerProviderStateMixin { late final Ticker _ticker; double _time = 0.0; @override void initState() { super.initState(); _ticker = createTicker(_handleTick)..start(); } @override void dispose() { _ticker.dispose(); super.dispose(); } void _handleTick(Duration elapsed) { setState(() => _time = elapsed.inMilliseconds.toDouble() / 1000.0); } @override Widget build(BuildContext context) => widget.builder.call(context, _time); }