simplewidgets / countries_world_map

This Flutter package draws a customizable World Map on a canvas. It is possible to give each country its own color.
MIT License
31 stars 19 forks source link

Printing the country name doesn't work on click #12

Open dipanshparmar opened 1 year ago

dipanshparmar commented 1 year ago

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

LauDijksterhuis commented 1 year ago

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

dipanshparmar commented 1 year ago

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?

LauDijksterhuis commented 1 year ago

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 :)

dipanshparmar commented 1 year ago

Thank you. Looking forward to it :)