Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter icons do not show

Tags:

flutter

I am trying to complete this Flutter Code Lab, but the icons do not appear in my application. But they appears in Android Studio code:enter image description here I have been included the lib in my file pubspec.yaml

name: startup_namer
description: A new Flutter application.

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.0
  english_words: ^3.1.0

But result is this:enter image description here

My main.dart file looks like this:

// Add the heart icons to the ListView.

import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';


void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {

   ..... 

  Widget _buildRow(WordPair pair) {
    final bool alreadySaved = _saved.contains(pair);

    return new ListTile(
      title: new Text(
        pair.asPascalCase,
        style: _biggerFont,
      ),
      trailing: new Icon(
        alreadySaved ? Icons.favorite : Icons.favorite_border,
        color: alreadySaved ? Colors.red : null,
        size: 22.0,
      ),
      onTap: () {      
        setState(() {
          if (alreadySaved) {
            _saved.remove(pair);
          } else {
            _saved.add(pair);
          }
        });
      },
    );
  }
}

I thought that is because I use iOS emulator, but when I tried with Android emulator the result was the same.

like image 229
MeLean Avatar asked Jun 10 '18 18:06

MeLean


People also ask

How do I show icons on Flutter?

You can use Icon() widget to add icons to your Flutter App. You have to pass the icon data as an icon to this widget. You can use default available Material icons with Icons class.

How do you make icons invisible in Flutter?

For Invisible: we wrap the widget in an IgnorePointer widget and an Opacity widget with the value zero.


2 Answers

(Copied from the comments)

You need to set uses-material-design: true in pubspec.yaml for the icons to be included in the app.

like image 177
Danny Tuppeny Avatar answered Sep 21 '22 00:09

Danny Tuppeny


In my case, I have written uses-material-design: true in pubspec.yaml file. I am able to solve this problem by restarting the Android emulator. You can also try by uninstalling old build from your emulator and then installing the new one.

This is little weird behavior, but it works for me.

like image 36
Rahul Sharma Avatar answered Sep 18 '22 00:09

Rahul Sharma