text
stringlengths 1
474
|
---|
Use a Navigator to move between different Routes
|
that represent different screens or pages,
|
or maybe different states or renderings of the same data.<topic_end>
|
<topic_start>
|
Listening to lifecycle events
|
In UIKit, you can override methods to the ViewController
|
to capture lifecycle methods for the view itself,
|
or register lifecycle callbacks in the AppDelegate.
|
In Flutter, you have neither concept, but you can instead
|
listen to lifecycle events by hooking into
|
the WidgetsBinding observer and listening to
|
the didChangeAppLifecycleState() change event.The observable lifecycle events are:For more details on the meaning of these states, see
|
AppLifecycleState documentation.<topic_end>
|
<topic_start>
|
Layouts
|
This section discusses different layouts in Flutter
|
and how they compare with UIKit.<topic_end>
|
<topic_start>
|
Displaying a list view
|
In UIKit, you might show a list in
|
either a UITableView or a UICollectionView.
|
In Flutter, you have a similar implementation using a ListView.
|
In UIKit, these views have delegate methods
|
for deciding the number of rows,
|
the cell for each index path, and the size of the cells.Due to Flutter’s immutable widget pattern,
|
you pass a list of widgets to your ListView,
|
and Flutter takes care of making sure that
|
scrolling is fast and smooth.
|
<code_start>import 'package:flutter/material.dart';
|
void main() {
|
runApp(const SampleApp());
|
}
|
class SampleApp extends StatelessWidget {
|
const SampleApp({super.key});
|
// This widget is the root of your application.
|
@override
|
Widget build(BuildContext context) {
|
return const MaterialApp(
|
title: 'Sample App',
|
home: SampleAppPage(),
|
);
|
}
|
}
|
class SampleAppPage extends StatefulWidget {
|
const SampleAppPage({super.key});
|
@override
|
State<SampleAppPage> createState() => _SampleAppPageState();
|
}
|
class _SampleAppPageState extends State<SampleAppPage> {
|
List<Widget> _getListData() {
|
final List<Widget> widgets = [];
|
for (int i = 0; i < 100; i++) {
|
widgets.add(Padding(
|
padding: const EdgeInsets.all(10),
|
child: Text('Row $i'),
|
));
|
}
|
return widgets;
|
}
|
@override
|
Widget build(BuildContext context) {
|
return Scaffold(
|
appBar: AppBar(
|
title: const Text('Sample App'),
|
),
|
body: ListView(children: _getListData()),
|
);
|
}
|
}<code_end>
|
<topic_end>
|
<topic_start>
|
Detecting what was clicked
|
In UIKit, you implement the delegate method,
|
tableView:didSelectRowAtIndexPath:.
|
In Flutter, use the touch handling provided by the passed-in widgets.
|
<code_start>import 'dart:developer' as developer;
|
import 'package:flutter/material.dart';
|
void main() {
|
runApp(const SampleApp());
|
}
|
class SampleApp extends StatelessWidget {
|
const SampleApp({super.key});
|
// This widget is the root of your application.
|
@override
|
Widget build(BuildContext context) {
|
return const MaterialApp(
|
title: 'Sample App',
|
home: SampleAppPage(),
|
);
|
}
|
}
|
class SampleAppPage extends StatefulWidget {
|
const SampleAppPage({super.key});
|
@override
|
State<SampleAppPage> createState() => _SampleAppPageState();
|
}
|
class _SampleAppPageState extends State<SampleAppPage> {
|
List<Widget> _getListData() {
|
List<Widget> widgets = [];
|
for (int i = 0; i < 100; i++) {
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.