text stringlengths 1 372 |
|---|
} |
<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() { |
super.initState(); |
controller = AnimationController( |
duration: const duration(milliseconds: 2000), |
vsync: this, |
); |
curve = CurvedAnimation(parent: controller, curve: Curves.easeIn); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.