Error code
E/flutter (25456): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null. E/flutter (25456): Receiver: null E/flutter (25456): Tried calling: E/flutter (25456): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5) E/flutter (25456): #1
_WeatherState.fetchLocationUpDate. (package:tast_project/screenes/screenweather.dart:31:27) E/flutter (25456): #2 State.setState (package:flutter/src/widgets/framework.dart:1148:30) E/flutter (25456): #3 _WeatherState.fetchLocationUpDate (package:tast_project/screenes/screenweather.dart:30:5) E/flutter (25456): E/flutter (25456): #4
_WeatherState.initState (package:tast_project/screenes/screenweather.dart:42:5) E/flutter (25456): #5 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4355:58) E/flutter (25456): #6 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5) E/flutter (25456): #7 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter (25456): #8 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter (25456): #9 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter (25456): #10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter (25456): #11 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter (25456): #12 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter (25456): #13 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter (25456): #14 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter (25456): #15 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5) E/flutter (25456): #16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter (25456): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter (25456): #18 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter (25456): #19 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter (25456): #20 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter (25456): #21 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter (25456): #22 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter (25456): #23 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter (25456): #24 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter (25456): #25 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter (25456): #26 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter (25456): #27 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11) E/flutter (25456): #28 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5) E/flutter (25456): #29 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter (25456): #30 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter (25456): #31 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter (25456): #32 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter (25456): #33 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter (25456): #34 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5445:14) E/flutter (25456): #35 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter (25456): #36 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter (25456): #37 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4243:16) E/flutter (25456): #38 Element.rebuild (package:flutter/src/widgets/framework.dart:3947:5) E/flutter (25456): #39 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4206:5) E/flutter (25456): #40 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4381:11) E/flutter (25456): #41 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4201:5) E/flutter (25456): #42 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3194:14) E/flutter (25456): #43 Element.updateChild (package:flutter/src/widgets/framework.dart:2988:12) E/flutter (25456): #44 ComponentElement.performRebuild (package:flutter/src/widgets/framework.da
Flutter code weather
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert';
class Weather extends StatefulWidget {
@override
_WeatherState createState() => _WeatherState();
}
const ipkay = '14f4090b86e2548527113ccac56a5ae4';
class _WeatherState extends State<Weather> {
var temp = 0;
String city='';
//var id = 4099194;
String location ;
var textEditingController = TextEditingController();
fetchSearch(String input) async {
http.Response response = await http.get(
"http://api.openweathermap.org/data/2.5/weather?units=metric&appid=14f4090b86e2548527113ccac56a5ae4&q=" + input);
var result = json.decode(response.body);
setState(() {
location =result['name'];
});}
fetchLocationUpDate()async{
http.Response response = await http.get(
'http://api.openweathermap.org/data/2.5/weather?units=metric&appid=14f4090b86e2548527113ccac56a5ae4&q=$location');
var result = json.decode(response.body);
setState(() {
temp =result['main']['temp'];
city =result['name'];
});}
glo(String city){
fetchSearch(city);
fetchLocationUpDate();}
@override
void initState() {
super.initState();
fetchLocationUpDate();}
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
backgroundColor: Colors.transparent,
body: SafeArea(
child: Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage(
'assetes/img/night.jpg',
),
fit: BoxFit.fill)),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'${temp.toString()} C°',
style: TextStyle(color: Colors.white, fontSize: 30),
),
Text(
'$city',
style: TextStyle(color: Colors.white, fontSize: 30),
),
Card(
child: TextField(
onSubmitted: (String city) {
glo(city);
},
controller: textEditingController,
decoration: InputDecoration(
hintText: 'please entre city',
prefixIcon: Icon(Icons.search),
),
),
),
)
],
),
),
),
);
}