• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Flutter 게시판 Future 다루기 그리고 FutureBuilder

Future 다루기 그리고 FutureBuilder

  • 이 주제에는 9개 답변, 2명 참여가 있으며 익명2 년, 4 월 전에 전에 마지막으로 업데이트했습니다.
10 글 보임 - 1 에서 10 까지 (총 10 중에서)
  • 글쓴이
  • #66391

    익명
    비활성
    Future 다루기 그리고 FutureBuilder 위 강의에서 이렇게 오류가 나네요. 도움이 필요합니다. ㅠ
    
    Launching lib/main.dart on Chrome in debug mode...
    Waiting for connection from debug service on Chrome...
    lib/main.dart:25:7: Error: The non-abstract class '_MyAppState' is missing implementations for these members:
     - State.build
    Try to either
     - provide an implementation,
     - inherit an implementation from a superclass or mixin,
     - mark the class as abstract, or
     - provide a 'noSuchMethod' implementation.
    class _MyAppState extends State<MyApp> {
          ^^^^^^^^^^^
    ../Downloads/flutter/packages/flutter/lib/src/widgets/framework.dart:1370:10: Context: 'State.build' is defined here.
      Widget build(BuildContext context);
             ^^^^^
    Failed to compile application.
    
    
    
    
    #66398

    codingapple
    키 마스터
    위젯만들때 build같은게 없거나 이상한데있나봅니다
    #66417

    익명
    비활성
    여기서 build를 추가하려면 어떻게 해야할까요??
    
    
    import 'package:flutter/material.dart';
    import 'style.dart';
    import 'package:http/http.dart' as http;
    import 'dart:convert';
    void main() {
      runApp(
          MaterialApp(
              theme: theme,
              home : MyApp()
          )
      );
    }
    class MyApp extends StatefulWidget {
      MyApp({Key? key}) : super(key: key);
      @override
      State<MyApp> createState() => _MyAppState();
    }
    class _MyAppState extends State<MyApp> {
      var tab = 0;
      var data = [];
      getData() async {
        var result = await http.get(
            Uri.parse('https://codingapple1.github.io/app/data.json'));
        var result2 = jsonDecode(result.body);
        setState(() {
          data = result2;
        });
        @override
        void initState() {
          super.initState();
          getData();
        }
        @override
        Widget build(BuildContext context) {
          return Scaffold(
            appBar: AppBar( title: Text('Instagram'),
              actions: [IconButton(
                icon : Icon(Icons.add_box_outlined),
                onPressed: (){},
                iconSize: 30,
              )],
            ),
            body: [Home(data : data), Text('hi')]

    , bottomNavigationBar: BottomNavigationBar( showSelectedLabels: true, showUnselectedLabels: true, onTap: (i){ setState(() { tab = i; }); }, items: [ BottomNavigationBarItem(icon: Icon(Icons.home_outlined), label: '홈'), BottomNavigationBarItem(icon: Icon(Icons.shopping_bag_outlined), label: '샵'), ], ) ,
          );
        }
      }
    }
    class Home extends StatelessWidget {
      const Home({Key? key, this.data}) : super(key: key);
      final data;
      @override
      Widget build(BuildContext context) {
        if (data.isNotEmpty) {
          return ListView.builder(itemCount: 10, itemBuilder: (c, i) {
            return Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Image.network('https://codingapple1.github.io/kona.jpg'),
                  Text('좋아요 100'),
                  Text('글쓴이'),
                  Text(data[i]['content']),
                ]
            );
          });
        } else {
          return Text('Loading');
        }
      }
    }
    
    #66461

    codingapple
    키 마스터
    getData() async {
    닫는 중괄호가 없는듯요
    #66498

    익명
    비활성
    중괄호 추가를 시도해보았으나 이렇게 계속 뜨네요, 볼드 처리 된 부분에서 해결하면 될 것 같은데 어떻게 해야할지 모르겠어요..
    Launching lib/main.dart on Chrome in debug mode...
    Waiting for connection from debug service on Chrome...
    ../Downloads/flutter/packages/flutter/lib/src/widgets/framework.dart:5079:27: Error: The method 'build' isn't defined for the class 'State<StatefulWidget>'.
     - 'State' is from 'package:flutter/src/widgets/framework.dart' ('../Downloads/flutter/packages/flutter/lib/src/widgets/framework.dart').
     - 'StatefulWidget' is from 'package:flutter/src/widgets/framework.dart' ('../Downloads/flutter/packages/flutter/lib/src/widgets/framework.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'build'.
      Widget build() => state.build(this);
                                           ^^^^^
    Failed to compile application
    .../Downloads/flutter/packages/flutter/lib/src/widgets/framework.dart:5079:27: 
    #66507

    익명
    비활성
    스택오버플로우에 질문하니 이러한 답변을 얻었으나 이해하지 못하겠어요
    
    Its very simple, your build method for MyApp class is inside your getData function, which should be outside of the function.. And thats what the error message says.
    #66510

    codingapple
    키 마스터
    setState(() {
          data = result2;
    });
    부분 밑에 닫는 중괄호 넣읍시다
    #66512

    익명
    비활성
    네, 넣어봤습니다
    
    import 'package:flutter/material.dart';
    import 'style.dart';
    import 'package:http/http.dart' as http;
    import 'dart:convert';
    void main() {
      runApp(
          MaterialApp(
              theme: theme,
              home : MyApp()
          )
      );
    }
    class MyApp extends StatefulWidget {
      MyApp({Key? key}) : super(key: key);
      @override
      State<MyApp> createState() => _MyAppState();
    }
    class _MyAppState extends State<MyApp> {
      var tab = 0;
      var data = [];
      getData() async {
        var result = await http.get(
            Uri.parse('https://codingapple1.github.io/app/data.json'));
        var result2 = jsonDecode(result.body);
        setState(() {
          data = result2;
        });}
      @override
      void initState() {
        super.initState();
        getData();
      }
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar( title: Text('Instagram'),
            actions: [IconButton(
              icon : Icon(Icons.add_box_outlined),
              onPressed: (){},
              iconSize: 30,
            )],
          ),
          body: [Home(data : data), Text('hi')]

    , bottomNavigationBar: BottomNavigationBar( showSelectedLabels: true, showUnselectedLabels: true, onTap: (i){ setState(() { tab = i; }); }, items: [ BottomNavigationBarItem(icon: Icon(Icons.home_outlined), label: '홈'), BottomNavigationBarItem(icon: Icon(Icons.shopping_bag_outlined), label: '샵'), ], ) ,
        );
      }
    }
    
    
    class Home extends StatelessWidget {
      const Home({Key? key, this.data}) : super(key: key);
      final data;
      @override
      Widget build(BuildContext context) {
        if (data.isNotEmpty) {
          return ListView.builder(itemCount: 10, itemBuilder: (c, i) {
            return Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Image.network('https://codingapple1.github.io/kona.jpg'),
                  Text('좋아요 100'),
                  Text('글쓴이'),
                  Text(data[i]['content']),
                ]
            );
          });
        } else {
          return Text('Loading');
        }
      }
    }
    여기서 문제가 또 있는걸까요??
    
    
    #66519

    익명
    비활성
    
    코드문제인지 실험해보려고 그냥 Text 명령만 해도 저렇게 build 오류가 나는 것 같아요.
    
    #66526

    익명
    비활성
    Console 안에 해답이 있었네요.. flutter 새로 다운로드 한 파일 복제해서 옮겨넣으니 해결되었습니다. 제가 파일 일부를 건들었나봐요.
10 글 보임 - 1 에서 10 까지 (총 10 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