에러가 안나는데 프로그레스바만 도네용..
313
작성한 질문수 5
import 'package:flutter/material.dart';
import 'package:flutter_dust/models/AirResult.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
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(
primarySwatch: Colors.blue,
),
home: Main(),
);
}
}
class Main extends StatefulWidget {
@override
_MainState createState() => _MainState();
}
class _MainState extends State<Main> {
AirResult _result;
Future<AirResult> fetchData() async {
var response = await http.get('https://api.airvisual.com/v2/nearest_city?key=a6bcd383-8475-4d34-9da1-e79ba8f1c4f5');
AirResult result = AirResult.fromJson(json.decode(response.body));
return result;
}
@override
void initState() {
super.initState();
fetchData().then((airResult) {
setState(() {
_result = airResult;
});
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body :Center(
child : _result == null ? CircularProgressIndicator() : Padding(
padding: EdgeInsets.all(8.0),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('현재 위치 미세먼지', style: TextStyle(fontSize: 30)),
SizedBox(
height: 16,
),
Card(
child: Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(8.0),
child: Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Text('얼굴 사진'),
Text('${_result.data.current.pollution}', style: TextStyle(fontSize: 40)),
Text(getString(_result), style: TextStyle(fontSize: 20))
],
),
color: getColor(_result),
padding: EdgeInsets.all(8.0),
),
),
Container(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Row(
children: <Widget>[
Image.network('https//airvisual.com/images/${_result.data.current.weather.ic}.png'
,width : 32,
height : 32),
SizedBox(width: 16),
Text('${_result.data.current.weather.tp}', style: TextStyle(fontSize: 16))
],
),
Text('${_result.data.current.weather.hu}'),
Text('${_result.data.current.weather.ws}')
],
))
],
),
),
SizedBox(
height: 16,
),
ClipRRect(
borderRadius: BorderRadius.circular(25),
child: RaisedButton(
padding: EdgeInsets.symmetric(vertical: 15, horizontal: 50),
color: Colors.orange,
child: Icon(Icons.refresh, color: Colors.white),
onPressed: () {},
),
),
],
)))));
}
Color getColor(AirResult result) {
if (result.data.current.pollution.aqius <= 50) {
return Colors.greenAccent;
} else if(result.data.current.pollution.aqius <= 100) {
return Colors.yellow;
} else if(result.data.current.pollution.aqius <= 150) {
return Colors.orange;
} else {
return Colors.red;
}
}
String getString(AirResult result) {
if (result.data.current.pollution.aqius <= 50) {
return '좋음';
} else if(result.data.current.pollution.aqius <= 100) {
return '보통';
} else if(result.data.current.pollution.aqius <= 150) {
return '나쁨';
} else {
return '최악';
}
}
}
1. 혹시 문제가 무엇일까요??
2. 그리고 인스타 입문 배우고 3번 정도
만들어 보면서 복습하였는데요,
UI부분은 이제 잘 이해가 가고
익숙해졌는데, 서버 연동 쪽은
여러 번 반복해도 잘 이해가 안되고
코드 복붙하는 느낌이 강했습니다.
이 코드를 사용함으로써 어떤 데이터가
전달 되고, 어떻게 데이터가 흐르는지
잘 이해가 안갔는데요.
혹시 인스타 2.0에서는 이 부분에 대한
것을 더 자세히 배울 수 있나요?
3.git 코드에 브랜치가 있었음
좋을 것 같아요 ㅠㅠ,,
예를 들어 저는 지금 실제 미세먼지 표시
하기를 듣고 있는데 flutter_airvisual
에는 뒤 과정까지 마무리된 코드가
있어서 전 단계에서 어려움에 쳐했을 때
도움 받기가 조금 힘듭니당 ㅠ.ㅠ
답변 1
0
1. 혹시 AndroidManifest.xml 파일에 INTERNET 권한이 누락 된 것은 아닌지 확인 바랍니다.
2. 인스타 2.0에서도 자~세~하게 설명을 하지는 않습니다. StreamBuilder 를 반복하여 다루면서 반복 학습을 유도하고 있습니다. 서버 연동에 대해서는 별도의 유튜브 영상을 찍어서 공유하도록 해 보겠습니다.
3. 브랜치 의견 감사합니다. 앞으로 강좌를 기획할 때 참고하도록 하겠습니다.
ListenableBuilder가 안되요..material import 했는데도 자동완성이 안뜨고 빨간줄이 뜨네요 ..
0
150
2
pubspec.yaml 파일에서 Pub get이 안됩니다.
0
889
1
[네이티브연동 관련 질문]
0
334
1
네이티브코드 연동할때 네이티브 디버깅은 어떻게 하나요?
0
477
1
CartBloc 대체 코드 올립니다.
0
455
2
강사님처럼 코드가 화면 범위 밖으로 나갔을 때 자동으로 줄바꿈은 어떻게 하나요?
0
969
1
ShowSnackBar Undefined 오류
0
419
1
null 관련 오류
0
318
1
화면새로고침 질문.
0
1491
1
flutter 멀티이미지업로드 질문
0
686
1
fluuter php mysql 글작성
0
435
2
플러터 서버에 이미지 저장하기
0
880
1
오류 질문입니다.
0
258
1
강의를 보다 listview 기능에 의문이 생겨 질문드립니다.
0
748
1
inheritedFromWidgetOfExactType 가 없습니다.
0
231
1
The operator '<' can't be unconditionally invoked because the receiver can be 'null'.
0
1115
1
해결이 어려운 부분이 있습니다 ㅠㅠ
0
1243
2
네이티브코드 연동 AS 21.11.11 update 영상 중
0
213
1
특정 함수로의 객체 전달 방법 문의 드립니다.
0
467
1
플러터 최적의 폴더 구조를 잡고 싶습니다.
0
1029
1
mainActive.kt 오류
0
318
1
xcode 오류가 납니다.
0
360
1
dart 2.12 이상 버전에서 json object null safety 처리는 어떻게 하나요?
0
631
1
json to dart
0
177
1





