akash
akash

Reputation: 11

How to ask location permission flutter

I want only the prompt that asks permission for location to be displayed on the screen when the app is opened(only for demo purpose). I don't want to use any packages for geocoding.

please give the flutter code for this

Upvotes: 1

Views: 457

Answers (1)

Kaushik Chandru
Kaushik Chandru

Reputation: 17734

If its only for a demo use an alert dialog

Future<void> _showMyDialog() async {
  return showDialog<void>(
    context: context,
    barrierDismissible: false, // user must tap button!
    builder: (BuildContext context) {
      return AlertDialog(
        title: const Text('AlertDialog Title'),
        content: SingleChildScrollView(
          child: ListBody(
            children: const <Widget>[
              Text('This is a demo alert dialog.'),
              Text('Would you like to approve of this message?'),
            ],
          ),
        ),
        actions: <Widget>[
          TextButton(
            child: const Text('Approve'),
            onPressed: () {
              Navigator.of(context).pop();
            },
          ),
        ],
      );
    },
  );
}

More about alert dialog https://api.flutter.dev/flutter/material/AlertDialog-class.html

Please notethat thispop up will not enable location permission. Its only for a demo

Upvotes: 1

Related Questions