I want to put the context widget in a string variable

I want to put the context widget in a string variable like that

String check = "$context.widget";

But I do it like that:

Widget checks = context.widget;
String check = "$checks";

as the . when i type it between “” the compiler just read context as a variable and .widget as a text so please advice

  • Please try using this approach, as I believe it will be helpful for your situation: String check = checks.toString();

    – 

  • 1

    Does this answer your question? Proper Syntax When Using dot Operator in String Interpolation in Dart

    – 

In your case, you’re evaluating an identifier, so you should use curly braces:

String check= "${context.widget}";

from dart docs:
You can use ${} to interpolate the value of Dart expressions within strings. The curly braces can be omitted when evaluating identifiers:

const string = 'dartlang';
print('$string has ${string.length} letters'); // dartlang has 8 letters

Leave a Comment