Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

creio que fiz como a professar fez, porem esta dando este erro no Widget _construirHome() em appBar: _construirAppBar().

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
          // This is the theme of your application.
          //
          // Try running your application with "flutter run". You'll see the
          // application has a blue toolbar. Then, without quitting the app, try
          // changing the primarySwatch below to Colors.green and then invoke
          // "hot reload" (press "r" in the console where you ran "flutter run",
          // or simply save your changes to "hot reload" in a Flutter IDE).
          // Notice that the counter didn't reset back to zero; the application
          // is not restarted.
          primarySwatch: Colors.deepOrange,
        ),
        home: Home()
    );
  }
}

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return _construirHome();

  }

   Widget _construirHome() {
    return Scaffold(
      body:  _construirCard(),
      appBar: _construirAppBar(),
    );
  }

  Widget _construirCard() {
    return SizedBox(
        height: 300,
        child: Card(
            margin: EdgeInsets.all(16),
            child: Column(
              children: <Widget>[
                Stack(
                  children: <Widget>[
                    _construirImagemCard(),
                    _construirTextoCard()
                  ],
                )
              ],
            )
        )
    );
  }

  Widget _construirTextoCard() {
    return Positioned(
        bottom: 10,
        left: 10,
        child: Text('Bolo de Chocolate',
            style: TextStyle(fontSize: 20))
    );
  }

  Widget _construirImagemCard() {
    return Image.network(
        'https://www.oetker.com.br/Recipe/Recipes/oetker.com.br/br-pt/baking/image-thumb__40008__RecipeDetailsLightBox/bolo-de-aniversario-de-chocolate.jpg',
        fit: BoxFit.fill, height: 268);
  }



  Widget _construirAppBar() {

    return AppBar(centerTitle: true,title: Text('Cozinhando em Casa'));


  }

}
1 resposta
solução!

Fala Natanael, tudo certo?

Vê, o erro está sendo causado pois o tipo do retorno da função_construirAppBar está definido como um Widget:

Widget _construirAppBar() {

    return AppBar(centerTitle: true,title: Text('Cozinhando em Casa'));

  }

Sendo que o tipo que o parâmetro "appBar" do Scaffold espera é AppBar. Para resolver, basta mudar esse tipo para AppBar:

AppBar _construirAppBar() {
    return AppBar(centerTitle: true, title: Text('Cozinhando em Casa'));
  }

-

Para saber mais
Todo AppBar é um Widget, mas nem todo Widget é uma AppBar. Isso quer dizer que o AppBar é uma especificação de Widget, e Widget é uma generalização do AppBar. Isso explica o por quê de não ter dado erro no seu return, mas ter dado erro no Scaffold.

-

Show? Espero ter ajudado, e qualquer coisa é só mandar! Estamos aqui para isso!

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