text
stringlengths
1
372
),
);
}
}
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>
widget opacity
in UIKit, everything has .opacity or .alpha.
in flutter, most of the time you need to
wrap a widget in an opacity widget to accomplish this.
<topic_end>
<topic_start>
custom widgets
in UIKit, you typically subclass UIView, or use a pre-existing view,
to override and implement methods that achieve the desired behavior.
in flutter, build a custom widget by composing smaller widgets
(instead of extending them).
for example, how do you build a CustomButton
that takes a label in the constructor?
create a CustomButton that composes a ElevatedButton with a label,
rather than by extending ElevatedButton:
<code_start>
class CustomButton extends StatelessWidget {
const CustomButton(this.label, {super.key});
final string label;
@override
widget build(BuildContext context) {
return ElevatedButton(
onPressed: () {},
child: text(label),
);
}
}
<code_end>
then use CustomButton,
just as you’d use any other flutter widget:
<code_start>
@override
widget build(BuildContext context) {
return const center(
child: CustomButton('Hello'),
);
}
<code_end>
<topic_end>
<topic_start>
navigation
this section of the document discusses navigation
between pages of an app, the push and pop mechanism, and more.
<topic_end>
<topic_start>
navigating between pages
in UIKit, to travel between view controllers, you can use a
UINavigationController that manages the stack of view controllers
to display.
flutter has a similar implementation,
using a navigator and routes.
a route is an abstraction for a “screen” or “page” of an app,
and a navigator is a widget
that manages routes. a route roughly maps to a
UIViewController. the navigator works in a similar way to the iOS
UINavigationController, in that it can push() and pop()
routes depending on whether you want to navigate to, or back from, a view.
to navigate between pages, you have a couple options:
the following example builds a map.
<code_start>
void main() {
runApp(
CupertinoApp(
home: const MyAppHome(), // becomes the route named '/'
routes: <string, WidgetBuilder>{
'/a': (context) => const MyPage(title: 'page a'),
'/b': (context) => const MyPage(title: 'page b'),
'/c': (context) => const MyPage(title: 'page c'),
},
),
);
}
<code_end>
navigate to a route by pushing its name to the navigator.