text
stringlengths
1
372
by default, flutter only supports US english for its strings.
if you need to add support for other languages,
include the flutter_localizations package.
you might also need to add dart’s intl
package to use i10n machinery, such as date/time formatting.
to use the flutter_localizations package,
specify the localizationsDelegates and
supportedLocales on the app widget:
<code_start>
import 'package:flutter_localizations/flutter_localizations.dart';
class MyWidget extends StatelessWidget {
const MyWidget({super.key});
@override
widget build(BuildContext context) {
return const MaterialApp(
localizationsDelegates: <localizationsdelegate<dynamic>>[
// add app-specific localization delegate[s] here
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
supportedLocales: <locale>[
locale('en', 'us'), // english
locale('he', 'il'), // hebrew
// ... other locales the app supports
],
);
}
}
<code_end>
the delegates contain the actual localized values,
while the supportedLocales defines which locales the app supports.
the above example uses a MaterialApp,
so it has both a GlobalWidgetsLocalizations
for the base widgets localized values,
and a MaterialWidgetsLocalizations for the material widgets localizations.
if you use WidgetsApp for your app, you don’t need the latter.
note that these two delegates contain “default” values,
but you’ll need to provide one or more delegates
for your own app’s localizable copy,
if you want those to be localized too.
when initialized, the WidgetsApp (or MaterialApp)
creates a localizations widget for you,
with the delegates you specify.
the current locale for the device is always accessible
from the localizations widget from the current context
(in the form of a locale object), or using the window.locale.
to access localized resources, use the localizations.of() method
to access a specific localizations class that is provided by a given delegate.
use the intl_translation package to extract translatable copy
to arb files for translating, and importing them back into the app
for using them with intl.
for further details on internationalization and localization in flutter,
see the internationalization guide, which has sample code
with and without the intl package.
<topic_end>
<topic_start>
where is my project file?
in Xamarin.Forms you will have a csproj file.
the closest equivalent in flutter is pubspec.yaml,
which contains package dependencies and various project details.
similar to .net standard,
files within the same directory are considered part of the project.
<topic_end>
<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.