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: <Widget>[
Padding(
padding: const 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: const EdgeInsets.all(16.0),
child: TextField(
controller: _controladorCampoValor,
style: TextStyle(
fontSize: 24.0,
),
decoration: InputDecoration(
icon: Icon(Icons.monetization_on),
labelText: 'Valor',
hintText: '0.00'
),
keyboardType: TextInputType.number,
),
),
ElevatedButton(
onPressed: () {
debugPrint('clicou no confirmar');
final int numeroConta = int.tryParse(_controladorCampoNumeroConta);
final double valor = double.tryParse(_controladorCampoValor);
if(numeroConta != null && valor != null){
final transferenciaCriada = Transferencia(valor, numeroConta);
debugPrint('$transferenciaCriada');
}
},
child: const Text(
"Confirmar",
style: TextStyle(fontSize: 24),
),
)
],
),
);
}
}
class ListaTransferencia extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return Scaffold(
appBar: AppBar(
title: Text('Transferências'),
),
body: Column(
children: <Widget>[
ItemTransferencia(Transferencia(100.0, 1000)),
ItemTransferencia(Transferencia(200.0, 2000)),
ItemTransferencia(Transferencia(300.0, 3000)),
],
),
floatingActionButton: FloatingActionButton(
onPressed: () { },
child: Icon(Icons.add),
),
);
}
}
class ItemTransferencia extends StatelessWidget {
final Transferencia _transferencia;
ItemTransferencia(this._transferencia);
@override
Widget build(BuildContext context) {
// TODO: implement build
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 'Transfrerencia{valor: $valor, numeroConta: $numeroConta}';
}
}
retorna os seguintes erros :
ERROR: lib/main.dart:63:50: Error: The argument type 'TextEditingController' can't be assigned to the parameter type 'String'.
ERROR: - 'TextEditingController' is from 'package:flutter/src/widgets/editable_text.dart' ('../../snap/flutter/common/flutter/packages/flutter/lib/src/widgets/editable_text.dart').
ERROR: final int numeroConta = int.tryParse(_controladorCampoNumeroConta);
ERROR: ^
ERROR: lib/main.dart:63:41: Error: A value of type 'int?' can't be assigned to a variable of type 'int' because 'int?' is nullable and 'int' isn't.
ERROR: final int numeroConta = int.tryParse(_controladorCampoNumeroConta);
ERROR: ^
ERROR: lib/main.dart:64:50: Error: The argument type 'TextEditingController' can't be assigned to the parameter type 'String'.
ERROR: - 'TextEditingController' is from 'package:flutter/src/widgets/editable_text.dart' ('../../snap/flutter/common/flutter/packages/flutter/lib/src/widgets/editable_text.dart').
ERROR: final double valor = double.tryParse(_controladorCampoValor);
ERROR: ^
ERROR: lib/main.dart:64:41: Error: A value of type 'double?' can't be assigned to a variable of type 'double' because 'double?' is nullable and 'double' isn't.
ERROR: final double valor = double.tryParse(_controladorCampoValor);
ERROR: ^