text
stringlengths 1
372
|
---|
"username":{ |
"type":"string", |
"example":"bob" |
} |
} |
} |
} |
<code_end> |
then in your code, you can access your strings as such: |
<code_start> |
Text(AppLocalizations.of(context)!.hello('John')); |
<code_end> |
flutter has basic support for accessibility on android, |
though this feature is a work in progress. |
see internationalizing flutter apps for more information on this. |
<topic_end> |
<topic_start> |
what is the equivalent of a gradle file? how do i add dependencies? |
in android, you add dependencies by adding to your gradle build script. |
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. |
while there are gradle files under the android folder in your |
flutter project, only use these if you are adding native |
dependencies needed for per-platform integration. |
in general, use pubspec.yaml to declare |
external dependencies to use in flutter. |
a good place to find flutter packages is pub.dev. |
<topic_end> |
<topic_start> |
activities and fragments |
<topic_end> |
<topic_start> |
what are the equivalent of activities and fragments in flutter? |
in android, an activity represents a single focused thing the user can do. |
a fragment represents a behavior or a portion of user interface. |
fragments are a way to modularize your code, compose sophisticated |
user interfaces for larger screens, and help scale your application UI. |
in flutter, both of these concepts fall under the umbrella of widgets. |
to learn more about the UI for building activities and fragments, |
see the community-contributed medium article, |
flutter for android developers: how to design activity UI in flutter. |
as mentioned in the intents section, |
screens in flutter are represented by widgets since everything is |
a widget in flutter. use a navigator to move between different |
routes that represent different screens or pages, |
or perhaps different states or renderings of the same data. |
<topic_end> |
<topic_start> |
how do i listen to android activity lifecycle events? |
in android, you can override methods from the activity to capture lifecycle |
methods for the activity itself, or register ActivityLifecycleCallbacks on |
the application. 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 the |
AppLifecycleStatus documentation. |
as you might have noticed, only a small minority of the activity |
lifecycle events are available; while FlutterActivity does |
capture almost all the activity lifecycle events internally and |
send them over to the flutter engine, they’re mostly shielded |
away from you. flutter takes care of starting and stopping the |
engine for you, and there is little reason for needing to |
observe the activity lifecycle on the flutter side in most cases. |
if you need to observe the lifecycle to acquire or release any |
native resources, you should likely be doing it from the native side, |
at any rate. |
here’s an example of how to observe the lifecycle status of the |
containing activity: |
<code_start> |
import 'package:flutter/widgets.dart'; |
class LifecycleWatcher extends StatefulWidget { |
const LifecycleWatcher({super.key}); |
@override |
State<LifecycleWatcher> createState() => _LifecycleWatcherState(); |
} |
class _LifecycleWatcherState extends State<LifecycleWatcher> |
with WidgetsBindingObserver { |
AppLifecycleState? _lastLifecycleState; |
@override |
void initState() { |
super.initState(); |
WidgetsBinding.instance.addObserver(this); |
} |
@override |
void dispose() { |
WidgetsBinding.instance.removeObserver(this); |
super.dispose(); |
} |
@override |
void didChangeAppLifecycleState(AppLifecycleState state) { |
setState(() { |
_lastLifecycleState = state; |
}); |
} |
@override |
widget build(BuildContext context) { |
if (_lastlifecyclestate == null) { |
return const text( |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.