Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String xml file in Flutter

In flutter string text are directly set to the TextField widget like:

new Text('Hello,  How are you?') 

Is correct way ? or we can maintain all string in one file and use it like:

<string name="name_hint">Hello, How are you?</string> 

Is it possible ?

like image 356
Magesh Pandian Avatar asked Apr 27 '18 17:04

Magesh Pandian


People also ask

Is it possible to create string text in flutter?

In flutter string text are directly set to the TextField widget like: new Text ('Hello, How are you?') Is correct way ? or we can maintain all string in one file and use it like: Is it possible ? Flutter currently doesn’t have a dedicated resources-like system for strings.

What is AndroidManifest XML in flutter?

The AndroidManifest.xml file describes essential information about your app to the Android build tools, the Android operating system, and Google Play. The AndroidManifest.xml file of a Flutter project locates at: <project-root>/android/app/src/main/AndroidManifest.xml

Is there a correct way to manage layout in flutter?

That is the correct way. In flutter you don't need .xml or .css files to manage your layout/stuff. Everything is managed using the dart code.

Where can I find the manifest file in flutter?

The AndroidManifest.xml file of a Flutter project locates at: <project-root>/android/app/src/main/AndroidManifest.xml If you only want to make an app for iOS devices, you can ignore this file and the entire android folder. You can also check out our Flutter category page or Dart category page for the latest tutorials and examples.


1 Answers

Flutter currently doesn’t have a dedicated resources-like system for strings. At the moment, the best practice is to hold your copy text in a class as static fields and accessing them from there. For example:

class Strings {   static const String welcomeMessage = "Welcome To Flutter"; } 

Then in your code, you can access your strings as such:

Text(Strings.welcomeMessage) 

source


Edit May '19:

There's now this package that allows you to create json files with your Strings. It will allow you to create Strings for plurals, genders and languages etc

You can create a separate json file for each language like so:

string_en.json

{ "thanks": "Thanks." } 

string_nl.json

{     "thanks": "Dankjewel." } 

And then use this to access it

S.of(context).thanks; 

It will know which language to choose based on your phone's default language.

like image 169
MSpeed Avatar answered Sep 18 '22 18:09

MSpeed