text stringlengths 1 372 |
|---|
to implement an animation along an interpolated curve. |
in this sense, the controller is the “master” source of the animation progress |
and the CurvedAnimation computes the curve |
that replaces the controller’s default linear motion. |
like widgets, animations in flutter work with composition. |
when building the widget tree, you assign the animation |
to an animated property of a widget, |
such as the opacity of a FadeTransition, |
and tell the controller to start the animation. |
the following example shows how to write a FadeTransition that fades |
the widget into a logo when you press the FloatingActionButton: |
<code_start> |
import 'package:flutter/material.dart'; |
void main() { |
runApp(const FadeAppTest()); |
} |
class FadeAppTest extends StatelessWidget { |
/// this widget is the root of your application. |
const FadeAppTest({super.key}); |
@override |
widget build(BuildContext context) { |
return const MaterialApp( |
title: 'fade demo', |
home: MyFadeTest(title: 'fade demo'), |
); |
} |
} |
class MyFadeTest extends StatefulWidget { |
const MyFadeTest({super.key, required this.title}); |
final string title; |
@override |
State<MyFadeTest> createState() => _MyFadeTest(); |
} |
class _MyFadeTest extends State<MyFadeTest> with TickerProviderStateMixin { |
late final AnimationController controller; |
late final CurvedAnimation curve; |
@override |
void initState() { |
super.initState(); |
controller = AnimationController( |
duration: const duration(milliseconds: 2000), |
vsync: this, |
); |
curve = CurvedAnimation( |
parent: controller, |
curve: Curves.easeIn, |
); |
} |
@override |
widget build(BuildContext context) { |
return scaffold( |
appBar: AppBar(title: text(widget.title)), |
body: center( |
child: FadeTransition( |
opacity: curve, |
child: const FlutterLogo(size: 100), |
), |
), |
floatingActionButton: FloatingActionButton( |
onPressed: () { |
controller.forward(); |
}, |
tooltip: 'fade', |
child: const Icon(Icons.brush), |
), |
); |
} |
} |
<code_end> |
for more information, see animation & motion widgets, |
the animations tutorial, and the animations overview. |
<topic_end> |
<topic_start> |
how do i draw/paint on the screen? |
Xamarin.Forms never had a built-in way to draw directly on the screen. |
many would use SkiaSharp, if they needed a custom image drawn. |
in flutter, you have direct access to the skia canvas |
and can easily draw on screen. |
flutter has two classes that help you draw to the canvas: CustomPaint |
and CustomPainter, the latter of which implements your algorithm to draw to |
the canvas. |
to learn how to implement a signature painter in flutter, |
see collin’s answer on custom paint. |
<code_start> |
import 'package:flutter/material.dart'; |
void main() { |
runApp(const MaterialApp(home: DemoApp())); |
} |
class DemoApp extends StatelessWidget { |
const DemoApp({super.key}); |
@override |
widget build(BuildContext context) => const scaffold(body: signature()); |
} |
class signature extends StatefulWidget { |
const signature({super.key}); |
@override |
SignatureState createState() => SignatureState(); |
} |
class SignatureState extends State<Signature> { |
List<Offset?> _points = <offset?>[]; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.