fontAwesome icons do not work inside my flutter app - flutter

I'm currently working on a side project and when I have included a font-awesome icon inside my app, it does not show up and instead, a blank box with two lines intersecting with each other like the letter x, how to fix this?
class ImageHoldingComponent extends StatefulWidget {
#override
_ImageHoldingComponentState createState() =>
_ImageHoldingComponentState();
}
class _ImageHoldingComponentState extends State<ImageHoldingComponent> {
#override
Widget build(BuildContext context) {
return Container(
child: Icon(FontAwesomeIcons.python)
);
}
}

The author of font_awesome_flutter package suggests the following steps for anyone who has icons not showing problem:
Stopping the app
Running flutter clean in your app directory
Deleting the app from your simulator / emulator / device
Rebuild & Deploy the app.
Also make sure to set uses-material-design to true in pubspec.yaml file.

This happens when you start using the older version of font_awesome_flutter and because the virtual device cache is stored when you build the Flutter app, so every time you change the icon you have to stop the emulator and rebuild it.
My experience is:
Stop main.dart (Android Emulator)
In pubspec.yaml add (font_awesome_flutter) new version
font_awesome_flutter: ^8.8.1
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
font_awesome_flutter: ^8.8.1 //new verison
And Then click
"Pub get"
at the top of Flutter commands
Run the emulator again (start main.dart)

If your app is running on the emulator or device just
stop it and relaunch it again
it solves your problem

Just save the from pupspec.yaml file under dependices and say pub get, don't forget to import it

Add font_awesome_flutter: ^10.3.0 package in pubspec.yaml file.
Then use like this
FaIcon(
Icons.access_alarm,
color: whatsappColor,
size: 30,
),

Related

How to add a package in the android studio - flutter?

I started fluttering a few days ago. I want to add "font awesome" to my project, but I can't. I searched but could not find the right answer. I finally got this guide, but it doesn't work either.
Adding a package dependency to an app
To add the package, css_colors, to an app:
Depend on it
Open the pubspec.yaml file located inside the app folder, and add css_colors: under dependencies.
Install it
From the terminal: Run flutter pub get.
OR
From Android Studio/IntelliJ: Click Packages get in the action ribbon at the top of pubspec.yaml.
Import it
Add a corresponding import statement in the Dart code.
4. Stop and restart the app, if necessary
If the package brings platform-specific code (Kotlin/Java for Android, Swift/Objective-C for iOS), that code must be built into your app. Hot reload and hot restart only update the Dart code, so a full restart of the app might be required to avoid errors like MissingPluginException when using the package.
In the dependencies: section of your pubspec.yaml, add the following line:
dependencies:
font_awesome_flutter:
Look here https://pub.dev/packages/font_awesome_flutter/install
It contain examples and instructions.
Steps also the same:
add the package name to dependencies section. It very important to keep the correct number of spaces in every line of pubspec.yaml, it has very sensitive format
in your case:
dependencies:
font_awesome_flutter: ^8.10.0
Click "Packeges get" in top right corner
Import the package into your dart code
in your case:
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
Now your can use it in Icon widget
Icon(
FontAwesomeIcons.mars,
size:80.0)

Trying to launch a URL in browser from my flutter app. When I click the button I created to launch the URL nothing happens. Don't know why

I am trying to create an app that allows the user to click a button and have a website open in their browser. I wrote this code with a lot of help from the Flutter docs. Everything compiles and runs fine but when I click the button in the middle of the screen that is supposed to launch the URL nothing happens. The button just does what I think is a splash animation but the URL is not launched in the browser as intended. This doesn't have anything to do with the fact that I am using an emulator to test this does it? Or is a problem with the url_launcher package? I will attach my code and the .yaml file. Would appreciate any response from anyone. Thank you very much!
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text("Your Covid-19 Briefing"),
),
body: Center(
child: RaisedButton(
onPressed: _launchUrl,
child: Text("Covid-19 Cases"),
),
),
),
);
}
_launchUrl() async {
const _urlToLaunch = "https://www.worldometers.info/coronavirus/";
if (await canLaunch(_urlToLaunch)) {
await launch(_urlToLaunch);
} else {
throw "Could not open $_urlToLaunch";
}
}
}
name: coronavirus_news_updates
description: A new Flutter application.
# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
url_launcher: ^5.4.11
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.3
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
Does it throw any error?. I tried running the above code with both emulator and my smartphone and it works fine.

Google Fonts package Not working in flutter

