class FormularioTransferencia extends StatelessWidget {
final TextEditingController _controlNumonta = TextEditingController(); final TextEditingController _controlValor = TextEditingController();
@override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Criando Transferência'), backgroundColor: Colors.orange ), body: Column( children: [ criarTextField('Número da conta','000-0', 20.0, LTRB(8.0, 8.0, 8.0, 8.0), const Icon(null), TextInputType.number, controlNumonta), // Instancia objetos texto criarTextField('Valor','0,00', 16.0, LTRB(50.0, 8.0 , 8.0, 8.0), const Icon(Icons.monetizationon), TextInputType.number, _controlValor), criarBotao('Confirmar', _controlNumonta, _controlValor) ], )); } }
class criarBotao extends StatelessWidget { final String _textoBotao; final TextEditingController _controlNumConta ; final TextEditingController _controlValor ;
criarBotao(this.textoBotao, this.controlNumConta, this._controlValor);
@override Widget build(BuildContext context) { return ElevatedButton( child: Text(_textoBotao), onPressed: () => criaTransferencia(context), ); }
void criaTransferencia(BuildContext context) { // Cria a transferencia final numeroConta = int.tryParse(controlNumConta.text); final valor = double.tryParse(controlValor.text); if (numeroConta != null && valor != null) { final tranferenciaCriada = Transferencia(valor, numeroConta); Navigator.pop(context, tranferenciaCriada); } } }
class criarTextField extends StatelessWidget{
final String label; final String hint; final double fontSize; final LTRB Ltrb; final Icon icon; final TextInputType KeyType; final TextEditingController controller; // define instância
criarTextField(this.label, this.hint, this.fontSize, this.Ltrb, this.icon, this.KeyType, this.controller);
@override Widget build(BuildContext context) { return Padding( padding: EdgeInsets.fromLTRB(Ltrb.esquerda, Ltrb.cima, Ltrb.direita, Ltrb.abaixo), child: TextField( controller: controller, style: TextStyle( fontSize: fontSize ), decoration: InputDecoration( icon: icon, labelText: label, hintText: hint, ), keyboardType: KeyType, ), ); } }
class ListaTransferencias extends StatefulWidget { final List _transferencias = [];
@override State createState() => ListaTransferenciasState(); }
class ListaTransferenciasState extends State {
@override Widget build(BuildContext context) { widget.transferencias.add(Transferencia(10, 10)); return Scaffold( appBar: AppBar( title: const Text('Byte bank'), centerTitle: true, backgroundColor: Colors.orange, ), body: ListView.builder( itemCount: widget.transferencias.length, itemBuilder: (context, int indice) { final transferencia = widget.transferencias[indice]; print('transferencias'); return ItemTransferencia(transferencia); }, ), floatingActionButton: FloatingActionButton( child: Icon(Icons.add), onPressed: () { final Future future = Navigator.push(context, MaterialPageRoute(builder: (context) { return FormularioTransferencia(); })); future.then((transferenciaRecebida) { if (transferenciaRecebida != null) { widget.transferencias.add(transferenciaRecebida); debugPrint(widget._transferencias.toString()); } }); }, ), ); } }
class ItemTransferencia extends StatelessWidget {
final Transferencia _transferencia; // Variavel com o valor
ItemTransferencia(this._transferencia); // Construtor
@override Widget build(BuildContext context) { return Card( child: ListTile( leading: const Icon(Icons.monetization_on), title: Text(transferencia.valor.toString()), subtitle: Text(transferencia.numeroConta.toString()) ), ); } }
class Transferencia { final int numeroConta; final double valor;
Transferencia(this.valor, this.numeroConta);
@override String toString() { return 'Transferencia{valor: $valor, numeroConta: $numeroConta}'; } }