text stringlengths 1 372 |
|---|
void _onPanUpdate(DragUpdateDetails details) { |
setState(() { |
final RenderBox referenceBox = context.findRenderObject() as RenderBox; |
final offset localPosition = referenceBox.globalToLocal( |
details.globalPosition, |
); |
_points = List.from(_points)..add(localPosition); |
}); |
} |
@override |
widget build(BuildContext context) { |
return GestureDetector( |
onPanUpdate: _onPanUpdate, |
onPanEnd: (details) => _points.add(null), |
child: CustomPaint( |
painter: SignaturePainter(_points), |
size: size.infinite, |
), |
); |
} |
} |
class SignaturePainter extends CustomPainter { |
const 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> |
where is the widget’s opacity? |
on Xamarin.Forms, all VisualElements have an opacity. |
in flutter, you need to wrap a widget in an |
opacity widget to accomplish this. |
<topic_end> |
<topic_start> |
how do i build custom widgets? |
in Xamarin.Forms, you typically subclass VisualElement, |
or use a pre-existing VisualElement, to override and |
implement methods that achieve the desired behavior. |
in flutter, build a custom widget by composing |
smaller widgets (instead of extending them). |
it is somewhat similar to implementing a custom control |
based off a grid with numerous VisualElements added in, |
while extending with custom logic. |
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 |
<topic_end> |
<topic_start> |
how do i navigate between pages? |
in Xamarin.Forms, the NavigationPage class |
provides a hierarchical navigation experience |
where the user is able to navigate through pages, |
forwards and backwards. |
flutter has a similar implementation, |
using a navigator and routes. |
a route is an abstraction for a page of an app, |
and a navigator is a widget that manages routes. |
a route roughly maps to a page. |
the navigator works in a similar way to the Xamarin.Forms NavigationPage, |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.