print statement is not working in a function

425 views
Skip to first unread message

raghav mri

unread,
Oct 9, 2020, 9:28:06 AM10/9/20
to Flutter Development (flutter-dev)
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),
            ),
          ],
        ),

      );
   }
}

Suzuki Tomohiro

unread,
Oct 9, 2020, 9:32:17 AM10/9/20
to Flutter Development (flutter-dev)
I don’t see lat() having print.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/b13e6184-a074-4f4e-b823-21c275a187b8n%40googlegroups.com.

raghav mri

unread,
Oct 9, 2020, 9:33:53 AM10/9/20
to Flutter Development (flutter-dev)
I haven't added in this but I added onto my code just a moment I will re-write the code

raghav mri

unread,
Oct 9, 2020, 9:34:43 AM10/9/20
to Flutter Development (flutter-dev)

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

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;
    print(loc);

Suzuki Tomohiro

unread,
Oct 9, 2020, 10:50:29 AM10/9/20
to raghav mri, Flutter Development (flutter-dev)
Any chance that
- super.initState threw an exception
- getCurrentPosition threw an exception
- getCurrentPosition did not finish
- position was null, or
- position.toJson threw an exception
?

In general, if you learn how to use breakpoints (in addition to prints), it gets easier to debug things.


Reply all
Reply to author
Forward
0 new messages