mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +00:00
First pass at a Next Generation UI demo app. The UI needs work, feedback gratefully accepted. ## Pre-launch Checklist - [x] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [x] I signed the [CLA]. - [x] I read the [Contributors Guide]. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-devrel channel on [Discord]. <!-- Links --> [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/wiki/Chat [Contributors Guide]: https://github.com/flutter/samples/blob/main/CONTRIBUTING.md
41 lines
1.1 KiB
Dart
41 lines
1.1 KiB
Dart
// 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<TickingBuilder> createState() => _TickingBuilderState();
|
|
}
|
|
|
|
class _TickingBuilderState extends State<TickingBuilder>
|
|
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);
|
|
}
|