text stringlengths 1 474 |
|---|
size: 24, |
color: Colors.black, |
), |
), |
], |
); |
}<code_end> |
<topic_end> |
<topic_start> |
What is the equivalent of a ScrollView? |
In Xamarin.Forms, a ScrollView wraps around a VisualElement, |
and if the content is larger than the device screen, it scrolls.In Flutter, the closest match is the SingleChildScrollView widget. |
You simply fill the Widget with the content that you want to be scrollable. |
<code_start>@override |
Widget build(BuildContext context) { |
return const SingleChildScrollView( |
child: Text('Long Content'), |
); |
}<code_end> |
If you have many items you want to wrap in a scroll, |
even of different Widget types, you might want to use a ListView. |
This might seem like overkill, but in Flutter this is |
far more optimized and less intensive than a Xamarin.Forms ListView, |
which is backing on to platform specific controls. |
<code_start>@override |
Widget build(BuildContext context) { |
return ListView( |
children: const <Widget>[ |
Text('Row One'), |
Text('Row Two'), |
Text('Row Three'), |
Text('Row Four'), |
], |
); |
}<code_end> |
<topic_end> |
<topic_start> |
How do I handle landscape transitions in Flutter? |
Landscape transitions can be handled automatically by setting the |
configChanges property in the AndroidManifest.xml:<topic_end> |
<topic_start> |
Gesture detection and touch event handling |
<topic_end> |
<topic_start> |
How do I add GestureRecognizers to a widget in Flutter? |
In Xamarin.Forms, Elements might contain a click event you can attach to. |
Many elements also contain a Command that is tied to this event. |
Alternatively you would use the TapGestureRecognizer. |
In Flutter there are two very similar ways:If the widget supports event detection, pass a function to it and |
handle it in the function. For example, the ElevatedButton has an |
onPressed parameter: |
<code_start>@override |
Widget build(BuildContext context) { |
return ElevatedButton( |
onPressed: () { |
developer.log('click'); |
}, |
child: const Text('Button'), |
); |
}<code_end> |
If the widget doesn’t support event detection, wrap the |
widget in a GestureDetector and pass a function |
to the onTap parameter. |
<code_start>class SampleApp extends StatelessWidget { |
const SampleApp({super.key}); |
@override |
Widget build(BuildContext context) { |
return Scaffold( |
body: Center( |
child: GestureDetector( |
onTap: () { |
developer.log('tap'); |
}, |
child: const FlutterLogo(size: 200), |
), |
), |
); |
} |
}<code_end> |
<topic_end> |
<topic_start> |
How do I handle other gestures on widgets? |
In Xamarin.Forms you would add a GestureRecognizer to the View. |
You would normally be limited to TapGestureRecognizer, |
PinchGestureRecognizer, PanGestureRecognizer, SwipeGestureRecognizer, |
DragGestureRecognizer and DropGestureRecognizer unless you built your own.In Flutter, using the GestureDetector, |
you can listen to a wide range of Gestures such as:The following example shows a GestureDetector |
that rotates the Flutter logo on a double tap: |
<code_start>class RotatingFlutterDetector extends StatefulWidget { |
const RotatingFlutterDetector({super.key}); |
@override |
State<RotatingFlutterDetector> createState() => |
_RotatingFlutterDetectorState(); |
} |
class _RotatingFlutterDetectorState extends State<RotatingFlutterDetector> |
with SingleTickerProviderStateMixin { |
late final AnimationController controller; |
late final CurvedAnimation curve; |
@override |
void initState() { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.