Flutter icons do not show - 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:
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:
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.

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

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.

Hot reloading does not show changes in resources. Press the stop button square red color in the top action menu bar of android studio and run the app again.
It works.

Please try:
Stopping the app
Running flutter clean in your app directory
Deleting the app from your simulator / emulator / device
Rebuild & Deploy the app.

If you are using the FlutterIcons library, make sure that your font-family in your pubspec.yaml matches the one declared in the my_flutter_app_icons.dart file.

I assume we're talking about the flutter_icons package?
I had to kill the app entirely and reinstall it and they started working for me. Not sure why a hot reload didn't do the trick.

Just delete the App from emulator/physical device on which you are working and again build the app.
It works for me and will surely works for you.

Add the following to your pubspec.yaml:
flutter:
uses-material-design: true
Took me a while to figure out based on the answers above that uses-material-design is a property of flutter, not of the root.

Icon changing to Chinese character was resolved by adding the correct path to the fonts folder. Specify, the correct path to your fonts folder by providing proper indentations:
Flutter Clean
Remove Build From your testing device/Emulator
Run the app

You need to set uses-material-design: true in pubspec.yaml for the icons to be included in the app.
Be sure to have a uses-material-design: true entry in the flutter section of your pubspec. yaml file. It allows you to use the predefined set of Material icons. Many Material Design widgets need to be inside of a MaterialApp to display properly, in order to inherit theme data.

this was issue for me
Make sure in pubspec.yaml file all the images and fonts have correct path and if you have added new image recently try to remove that and then rebuild

The icons were loading normally on all devices except android for me. To fix it I simply:
Before
Icon(
Icons.chevron_left,
size: 40.0,
color: Colors.white,
),
After
Icon(
MdiIcons.chevronLeft,
size: 40.0,
color: Colors.white,
),
Steps
Add to pubspec yahml
dependencies:
material_design_icons_flutter: ^4.0.5955
Add this to the file you want the icon
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
Instead of Icons.NameHere use MdiIcon.NameHere

if all the above not worked then run
flutter pub run flutter_launcher_icons:main

The problem started in my project when I included my app within GetMaterialApp instead of MaterialApp Widget. All Material icons started to look like [X].

Related

Flutter desktop windows notification badge on app icon

I can't seem to find this one. Is it possible to add the number on the app icon? (windows desktop)
For example this is Telegram on windows:
You can use package:windows_taskbar to add badge (overlay icon) to your Flutter Windows app's taskbar icon.
You have to create icons yourself though, maybe "1", "2", "3"... "9" & "9+" like most applications (as .ico files).
It's very easy to use as well.
Add in pubspec.yaml
dependencies:
windows_taskbar: ^1.1.0
Set Icon
WindowsTaskbar.setOverlayIcon(
ThumbnailToolbarAssetIcon('assets/red_slash.ico'),
tooltip: 'Stop',
);
Don't forget to add the icon file to your pubspec.yaml assets.
Remove Icon
WindowsTaskbar.resetOverlayIcon();
NOTE: I'm developer of the package.
These badges are autocreated on notification. There arent much packages for notifications in windows. You can give this a try.
quick_notify: ^0.2.1
QuickNotify.notify(
title: 'My title',
content: 'My content',
);

Flutter - Some icons are not found

I'm trying to use Icon(Icons.factory) but it not displayed: in VSCode and even in my app.
Do you know why? (I saw I need to add font_awesome_flutter or material_design_icons_flutter but is it mandatory?)
I'm using cupertino_icons: ^1.0.4 & uses-material-design: true in my pubspec.yaml
I haven't seen any icon with name factory in the cupertino documentation but if you want to add any icon which is not yet present in your ide's options, simply visit flutters cupetino docs and click on the icon you want. For example the paperlane icon which is not yet available in the options
static const IconData paperplane = IconData(0xf733, fontFamily: iconFont, fontPackage: iconFontPackage);
change above code to
static const IconData paperplane = IconData(0xf733, fontFamily: CupertinoIcons.iconFont, fontPackage: CupertinoIcons.iconFontPackage);
then you can use the font in your code as
Icon(paperplane)
Remember to update your cupertino package and import the file for some icons to work

How to find flower and animal icons for flutter

