Home > other >  How to put a value in external string
How to put a value in external string

Time:10-19

I have a Dart file that has all my strings (like strings.xml in Java) How can I write a dynamic string?

Texts {
  static const String welcome_msg = "Hello $user";
}

and in another Dart file, I want to have something like this:

Texts.welcome_message("Username");

P.S: I prefer to do it without writing a function

thanks, I'm apologizing if I describe what I meant bad

CodePudding user response:

You have to use a method with parameter for your case to work:

class Texts {
  static String welcomeMessage(String user) => 'Hello $user';
}

And then you can call it like this:

Texts.welcomeMessage('John Doe');
  • Related