Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:flutter_hooks/flutter_hooks.dart';
- void main() => runApp(MyApp());
- class MyApp extends StatelessWidget {
- @override
- Widget build(BuildContext context) {
- return MaterialApp(
- home: MyHomePage(),
- );
- }
- }
- double smooth(double value,
- {duration = const Duration(milliseconds: 250), curve: Curves.easeInOut}) {
- final controller = useAnimationController(
- initialValue: value,
- lowerBound: double.negativeInfinity,
- upperBound: double.infinity,
- );
- useValueChanged(value, (_, __) {
- controller.animateTo(value, duration: duration, curve: curve);
- });
- return useAnimation(controller);
- }
- class MyHomePage extends HookWidget {
- @override
- Widget build(BuildContext context) {
- final counter = useState(0.0);
- return Scaffold(
- appBar: AppBar(
- title: Text('Hooks'),
- ),
- body: Center(
- child: Text(
- smooth(counter.value).toStringAsFixed(2),
- ),
- ),
- floatingActionButton: FloatingActionButton(
- onPressed: () {
- counter.value++;
- },
- child: Icon(Icons.add),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement