Acompanhei a aula até o final pra ver se de alguma maneira o problema se resolveria, mas não teve jeito. Sou iniciante em programação em geral e não consegui descobrir o motivo de tanto erro, se copiei o código de acordo com a aula.
Minha versão do Flutter:
Flutter 2.5.0 Dart 2.14.0
class FormularioTransferencia extends StatelessWidget {
final TextEditingController _controladorCampoNumeroConta = TextEditingController();
final TextEditingController _controladorCampoValor = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Criando transferência'),
),
body: Column(
children: const [
Padding(
padding: EdgeInsets.all(16.0),
child: TextField(
controller: _controladorCampoNumeroConta,
style: TextStyle(
fontSize: 24.0,
),
decoration: InputDecoration(
labelText: 'Número da conta',
hintText: '0000',
),
keyboardType: TextInputType.number,
),
),
Padding(
padding: EdgeInsets.all(16.0),
child: TextField(
controller: _controladorCampoValor,
style: TextStyle(
fontSize: 24.0,
),
decoration: InputDecoration(
icon: Icon(Icons.monetization_on),
labelText: 'Valor',
hintText: '0000',
),
keyboardType: TextInputType.number,
),
),
ElevatedButton(
child: Text('Confirmar'),
onPressed: () {
debugPrint('clicou confirmar');
final int numeroConta = int.tryParse(_controladorCampoNumeroConta.text);
final double valor = double.tryParse(_controladorCampoValor.text);
if(numeroConta != null && valor != null){
final transferenciaCriada = Transferencia(valor, numeroConta);
debugPrint('$transferenciaCriada');
}
},
),
],
));
}
}
class ItemTransferencia extends StatelessWidget {
final Transferencia _transferencia;
ItemTransferencia(this._transferencia);
@override
Widget build(BuildContext context) {
return Card(
child: ListTile(
leading: Icon(Icons.monetization_on),
title: Text(_transferencia.valor.toString()),
subtitle: Text(_transferencia.numeroConta.toString()),
),
);
}
}
class Transferencia {
final double valor;
final int numeroConta;
Transferencia(this.valor, this.numeroConta);
@override
String toString() {
return 'Transferencia{valor: $valor, numeroConta: $numeroConta}';
}
}
Os erros são estes:
lib/main.dart:32:29: Error: Not a constant expression.
controller: _controladorCampoNumeroConta,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lib/main.dart:46:29: Error: Not a constant expression.
controller: _controladorCampoValor,
^^^^^^^^^^^^^^^^^^^^^^
lib/main.dart:61:17: Error: Not a constant expression.
debugPrint('clicou confirmar');
^^^^^^^^^^
lib/main.dart:61:17: Error: Method invocation is not a constant expression.
debugPrint('clicou confirmar');
^^^^^^^^^^
lib/main.dart:64:20: Error: Not a constant expression.
if(numeroConta != null && valor != null){
^^^^^^^^^^^
lib/main.dart:64:43: Error: Not a constant expression.
if(numeroConta != null && valor != null){
^^^^^
lib/main.dart:66:19: Error: Not a constant expression.
debugPrint('$transferenciaCriada');
^^^^^^^^^^
lib/main.dart:66:32: Error: Not a constant expression.
debugPrint('$transferenciaCriada');
^^^^^^^^^^^^^^^^^^^
lib/main.dart:66:19: Error: Method invocation is not a constant expression.
debugPrint('$transferenciaCriada');
^^^^^^^^^^
lib/main.dart:60:26: Error: Not a constant expression.
onPressed: () {
^^
lib/main.dart:28:21: Error: Constant evaluation error:
children: const [
^
lib/main.dart:32:29: Context: Not a constant expression.
controller: _controladorCampoNumeroConta,
^
Tentei algumas soluções sugeridas nos outros tópicos, mas sem sucesso.