Hey guys if I make a print in the function lat() it's not getting printed on the console is there any way to prevent such behavior in the function cause I am not able to debug the application I am new to Dart/Flutter please help me guys I am actually trying to get the lat and long so that I can send it to an API and get the weather data
This is my code
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:http/http.dart' as http;
import 'package:geolocator/geolocator.dart';
import 'dart:convert';
class Home extends StatefulWidget {
@override
_Home createState() => _Home();
}
class _Home extends State<Home> {
int weather = 4;
dynamic _text;
dynamic permisson;
void lat() async {
var pos = await getCurrentPosition(desiredAccuracy: LocationAccuracy.high).then((position) {
dynamic loc = position.toJson;
setState(() { _text = position.toJson(); });
});
}
@override
void initState() {
super.initState();
lat();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Home"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Image(
height: 250
),
Center(
child: ListTile(
title: Text(weather.toString()),
subtitle: Text('Music by Julie Gable. Lyrics by Sidney Stein.'),
),
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
TextButton(
child: const Text('BUY TICKETS'),
onPressed: () {
setState(() { weather = 4; });
},
),
const SizedBox(width: 8),
TextButton(
child: const Text('LISTEN'),
onPressed: () {
print(_text['longitude']);
},
),
const SizedBox(width: 8),
],
),
],
),
),
],
),
),
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
backgroundColor: Color(0xFF6200EE),
selectedItemColor: Colors.white,
unselectedItemColor: Colors.white.withOpacity(.60),
selectedFontSize: 14,
unselectedFontSize: 14,
onTap: (value) {
print(value);
if(value == 0) {
print("home");
Navigator.pushNamed(context, '/home');
} else if (value == 1) {
print("Settings");
} else if (value == 2) {
print("Profile");
} else if (value == 3) {
print("About");
}
},
items: [
BottomNavigationBarItem(
title: Text('Home'),
icon: Icon(Icons.home),
),
BottomNavigationBarItem(
title: Text('Setting'),
icon: Icon(Icons.settings),
),
BottomNavigationBarItem(
title: Text('Profile'),
icon: Icon(Icons.account_circle),
),
BottomNavigationBarItem(
title: Text('About'),
icon: Icon(Icons.info),
),
],
),
);
}
}