concatenate a link in a Map

Asked

Viewed 166 times

0

I receive data from an API of The Movie DB, of which I must take an image link,the movie poster. The problem is that the data of this image only generates me half the link.

Code:

class FilmePresentation extends StatelessWidget {
  final Map _FilmeData;
  FilmePresentation(this._FilmeData);
  @override
  Widget build(BuildContext context) {
    var link = ["http://image.tmdb.org/t/p/w185/"];
    return Scaffold(
      appBar: AppBar(
        title: Text(_FilmeData["title"]),
        backgroundColor: Colors.pink,
      ),
      backgroundColor: Colors.white,
      body: Center(
        child: Image.network(_FilmeData["poster_path"]),
    ),
    );
  }
}

note that I tried to create a "link" variable that has the first part of the link and the vector ["poster_path"] contains the second part. However, I have tried the following means and I cannot concatenate:

_FilmeData+link+["poster_path"] //ou
_FilmeData[link]["poster_path"] //ou
_FilmeData+"http://image.tmdb.org/t/p/w185/"+["poster_path"]

there is some way to put this link in the ["poster_path"]?

1 answer

1


Well, some questions to be cleared up first.

You have a variable of the type Map _FilmeData (it is not ideal to name variables starting with uppercase letter) and a variable of type List link. All three examples you’ve shown of attempts, I believe they won’t even compile, because you’re mixing things up.

The link variable could simply be a String, No? Instead of being a list to store a value. This way you could simply use string interpolation to concatenate the values of the urls.

final _filmeData = {'poster_path': 'segundaParteURL'};
final linkString = 'http://primeiraParte/';
print('Interpolação de String: $linkString${_filmeData['poster_path']}');

If for some other reason you really need to use a list to save a value, you need to enter the index value to access it and get the url, getting:

final _filmeData = {'poster_path': 'segundaParteURL'};
final linkList = ['http://primeiraParte/']; //Porque usar list??
print('Interpolação de String com List: ${linkList[0]}${_filmeData['poster_path']}');

Now, if you need to also update the value of the url in Map, you would have to update it by doing:

final _filmeData = {'poster_path': 'segundaParteURL'};
_filmeData['poster_path'] = linkList[0] + _filmeData['poster_path'];
print('Substituindo no Map: ${_filmeData['poster_path']}');

Test these examples on Dartpad.

the/

  • My friend you’re to be congratulated

  • @Lucaspires if useful, mark the answer as accepted :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.