Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Falha na aplicação Superclass has no method named 'inheritFromElement'.

Após implementar as alterações da aula 03 Usando Provider parte 02 adiciona meu app apresentou o seguinte erro:


FAILURE: Build failed with an exception.

* Where:
Script '/opt/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 1156

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/opt/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 26s
Exception: Gradle task assembleDebug failed with exit code 1
Exited

Eu fiz a implementação na versão do curso após o crashAnalytics com Firebase. Nela o dashboard está um pouco diferente do apresentado neste treinamento. Não sei porque não deram continuidade na versão com o crashAnalytics.

Código do Dashboard com a implementação do Saldo e o botão Adiciona

class Dashboard extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Dashboard'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Image.asset('images/bytebank_logo.png'),
            ),
            Container(
                child: ListView(children: <Widget>[
              Align(
                alignment: Alignment.topCenter,
                child: SaldoCard(),
              ),
              Consumer<Saldo>(builder: (context, saldo, child) {
                return ElevatedButton(
                    child: Text('Adiciona'),
                    onPressed: () {
                      saldo.adiciona(10);
                    });
              })
            ])),
            Container(
              height: 120,
              child:
                  ListView(scrollDirection: Axis.horizontal, children: <Widget>[
                _FeatureItem('Transfer', Icons.monetization_on, onClick: () {
                  _showContactsList(context);
                }),
                _FeatureItem('Transaction feed', Icons.description,
                    onClick: () => _showTransactionFeed(context)),
                _FeatureItem('Nova feature', Icons.done, onClick: () {
                  print('press New feature');
                })
              ]),
            ),
          ],
        ));

Alguém tem ideia do que eu devo fazer para corrigir este erro?

3 respostas

Olá, tenta apagar os arquivos de build que são gerados automaticamente eles ficam no repositório flutter, depois vc vai no yaml e pressiona pug get.

Ok. Antonio obrigado pelas dicas. Nos últimos dias fui pesquisando pelos erros e consegui resolver vou compartilhar o passo a passo da resolução.

solução!

Partindo do erro inicial Superclass has no method named 'inheritFromElement' fiz os seguintes passos

Realizar o downgrade da versão do flutter https://stackoverflow.com/questions/65749767/error-the-method-inheritfromwidgetofexacttype-isnt-defined-for-the-class-bu

Atualizar a versão do provider https://github.com/obnil/flutter_music_app/issues/14

Após atualizações ele apresentou outro erro na execução

════════ Exception caught by rendering library ═════════════════════════════════
RenderBox was not laid out: RenderRepaintBoundary#1a7d5 relayoutBoundary=up2 NEEDS-PAINT
'package:flutter/src/rendering/box.dart':
package:flutter/…/rendering/box.dart:1
Failed assertion: line 1979 pos 12: 'hasSize'

The relevant error-causing widget was
Column
lib/…/dashboard/dashboard.dart:15
═════════════════

Como o downgrade não resolveu decidi atualizar o flutter novamente. Na época da resolução do problema a versão dele foi a 3.0.5

Investigando o novo erro gerador

RenderBox was not laid out: RenderViewport#44d5b NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart':

Encontrei esta outra dica de resolução https://stackoverflow.com/questions/52801201/flutter-renderbox-was-not-laid-out

Fiz alguns ajustes na dashboard.dart e agora consigo carregar o novo campo de saldo e o botão de forma correta: Dashboard Bytebank com o campo de saldo e botão adicionar

Um dos componentes que estava gerando erro na página foi o container que carrega o saldoCard. Inicialmente deixei o height dele com 100 e ele estorou o espaço da tela

Container(
                height: 100,
                child: ListView(
                  children: <Widget>[
                    Align(
                      alignment: Alignment.topCenter,
                      child: SaldoCard(),
                    )
                  ],
                ),
              ),

Dashboard com erro na renderização

A solução foi alterar o height para 80 e dai a tela renderizou de forma correta.

Segue código fonte no github branch Gerenciamento-estados https://github.com/estevamdf2/bytebank_alura/tree/gerenciamento-estados

Segue abaixo código da dashboard.dart com as alterações

class Dashboard extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('Dashboard'),
        ),
        body: Column(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.all(8.0),
                child: Image.asset('images/bytebank_logo.png'),
              ),
              Container(
                height: 80,
                child: ListView(
                  children: <Widget>[
                    Align(
                      alignment: Alignment.topCenter,
                      child: SaldoCard(),
                    )
                  ],
                ),
              ),
              Consumer<Saldo>(builder: (context, saldo, child) {
                return ElevatedButton(
                    child: Align(
                      alignment: Alignment.bottomCenter,
                      child: Text('Adiciona'),
                    ),
                    onPressed: () {
                      saldo.adiciona(10);
                    });
              }),
              Container(
                height: 120,
                child: ListView(
                    scrollDirection: Axis.horizontal,
                    children: <Widget>[
                      _FeatureItem('Transfer', Icons.monetization_on,
                          onClick: () {
                        _showContactsList(context);
                      }),
                      _FeatureItem('Transaction feed', Icons.description,
                          onClick: () => _showTransactionFeed(context)),
                      _FeatureItem('Nova feature', Icons.done, onClick: () {
                        print('press New feature');
                      })
                    ]),
              ),
            ]));
  }

  ....
  //outros métodos

}

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software