countries_world_map icon indicating copy to clipboard operation
countries_world_map copied to clipboard

Printing the country name doesn't work on click

Open dipanshparmar opened this issue 3 years ago • 4 comments

When printing the country name on the click, it just prints an empty string.

Code used:

import 'package:countries_world_map/countries_world_map.dart';
import 'package:countries_world_map/data/maps/world_map.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: HomePage(),
      debugShowCheckedModeBanner: false,
    );
  }
}

class HomePage extends StatelessWidget {
  const HomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Padding(
          padding: const EdgeInsets.all(20.0),
          child: SingleChildScrollView(
            scrollDirection: Axis.horizontal,
            child: SizedBox(
              height: MediaQuery.of(context).size.height,
              child: InteractiveViewer(
                child: SimpleMap(
                  fit: BoxFit.fitHeight,
                  instructions: SMapWorld.instructions,
                  callback: (id, name, tapDetails) {
                    print(name);
                  },
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}

Output image

dipanshparmar avatar Feb 07 '23 14:02 dipanshparmar

Hi @dipanshparmar Yes this was done intentionally as the name of the country varies per language.

To get the name of the country you might want to use this API: https://restcountries.com/v3.1/alpha/ + ID to get

BUT, if you think using the English name as a default is better, then we might implement this. Let me know your thoughts

LauDijksterhuis avatar Feb 07 '23 14:02 LauDijksterhuis

Using the English names by default is a better idea for simplicity's sake and to get the work done. e.g. If I'm working on a country guessing app on the map, forcing the users to connect to the internet only to display the name of the country they selected seems inconvenient to me. Also, you should remove the name parameter if it is not supposed to do anything.

What do you think?

dipanshparmar avatar Feb 07 '23 14:02 dipanshparmar

At this moment the name parameter is used for all other maps (like Japan, Argentina). It does make sense to add the name of countries as well. I will add it in the next release :)

LauDijksterhuis avatar Feb 07 '23 15:02 LauDijksterhuis

Thank you. Looking forward to it :)

dipanshparmar avatar Feb 07 '23 16:02 dipanshparmar