tiede_builder_pkg

Creator: coderz1093

Last updated:

0 purchases

TODO
Add to Cart

Description:

tiede builder pkg

Tiede Builder Package
Features #
TODO: Package para builder de UI's sem renderização de toda interface, será reconstruído somente widgets que precisam de renderização
Getting started #

Entre no arquivo pubspec.yaml
Adicione isto ao arquivo pubspec.yaml do seu pacote:

dependencies:
tiede_builder_pkg: ^1.0.1
copied to clipboard

Get dependencies

flutter pub get
copied to clipboard
Usage #
TODO: Caso de uso.

Consumir uma API para teste na classe Cidades que receberá alteração para exemplo de notificação de alterações de dados

import "dart:convert";
import "package:http/http.dart" as http;

class ApiConsumer {

Future<List> get(String uf) async {
try{
var response = await http.get(Uri.parse('https://brasilapi.com.br/api/ibge/municipios/v1/$uf?providers=dados-abertos-br,gov,wikipedia'));
return jsonDecode(response.body);
} catch(e) {
return [];
}
}

}
copied to clipboard

Uso da classe TiedeNotify para notificar alterações em variavéis da classe Cidades quando um novo dado for alterado

import 'package:tiede_builder_pkg/tiede_builder_pkg.dart';
import 'api_consumer.dart';

class Cidades extends TiedeNotify{

List cidades = [];
String uf = 'MG';

getCidades({String uf = 'MG'}) async {
this.uf = uf;
cidades.clear();

notify(isLoading: true); // --------> NOTIFICA ALTERAÇÃO PARA RECONSTRUIR WIDGET E ATIVA LOADING

ApiConsumer().get(uf).then((value) {
cidades = value;
print('get ok');

notify(); // --------> NOTIFICA ALTERAÇÃO PARA RECONSTRUIR WIDGET APOS MODIFICAÇÃO DOS DADOS

});
}

}

copied to clipboard

Uso da classe TiedeBuilder para reconstruir widgets que precisam sofrer alteração

import 'package:flutter/material.dart';
import 'package:tiede_builder_pkg/tiede_builder_pkg.dart';
import 'cidades_controller.dart';

class HomePage extends StatelessWidget {
HomePage({super.key});

Cidades cidades = Cidades();

@override
Widget build(BuildContext context) {
print('build home page');

return Scaffold(

appBar: AppBar(
title: const Text('Cidades'),
),

body: Column(
children: [

Padding(
padding: const EdgeInsets.all(20.0),
child: TextField(
decoration: const InputDecoration(
hintText: 'UF',
border: OutlineInputBorder(),
),
onChanged: (value) {
if(value.toUpperCase().length == 2) {
cidades.getCidades(uf: value.toUpperCase());
}
}
),
),

Flexible(
child: Padding(
padding: const EdgeInsets.all(20.0),

// RECONSTRUIR GALHOS DA ARVORE DE WIDGETS
child: TiedeBuilder(
notify: cidades,
builder: (context)=>
cidades.isLoading
? const CircularProgressIndicator()
: ListView(
children: cidades.cidades.map((e) => Text('${e['nome']} - ${cidades.uf}')).toList(),
),
),
),
),

// RECONSTRUIR GALHOS DA ARVORE DE WIDGETS
TiedeBuilder(
notify: cidades,
builder: (context)=>
Padding(
padding: const EdgeInsets.all(12.0),
child: Text('Total de cidades: ${cidades.cidades.length}'),
),
),

],
),
);
}
}

copied to clipboard

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.