text stringlengths 1 372 |
|---|
// this widget is the root of your application. |
const SampleApp({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 SingleTickerProviderStateMixin { |
late AnimationController controller; |
late CurvedAnimation curve; |
@override |
void initState() { |
super.initState(); |
controller = AnimationController( |
duration: const duration(milliseconds: 2000), |
vsync: this, |
); |
curve = CurvedAnimation( |
parent: controller, |
curve: Curves.easeIn, |
); |
} |
@override |
void dispose() { |
controller.dispose(); |
super.dispose(); |
} |
@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> |
drawing on the screen |
in UIKit, you use CoreGraphics to draw lines and shapes to the |
screen. flutter has a different API based on the canvas class, |
with two other classes that help you draw: 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 StackOverflow. |
<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 |
State<Signature> createState() => SignatureState(); |
} |
class SignatureState extends State<Signature> { |
List<Offset?> _points = <offset?>[]; |
@override |
widget build(BuildContext context) { |
return GestureDetector( |
onPanUpdate: (details) { |
setState(() { |
RenderBox? referenceBox = context.findRenderObject() as RenderBox; |
offset localPosition = |
referenceBox.globalToLocal(details.globalPosition); |
_points = List.from(_points)..add(localPosition); |
}); |
}, |
onPanEnd: (details) => _points.add(null), |
child: |
CustomPaint( |
painter: SignaturePainter(_points), |
size: size.infinite, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.