text
stringlengths
1
474
);
}<code_end>
<code_start>@override
Widget build(BuildContext context) {
return const Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Column One'),
Text('Column Two'),
Text('Column Three'),
Text('Column Four'),
],
);
}<code_end>
To learn more about building linear layouts,
see the community-contributed Medium article
Flutter for Android Developers: How to design LinearLayout in Flutter.<topic_end>
<topic_start>
What is the equivalent of a RelativeLayout?
A RelativeLayout lays your widgets out relative to each other. In
Flutter, there are a few ways to achieve the same result.You can achieve the result of a RelativeLayout by using a combination of
Column, Row, and Stack widgets. You can specify rules for the widgets
constructors on how the children are laid out relative to the parent.For a good example of building a RelativeLayout in Flutter,
see Collin’s answer on StackOverflow.<topic_end>
<topic_start>
What is the equivalent of a ScrollView?
In Android, use a ScrollView to lay out your widgets—if the user’s
device has a smaller screen than your content, it scrolls.In Flutter, the easiest way to do this is using the ListView widget.
This might seem like overkill coming from Android,
but in Flutter a ListView widget is
both a ScrollView and an Android ListView.
<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?
FlutterView handles the config change if AndroidManifest.xml contains:<topic_end>
<topic_start>
Gesture detection and touch event handling
<topic_end>
<topic_start>
How do I add an onClick listener to a widget in Flutter?
In Android, you can attach onClick to views such as button by calling
the method ‘setOnClickListener’.In Flutter there are two ways of adding touch listeners:
<code_start>@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: () {
developer.log('click');
},
child: const Text('Button'),
);
}<code_end>
<code_start>class SampleTapApp extends StatelessWidget {
const SampleTapApp({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?
Using the GestureDetector, you can listen to a wide range of Gestures such as:TapDouble tapLong pressVertical dragHorizontal dragThe following example shows a GestureDetector
that rotates the Flutter logo on a double tap:
<code_start>class SampleApp extends StatefulWidget {
const SampleApp({super.key});
@override
State<SampleApp> createState() => _SampleAppState();
}
class _SampleAppState extends State<SampleApp>
with SingleTickerProviderStateMixin {
late AnimationController controller;
late CurvedAnimation curve;
@override
void initState() {
super.initState();
controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 2000),