text
stringlengths 1
474
|
|---|
<topic_start>
|
What is the equivalent of Nuget? How do I add dependencies?
|
In the .NET ecosystem, native Xamarin projects and Xamarin.Forms projects
|
had access to Nuget and the built-in package management system.
|
Flutter apps contain a native Android app, native iOS app and Flutter app.In Android, you add dependencies by adding to your Gradle build script.
|
In iOS, you add dependencies by adding to your Podfile.Flutter uses Dart’s own build system, and the Pub package manager.
|
The tools delegate the building of the native Android and iOS wrapper apps
|
to the respective build systems.In general, use pubspec.yaml to declare
|
external dependencies to use in Flutter.
|
A good place to find Flutter packages is on pub.dev.<topic_end>
|
<topic_start>
|
Application lifecycle
|
<topic_end>
|
<topic_start>
|
How do I listen to application lifecycle events?
|
In Xamarin.Forms, you have an Application
|
that contains OnStart, OnResume and OnSleep.
|
In Flutter, you can instead listen to similar 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 the AppLifecycleStatus documentation.<topic_end>
|
<topic_start>
|
Layouts
|
<topic_end>
|
<topic_start>
|
What is the equivalent of a StackLayout?
|
In Xamarin.Forms you can create a StackLayout
|
with an Orientation of horizontal or vertical.
|
Flutter has a similar approach,
|
however you would use the Row or Column widgets.If you notice the two code samples are identical
|
except the Row and Column widget.
|
The children are the same and this feature
|
can be exploited to develop rich layouts
|
that can change overtime with the same children.
|
<code_start>@override
|
Widget build(BuildContext context) {
|
return const Row(
|
mainAxisAlignment: MainAxisAlignment.center,
|
children: <Widget>[
|
Text('Row One'),
|
Text('Row Two'),
|
Text('Row Three'),
|
Text('Row Four'),
|
],
|
);
|
}<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>
|
<topic_end>
|
<topic_start>
|
What is the equivalent of a Grid?
|
The closest equivalent of a Grid would be a GridView.
|
This is much more powerful than what you are used to in Xamarin.Forms.
|
A GridView provides automatic scrolling when the
|
content exceeds its viewable space.
|
<code_start>@override
|
Widget build(BuildContext context) {
|
return GridView.count(
|
// Create a grid with 2 columns. If you change the scrollDirection to
|
// horizontal, this would produce 2 rows.
|
crossAxisCount: 2,
|
// Generate 100 widgets that display their index in the list.
|
children: List<Widget>.generate(
|
100,
|
(index) {
|
return Center(
|
child: Text(
|
'Item $index',
|
style: Theme.of(context).textTheme.headlineMedium,
|
),
|
);
|
},
|
),
|
);
|
}<code_end>
|
You might have used a Grid in Xamarin.Forms
|
to implement widgets that overlay other widgets.
|
In Flutter, you accomplish this with the Stack widget.This sample creates two icons that overlap each other.
|
<code_start>@override
|
Widget build(BuildContext context) {
|
return const Stack(
|
children: <Widget>[
|
Icon(
|
Icons.add_box,
|
size: 24,
|
color: Colors.black,
|
),
|
Positioned(
|
left: 10,
|
child: Icon(
|
Icons.add_circle,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.