The google_fonts package is not working in the final build apk in FLutter, it works fine in the debug mode, but as soon as I build it and install the final apk, It just shows regular font.
It could be because of internet permission issue, google fonts using internet acces and if don't apply the permission in your project it won't work when you install the app.
for this you need to add follow line to file AndroidManifest.xml which is there;
yourappname/android/app/src/debug/AndroidManifest.xml
and the line you will add:
<uses-permission android:name="android.permission.INTERNET"/>
I don't believe it is an internet problem. Most times fonts using Flutter packages contain an error in the Pubspec file.
Check your Pubspec.yaml file. Make sure your google fonts package is Formatted this way
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
google_fonts: ^1.1.0
flutter:
assets:
- google_fonts/ # you only need this line and nothing in the fonts area per https://pub.dev/packages/google_fonts
Make sure you have added the below line in /android/app/src/main/AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET"/>
hello my friend try to check the version first ;)
enter image description here
To use google_fonts you must initialize the license for it.
To do that follow the steps:
Suppose you using this:
fontFamily: GoogleFonts.shadowsIntoLight().fontFamily,
Therefore, you are using shadowsIntoLight font.
To license it, first download the particular font from Google Fonts.
After you download the zip files, extract it.
Make a folder named google_fonts in the root directory of your flutter app file.
=> Now place the .ttf and OFL.txt files (present in the extracted folder) in google_fonts folder that you made previously.
[Note: Only OFL.txt is enough for all your fonts.]
This is how my one looks:
Now go to main.dart file:
=> Add these lines inside the void main() {runApp(MyApp());}:
void main() {
LicenseRegistry.addLicense(() async* {
final license = await rootBundle.loadString('google_fonts/OFL.txt');
yield LicenseEntryWithLineBreaks(['google_fonts'], license);
});
runApp(...);
}
and import the followings:
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Now close your app and restart it and the release it:
flutter build apk --release
Google fonts uses internet, so you may have to update the dependencies in the manifest.xml file.
<uses-permission android:name="android.permission.INTERNET"/>
Else you can try to make the google font available in the offline by adding it in the assets folder.
And then change the code from
// Online Code
Text(
'This is hammersmithOne from Google Font'
style: GoogleFonts.hammersmithOne(),
),
to
// Offline Code
Text(
'This is hammersmithOne from Google Font',
style: TextStyle(fontFamily: 'hammersmithOne') // This is loaded from assets
),
For futher reference refer this article.

Flutter: Unimplemented handling of missing static target

I am running my first Flutter project
I created a sample project and I was able to run the app in
simulator
I have edited the file main.dart
main.dart
import 'package:flutter/material.dart';
void main() => runApp(MaterialApp(home: Text('Hello World')));
Now I am getting the error :
pubspec.yaml
name: flutter_app
description: A new Flutter application.
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware.
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
The same error occurred for me at first ... but it worked when I did a 'hot restart'
Just compile the project again and it will work. The error occurs because static variables are hard compiled on the executable and are not dynamic. If you hot reload the changes, it will not rebuild the executable (apk), so that's why you need to rebuild the app.
Your code works for me...
Have you tried a hot restart? The shortcut is CTRL+SHIFT+\ or just click the button with the green circle-arrow in the console-window
I'm not sure what that error is, since I can't replicate it. However, this is more like what your app should look like. Give this a shot and see if it works.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
home: Text('Hello World'),
);
}
}
Just delete the build and recompile. It worked for me. Use the following code:
flutter clean
flutter run
Usually, a Full App Restart is required after a heavy logic change, as transforming a StatelessWidget into StatefulWidget. Check André Glatzl answer
In Android Studio use the Flutter Hot Restart
A hot restart will work. But the source of the problem might be as follows.
You've created new project. You've deleted boilerplate code and try to modify without a stateful or stateless widget. Flutter tries to rebuild widgets under build() method. But when you hot reload, flutter might not resolve what you've updated.
Another example of such error is, when we create a new static variable(static String token = "abc";) in one Class (like constants.dart) and try to reference them in another screen (constants.token), flutter failed to resolve such static things when we hotreload. but it work fine when we hotrestart.
One of the reasons this happens is you are running the app for the first time and then you make some changes and reload again. Without reloading, stop the execution, and again run the app from scratch, this error won't come.
I also faced the same situation, I fixed it by running the app again, This issue is caused when you applied a lot of change to your code and pressed the hot reload button.
Restarting the app worked in my case.
Run this command again
'flutter run'
should work
You changed the myApp and created your own MaterialApp so all you have to do is after changing the name into MaterialApp instead of hot restart click the play button. It will work.
Thanks
Just press the red stop button and click the play button again. It will work :)
As other answers mention, you can 'hot reload' or rebuild your app to solve this issue.
But the reason why I got this error, was that I have edited the pubspec.yaml file, when editing the pubspec.yaml file, you should stop and rebuild the entire app.
Navigate to your lib folder where your main.dart file is and run the commands below:
PS C:\Users\mobile_app\lib> flutter clean
PS C:\Users\mobile_app\lib> flutter pub get
PS C:\Users\mobile_app\lib> flutter run
although if you are having null safety issues I would prefer you debug your application first. In my encounters this error is of a result of trying to run a class component outside a the Static Widget with context hence the class is loaded before build time making the application fail to start.
I occurred when I was implementing TextEditingController and there after I created a function which has parameter inside, so when I wrote the addListener for the controller, then below error got occurred,
Unimplemented handling of missing static target flutter
but after removing the argument from the addListener function still the issue persists and which broked my application, even I did the hot reload in my Android Studio.
Solution:
Mostly similar to above said, but little different, I terminated my app, and rerun the app, and which fixed the issue.
Hope this would help manyone.
If you have added Hot Reloading extension then exit and try restarting the HOt Reloading.
It should work.
Check your import.
It should be
import 'package:your_app...' not import 'file://C/path/your_app/

