Created
May 13, 2019 15:37
Revisions
-
t-artikov created this gist
May 13, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ 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), ), ); } }