I need flower and animal icons for an application. When I looked at Pub.dev, I couldn't find a package containing flower and animal icons. Can you give an idea about what I can do?
I looked at these packages but there are no flower and animal icons.
font_awesome_flutter: ^9.2.0
unicons: ^2.0.2
Material icons have some flower icons, but if you need something really specific you should use a SvgPicture, and download any SVG file.
Here is an example
SvgPicture.asset(
"assets/img/your-icon.svg",
height: 32,
width: 32,
color: Colors.black54,
),
To use this way you have to declare the assets folder in the pubspec.yaml and run a flutter pub get after that, an exampleenter code here:
flutter:
assets:
- assets/img/
Try using Flutter_Icons.
Add this in your Flutter page:
import 'package:flutter_icons/flutter_icons.dart';
IconButton(
icon: const Icon(FontAwesome5.cat), //Example
onPressed: () {},
)
And remember to add the package to your dependencies in your pubspec.yaml:
dependencies:
flutter_icons: ^1.1.0

Flutter Material Icons changed after upgrading SDK to 2.2.1 (latest stable)

I just upgraded my SDK and some Material Icons changed to this ugly ones, any advice?
Usually this happens when your pubspec.yaml file, under dev-dependencies has uses-material-designset to false and its not including the material icons in your app.
Change it to true, and restart the app. It should work after that.
I found the issue, the material icon codes where replaced in this SDK and I was using IconData instead of referencing by their name. So I updated the code to be like:
Icon(Icons.arrow_back_ios_new_rounded, size: 20)
See https://github.com/flutter/flutter/issues/84427

Flutter hot reloading is not working to display changes

I have two files, main.dart and sections.dart.
I have defined a few widgets in section.dart and used them in main.dart file, when I run flutter run command changes are displayed on screen, but when I press R to hot reload, nothing changes on screen.
main.dart:
import 'package:flutter/material.dart';
import 'sections.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Share IDEASS',
home: Scaffold(
appBar: AppBar(
title: Text('IDEASs'),
),
body: ListView(
children: [
labelsSection,
],
),
),
);
}
}
Sections.dart:
import 'package:flutter/material.dart';
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
title: 'Share IDEAS',
);
}
}
Column labelSectionMethod(color,IconData icon, String label,String numbers){
return Column(
children: <Widget>[
Icon(icon, color:color),
Container(
child: Text(label,
style: TextStyle(color: color
),
),
),
Container(
child:Text(numbers,
style:TextStyle(color:color
),
),
),
],
);
}
Widget labelsSection=Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
labelSectionMethod(Colors.red,Icons.supervised_user_circle,"IDEASS","35"),
labelSectionMethod(Colors.red,Icons.favorite,"LIKE","22"),
labelSectionMethod(Colors.red,Icons.data_usage,"STREAK","12"),
],
),
);
Maybe because I am repeating:
return MaterialApp(
title: 'Share IDEAS',
);
in sections.dart, or something to do with main function.
UPDATE:
i moved content of sections.dart file in main.dart file still hot reload is not working.
After moving a file to another directory, Android Studio changed my imports to absolute paths.
import 'file:///C:/Users/svenv/AndroidStudioProjects/sample_screen_collection/lib/welcome/reading_list_card.dart';
i had to change it to this
import 'package:samplescreencollection/components/reading_list_card.dart';
This usually happens when you have change a lot of code, added states, changed a widget from stateless to state full, etc. Preforming a hot restart (ctrl +F5) will fix this issue.
If this seems to not work still, try removing the app from your phone/simulator/emulator (closing the app, and deleting it) and running debug/flutter run again. This should fix your issue
There have been issue reported to Flutter regarding this,https://github.com/flutter/flutter/issues/17155#issue-319238844
Basically it's like Flutter is not properly identifying the changes in order to generate updated build files (my personal understanding):
Solution
Simple solution is Clean the project and rebuild it.
I'm using Android studio Android Studio 3.6, Following steps illustrate how to clean the flutter project
Navigate to Tools in navigationbar
Select Flutter > Flutter Clean
Finally Run the Project again by clicking the green playicon
Sometimes flutter gets confused with large amounts of changes, and you need to perform a restart, especially when interacting with the entire App or main function.
You can pressCtrl+C to kill the flutter run process, and try launching it again. Additionally, if you run Flutter through IntelliJ or Android Studio, the flutter plugin includes a "Hot Restart" feature which accomplishes the same thing.
My situation was - Flutter would neither hot reload nor stop on a break-point nor even provide fresh builds to Android emulator, whereas iOS was fine.
I tried suggestions from above but nothing really worked, spent a day on these things.I upgraded from Android Studio 3.x to 4.1 and nothing changed.
What worked for me was:
Create a totally new Flutter sample project.
Validate it works - new versions are deployed, debugging and hot reloads work
Transfer my project into this new project. This pretty much involved replace of the lib and .git folders and manual updates of pubspec.yaml, AndroidManifest.xml and Info.plist (manual file updates took most of the effort, but still much less time than my several day attempts to make things work again)
Verify everything works.