Pular para o conteúdo
Snippets·Grátis

Snippets de Dart e Flutter

20 snippets de Dart e Flutter: initState e dispose, Scaffold, FutureBuilder e StreamBuilder, ListView.builder, navegação, diálogos e SnackBars, um modelo JSON com copyWith e testes de unidade e de widget.

Instalação grátis.

Se o PocketCode estiver instalado no seu Android, isto abre a página no app.

Prévia

5 de 20

initStateinitst

Set up a State object once, before the first build

@override
void initState() {
  super.initState();
  $0
}

disposedisp

Release controllers when the widget leaves the tree

@override
void dispose() {
  ${1:_controller}.dispose();
  super.dispose();
}

Scaffold with an app barscaff

Screen skeleton with a title bar and a body

Scaffold(
  appBar: AppBar(title: const Text('${1:Title}')),
  body: ${2:const Placeholder()},
)

FutureBuilderfutbuild

Show a spinner, the error or the result of a Future

FutureBuilder<${1:String}>(
  future: ${2:_future},
  builder: (context, snapshot) {
    if (snapshot.connectionState != ConnectionState.done) {
      return const CircularProgressIndicator();
    }
    if (snapshot.hasError) {
      return Text(snapshot.error.toString());
    }
    return Text(${3:snapshot.data ?? ''});
  },
)

StreamBuilderstreambld

Rebuild every time a Stream emits a value

StreamBuilder<${1:int}>(
  stream: ${2:_counter},
  builder: (context, snapshot) {
    if (!snapshot.hasData) {
      return const CircularProgressIndicator();
    }
    return Text(${3:snapshot.data.toString()});
  },
)

Mudanças na 1.0.0

Primeira versão.

Relacionados