Expanded with non-constant Text child

  Kiến thức lập trình

I’m trying to create DataTable with localized header. However Expanded does not take non-constant child.

String col1 = MainLocalizations.of(context)!.getText('col1').toString()!;
    Text txt = Text(
      col1,
      style: TextStyle(fontStyle: FontStyle.italic),
    );

    return DataTable(
      columns: const <DataColumn>[
        DataColumn(
          label: Expanded(
            child: txt, // PROBLEM
          ),
        )

Compilation fails with

lib/main.dart:85:20: Error: Not a constant expression.
            child: txt,
                   ^^^

I need a way to create localized DataTable layout. Please advise.

LEAVE A COMMENT