10 글 보임 - 1 에서 10 까지 (총 10 중에서)
-
글쓴이글
-
2023년 2월 1일 18:19 #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.
2023년 2월 1일 20:36 #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'); } } }
2023년 2월 2일 14:22 #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 .
2023년 2월 2일 14:44 #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.
2023년 2월 2일 14:59 #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'); } } } 여기서 문제가 또 있는걸까요??
2023년 2월 2일 15:44 #66526
익명비활성Console 안에 해답이 있었네요.. flutter 새로 다운로드 한 파일 복제해서 옮겨넣으니 해결되었습니다. 제가 파일 일부를 건들었나봐요.
-
글쓴이글
10 글 보임 - 1 에서 10 까지 (총 10 중에서)
- 답변은 로그인 후 가능합니다.