Ir para conteúdo
Fluttership
  • Cadastre-se
Entre para seguir isso  
Alex Castro

Flutter v1.8.3

Recommended Posts

Atualização referente as funções assíncronas

 

 

#34545 In order to keep errors from getting inadvertently swallowed in FutureBuilder and StreamBuilder, the following changes were made to those APIs (announcement😞

  • AsyncSnapshot.data now throws an error if AsyncSnapshot.hasData is false. Callers can guard against this by consulting AsyncSnapshot.hasData before accessing the data property:

    Before

    builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
      String data = snapshot.data ?? 'default_value';
      ...
    },

    After

    builder: (BuildContext context, AsyncSnapshot snapshot) {
      String data = snapshot.hasData ? snapshot.data : 'default_value';
      ...
    },
  • AsyncSnapshot.requireData was removed. Callers who are using this can update their code by accessing AsyncSnapshot.data instead, which now behaves the way that requireDatadid.

  • The initialData argument to the StreamBuilder() constructor is now a required argument. Callers who do not wish to pass initial data may use the newly added StreamBuilder.withoutInitialData() constructor. This should go in tandem with a change that checks for snapshot.hasData in your builder method:

    Before

    return StreamBuilder<String>(
      stream: myStream,
      builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
        return Text(snapshot.data ?? 'default_value');
      },
    );

    After

    return StreamBuilder<String>.withoutInitialData(
      stream: someStream,
      builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
        return Text(snapshot.hasData ? snapshot.data : 'default_value');
      },
    );
  • The initialData argument to the FutureBuilder() constructor is now deprecated and will be removed in a future release. Callers who are using FutureBuilder.initialDatashould instead check the snapshot's connection state in their builder method:

    Before

    return FutureBuilder<String>(
      future: someFuture,
      initialData: 'initial_value',
      builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
        return Text(snapshot.data);
      },
    );

    After

    return FutureBuilder<String>(
      future: someFuture,
      builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
        return Text(snapshot.connectionState == ConnectionState.done
            ? snapshot.data
            : 'initial_value');
      },
    );

     

    Fonte: https://github.com/flutter/flutter/wiki/Changelog

Compartilhar este post


Link para o post
Compartilhar em outros sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Visitante
Responder

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Entre para seguir isso  

×
×
  • Criar Novo...