Target of URI doesn't exist 'package:english_words/english_words.dart'

I'm learning to use Flutter using Android Studio. I'm going through step by step doc provided by Flutter. At Step:2 Use an external package I'm getting issue importing the english_words package. I have properly added the package in pubspec.yaml and clicked Packages Get which added the dependency but at the time of importing the package in lib/main.dart it is saying
Target of URI doesn't exist
'package:english_words/english_words.dart'.
I have seen many questions on StackOverflow but none of them helped me. Please help!
For some packages, once you do all the process described by the other answers to this question, you have to close the Android project and open it again. As well as the emulator.
Some packages need the restart, others do not need it.
After adding the package in the pubspec.yaml file, you need to execute the command flutter packages get or click on "Packages Get" in the action ribbon at the top of pubspec.yaml file.
Then the dependency and any transitive dependency will be added to the .packages file.
Check this:
https://flutter.io/using-packages/
Solution (For VSCode):
Run flutter packages get in pubspec.yml
Restart VSCode
I had the same issue and went about it like listed below and it worked.
1. Add the package
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
**english_words: ^3.1.5**
Save the pubspec.yaml file
go to your terminal and run 'flutter packages get'
4.Close your simulator and rebuild your cradle
Run the main.dart again and it should remove the error.
This is what worked for me, all the best.
Make sure that english_words is on the base-line with flutter:
Took me a lot of time, but in summary, just save the file pubspec.yaml will do. The command flutter pub get will be ran once u save it, then u can import the package.
There is no need to restart ur editor etc.
My solution was to add the "english_words: ^3.1.5" the version at the moment that I write this, under the "dependencies:" and before the "Flutter:" argument, without the "+" sign.
Hope that helps
I used this and it worked for me... without + sign and version in double quote ""..
english_words: "^3.1.5"
Make Sure that the alignment of english_words is correct inside your pubspec.yaml as it's "space sensitive" :
dependencies:
english_words: ^3.1.5 //two spaces
also never align it using tabs, I don't know why but it never works, and don't use + sign
There are so many methods to solve this issue, most of them will get solved on the second step,if not please try third method also it will work.
Run flutter packages get in pubsec.yaml file (if you are using VS Code it will be easier).
Restart your IDE.
Check it now, mostly it will work. If not try third step.
you have to repair pub caches
flutter packages pub cache repair
I hope it will work. if all methods are not working try to re install flutter.
my friend solution is so simple only add this code line in file pubspec.yaml
english_words: ^3.1.0
like this
dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
english_words: ^3.1.0
dev_dependencies:
flutter_test:
sdk: flutter
it would work perfectly:)
I faced the same issue but I managed to solve it using the steps below:
add the package as an example english_words: ^3.1.0" in 'pubspec.yaml file.
save file or press ctrl+s
//the Output Console will appear this message
[app name] flutter packages get.
Running "flutter pub get" in first_app..., 2.4s
exit code 0.).
3. check main.dart file, the error will be removed.
For me nothing worked. Things resolved only after
Flutter upgrade
in pubsec.yaml file
For those who are still experiencing this problem, it took me hours to figure out what was wrong. Basically, if all the other answers don't work:
Open the test/.packages file on whatever IDE you are using
Locate the package that is not working and go to that directory on your computer.
Delete the whole package. In my case it was the whole english_words package folder.
In the pubspec.lock and .packages file, delete all instances of that package.
run pub get
In the docs of https://flutter.dev/docs/get-started/codelab there is the following code:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.3
+ english_words: ^3.1.5
The thing which is causing the error is "+ sign". I just removed it and all worked fine for me.
Delete the plus sign "+" in front of english_words (if you have one)
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
english_words: ^3.1.5
I got the same issue.
It is observed only in version 4.0.0 .For lower versions there is no problem.
So here is what you can do to solve this:
Download code for the dependency from :
https://github.com/filiph/english_words
Unzip it Rename it to
english_words-4.0.0
Copy this folder.
Now go to flutter's SDK folder and navigate to
.pub-cache\hosted\pub.dartlang.org
and paste the folder english_words-4.0.0 here. Add dependency in pubspec.yaml file. Now run flutter pub get command.
You are good to go.
Note : How to find the path of Flutter SDK
All you need to do is to restart IDE(Android studio or VSCode)
Having this error message:
Error: Cannot run with sound null safety, because the following
dependencies don't support null safety:
package:english_words
I had to change this dependency english_words: ^3.1.5 to the latest version english_words: ^4.0.0 and make "pub get":
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.2
english_words: ^4.0.0
provider: ^6.0.0
in your pubspec.yaml file, instead of:
english_words: ^4.0.0
try:
english_words: '4.0.0'
it worked for me