Saltar al contenido
Snippets·Gratis

Snippets de Dart y Flutter

20 snippets de Dart y Flutter: initState y dispose, Scaffold, FutureBuilder y StreamBuilder, ListView.builder, navegación, diálogos y SnackBars, un modelo JSON con copyWith y tests unitarios y de widgets.

Se instala gratis.

Si tienes PocketCode instalado en tu Android, esto abre la página en la app.

Vista previa

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()});
  },
)

Cambios en la 1.0.0

Primera versión.

Relacionados