text
stringlengths 1
372
|
---|
);
|
}
|
}
|
<code_end>
|
to learn more ways to manage state, check out state management.
|
<topic_end>
|
<topic_start>
|
animations
|
two main types of UI animations exist.
|
<topic_end>
|
<topic_start>
|
implicit animation
|
SwiftUI and flutter take a similar approach to animation.
|
in both frameworks, you specify parameters like duration, and curve.
|
in SwiftUI, you use the animate() modifier to handle implicit
|
animation.
|
flutter includes widgets for implicit animation.
|
this simplifies animating common widgets.
|
flutter names these widgets with the following format: AnimatedFoo.
|
for example: to rotate a button, use the AnimatedRotation class.
|
this animates the transform.rotate widget.
|
<code_start>
|
AnimatedRotation(
|
duration: const duration(seconds: 1),
|
turns: turns,
|
curve: Curves.easeIn,
|
child: TextButton(
|
onPressed: () {
|
setState(() {
|
turns += .125;
|
});
|
},
|
child: const Text('Tap me!')),
|
),
|
<code_end>
|
flutter allows you to create custom implicit animations.
|
to compose a new animated widget, use the TweenAnimationBuilder.
|
<topic_end>
|
<topic_start>
|
explicit animation
|
for explicit animations, SwiftUI uses the withAnimation() function.
|
flutter includes explicitly animated widgets with names formatted
|
like FooTransition.
|
one example would be the RotationTransition class.
|
flutter also allows you to create a custom explicit animation using
|
AnimatedWidget or AnimatedBuilder.
|
to learn more about animations in flutter, see animations overview.
|
<topic_end>
|
<topic_start>
|
drawing on the screen
|
in SwiftUI, you use CoreGraphics to draw lines and shapes to the
|
screen.
|
flutter has an API based on the canvas class,
|
with two classes that help you draw:
|
CustomPaint that requires a painter:
|
<code_start>
|
CustomPaint(
|
painter: SignaturePainter(_points),
|
size: size.infinite,
|
),
|
<code_end>
|
CustomPainter that implements your algorithm to draw to the canvas.
|
<code_start>
|
class SignaturePainter extends CustomPainter {
|
SignaturePainter(this.points);
|
final List<Offset?> points;
|
@override
|
void paint(Canvas canvas, size size) {
|
final paint paint = paint()
|
..color = colors.black
|
..strokeCap = StrokeCap.round
|
..strokeWidth = 5;
|
for (int i = 0; i < points.length - 1; i++) {
|
if (points[i] != null && points[i + 1] != null) {
|
canvas.drawLine(points[i]!, points[i + 1]!, paint);
|
}
|
}
|
}
|
@override
|
bool shouldRepaint(SignaturePainter oldDelegate) =>
|
oldDelegate.points != points;
|
}
|
<code_end>
|
<topic_end>
|
<topic_start>
|
navigation
|
this section explains how to navigate between pages of an app,
|
the push and pop mechanism, and more.
|
<topic_end>
|
<topic_start>
|
navigating between pages
|
developers build iOS and macOS apps with different pages called
|
navigation routes.
|
in SwiftUI, the NavigationStack represents this stack of pages.
|
the following example creates an app that displays a list of persons.
|
to display a person’s details in a new navigation link,
|
tap on that person.
|
if you have a small flutter app without complex linking,
|
use navigator with named routes.
|
after defining your navigation routes,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.