Buscar pacotes, repositórios e categorias de apps

Detalhes do pacotev1.0.0+4

ready_view

Ao desenvolver com Flutter, é comum precisar usar operações assíncronas ao buscar informações da rede ou de bancos de dados. Nesses casos, precisamos incluir widgets de carregamento nas nossas páginas, acompanhar a conclusão do carregamento e exibir a visualização original assim que o carregamento for concluído. Incluir essa série de código pode tornar o código da interface bastante complexo e bagunçado. Por isso, a biblioteca ready_view oferece uma solução simples e elegante para lidar com ações assíncronas.

AndroidiOSWebmacOSWindowsLinux
Downloads em 30 dias
2
Curtidas
4
Pontos Pub
145

Instalar pacote

flutter pub add ready_view

Visão geral do pacote

Orientação gerada a partir de informações públicas. Apenas para referência.

ReadyView é um pacote Flutter/Dart projetado para simplificar o manuseio de operações assíncronas no desenvolvimento de interfaces. Ele oferece uma maneira clara e declarativa de gerenciar estados de carregamento, resultados bem-sucedidos e erros ao buscar dados em redes ou bancos de dados. Ao envolver conteúdo com o ReadyView, os desenvolvedores podem evitar código repetitivo para indicadores de carregamento e rastreamento de estado, resultando em árvores de widgets mais limpas e mais fáceis de manter. O pacote suporta todas as principais plataformas e se integra perfeitamente a projetos existentes do Flutter.

Casos de uso

  • Manipulação de respostas da API
  • Exibindo estados de carregamento
  • Gerenciando condições de erro
  • Simplificando a lógica de interface assíncrona
  • Substituindo a gestão manual de estado

Principais recursos

  • Estados de carregamento declarativos
  • Tratamento de erro embutido
  • Boilerplate mínimo
  • Suporte multiplataforma
  • Integração fácil com operações baseadas em Future

Indicado para

  • Desenvolvedores em busca de padrões de UI assíncrona limpa
  • Projetos com chamadas frequentes de rede/banco de dados
  • Equipes que desejam reduzir a complexidade do widget
  • Iniciantes do Flutter aprendendo fluxos assíncronos
  • Aplicativos que exigem feedback de carregamento responsivo

Considerações

  • Requer conhecimento sobre futuros
  • Limitado a envoltórios de operação assíncrona
  • Não adequado para máquinas de estado complexas
  • Pode ser necessário lógica adicional para mecanismos de repetição
  • Melhor usado com cenários simples de busca e exibição

README original

Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.

pub package GitHub

ready_view

Motivation

When developing with Flutter, it is often necessary to use asynchronous operations when fetching information from networks or databases. In such cases, we need to include loading widgets on our pages, track the completion of loading, and display the original view once the loading is complete. Including this series of code can make the view code quite complex and messy.

Therefore, the ready_view library offers a simple and elegant solution for handling asynchronous actions.

Installation

flutter pub add ready_view

Usage

1. Change Code
When Stateless Widget
// replace
StatelessWidget => ReadyStatelessWidget

build(BuildContext context) => buildWhenReady(BuildContext context)
Stateful Widget
// replace
extends State<.. => extends ReadyState<..

build(BuildContext context) => buildWhenReady(BuildContext context)
2. Add readyState(Optional)

When asynchronous actions are required, you can override the readyState() to perform the necessary tasks.

// handle async operation here if needed
@override
Function? readyState(BuildContext context) {
  return () async {
    // your async code here
    await Future.delayed(const Duration(seconds: 2));
  };
}
3. Custom Loading Widget(Optional)

You can customize the loading widget by overriding the loadingWidget() if you want.

  // custom loading widget if needed
  @override
  Widget loadingWidget() {
    return Scaffold(
        body: Center(
            child: Container(
      width: 100,
      height: 100,
      color: Colors.red,
    )));
  }

Example

Stateless Widget
import 'package:flutter/material.dart';
import 'package:ready_view/ready_view.dart';

class StatelessExample extends ReadyStatelessWidget {
  const StatelessExample({super.key});

  // handle async operation here if needed
  @override
  Function? readyState(BuildContext context) {
    return () async {
      await Future.delayed(const Duration(seconds: 2));
    };
  }

  // custom loading widget if needed
  // @override
  // Widget loadingWidget() {
  //   return Scaffold(
  //       body: Center(
  //           child: Container(
  //     width: 100,
  //     height: 100,
  //     color: Colors.red,
  //   )));
  // }

  @override
  Widget buildWhenReady(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('StatelessExample'),
      ),
      body: const Center(
        child: Text('Content is ready!'),
      ),
    );
  }
}

void main() {
  runApp(const MaterialApp(
    home: StatelessExample(),
  ));
}
Stateful Widget
import 'package:flutter/material.dart';
import 'package:ready_view/ready_view.dart';

class StatefulExample extends StatefulWidget {
  const StatefulExample({super.key});

  @override
  ReadyState<StatefulExample> createState() => _StatefulExampleState();
}

class _StatefulExampleState extends ReadyState<StatefulExample> {
  
  // handle async operation here if needed
  @override
  Function? readyState(BuildContext context) {
    return () async {
      await Future.delayed(const Duration(seconds: 2));
    };
  }

  // custom loading widget if needed
  // @override
  // Widget loadingWidget() {
  //   return Scaffold(
  //       body: Center(
  //           child: Container(
  //     width: 100,
  //     height: 100,
  //     color: Colors.red,
  //   )));
  // }

  @override
  Widget buildWhenReady(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('StatefulExample'),
      ),
      body: const Center(
        child: Text('Content is ready!'),
      ),
    );
  }
}

void main() {
  runApp(const MaterialApp(
    home: StatefulExample(),
  ));
}
Comparison with FutureBuilder

Although similar to FutureBuilder, using FutureBuilder asynchronously when the view is first created requires setting up related state, including calling asynchronous functions in initState, and placing the FutureBuilder in the build function along with a separate loading widget. In contrast, ready_view allows you to keep your existing code as it is, while providing a cleaner and more intuitive way to handle asynchronous actions by separately calling the readyState and loadingWidget functions when needed.

Categorias

Repositório-fonte

Projetos que usam este pacote

Ainda não há dados.