Implementing Flutter Icons in the `buildMenuItem()` Widget - flutter

In the Container widget, I have tried implementing many flutter icons and all are working well except for the cell_tower_rounded. This is an icon that is as well supported by icons Null safety.Kindly help why is this cell_tower icon not working while the rest are just ok.
My editor underlines it in red and the error is undefined_getter
Container(padding,child,childred[
buildMenuItem(
text: 'Connection Status',
icon: Icons.cell_tower_rounded,
onClicked: () => selectedItem(context, 0),
]),

I think you have some typo on your code. The correct should be
Container(padding,child:Row(children[
buildMenuItem(
text: 'Connection Status',
icon: Icon(Icons.cell_tower_rounded),
onClicked: () => selectedItem(context, 0),
])),
You can use either Row or Column. It depends on what you want.

Thank you for your contributions, But well, I figured it out and found a fix. The problem was that my Flutter Version was out of date. Most of the latest icons are not easily supported in previous flutter versions.
I was using Flutter: 2.8.2 while at the time of release of cell_tower_rounded icon, flutter version was at Flutter: 2.10.2.
Incase you are experiencing a unique problem with some widgets, packages or icons, simple run: $ flutter upgrade in your project directory.
You'll probably also need to update your Kotlin Version in the android/build.gradle to the latest one.Find the latest Kotlin version here:
Today(as at the time of this post), the latest one is version 1.6.0, so kindly update like this:
buildscript {
ext.kotlin_version = '1.6.0'

Related

Which Flutter version is safe for Production Release?

I'm currently on version 3.3.9 channel stable and experiencing some weird assertion error from 'text_painter.dart:975:12' - which is the following function:
/// Returns the position within the text for the given pixel offset.
TextPosition getPositionForOffset(Offset offset) {
assert(!_debugNeedsLayout);
return _paragraph!.getPositionForOffset(offset);
}
I'm working on web and it seems to happen when I move my cursor over the screen before the page has fully loaded - before my custom fonts show up.
Has anyone else experienced something similar? What's my safest option for a production release?
** UPDATE
Now using latest version 3.3.10 channel stable and still facing the same issue. Additionally, found this comment the source code:
// The TextPainter class should not aggressively invalidate the layout as long
// as `markNeedsLayout` is not called (i.e., the layout cache is still valid).
// See: https://github.com/flutter/flutter/issues/85108
This must be a source code error from flutter. You should try downgrading to version 3.2.0. I find It more state in production rollouts.
Try updating Flutter Source packages:
To update to the latest compatible versions of all the dependencies listed in the pubspec.yaml file, use the upgrade command:
flutter pub upgrade
If still issue persists,
Try updating all packages:
flutter pub upgrade --major-versions

flutter: No named parameter with the name 'clipBehavior', clipBehavior: Clip.none

I am trying to add a notifications counter badge with using badges package with flutter but the project does not compile as soon as I add the below code. I'm using flutter v1.17.4.
Badge(
badgeColor: Colors.deepOrangeAccent,
toAnimate: true,
child: IconButton(
icon: Icon(Icons.shopping_cart),
onPressed: (){
Navigator.push(context, MaterialPageRoute(builder: (context)=> ShoppingCart()));
}
)
),
When start debugging, flutter: No named parameter with the name 'clipBehavior', clipBehavior: Clip.none displays. Is there any possible solution without Updating the version of flutter to latest version?
The error is not from the Flutter framework but from the older version of Badge package that you are using. The author of Badge has updated the package on December 8, 2020 with precise the same bug fix.
[1.1.6] - [December 8, 2020]
Fix error parameter with the name 'clipBehavior'
Please upgrade the Badge package to its latest version Badges 1.1.6.

I have a couple of problems when I upgraded packages in my Flutter app

I have a couple of problems when I upgraded packages in my Flutter app.
Compiler message:
/C:/flutter/.pub-cache/hosted/pub.dartlang.org/country_pickers-1.3.0/lib/country_picker_dropdown.dart:151:7: Error: No named parameter with the name 'onTap'.
onTap: widget.onTap,
^^^^^
/C:/flutter/packages/flutter/lib/src/material/dropdown.dart:784:3: Context: Found this candidate, but the arguments don't match.
DropdownButton({
^^^^^^^^^^^^^^
I created a fork from the package country_pickers to solve this issue. They are depending on a newer version of flutter while I'm not planning to upgrade my app flutter version now. I'm using flutter version 1.12.13
If you are directly depending on the package you can use my fork.
country_pickers :
git:
url: git://github.com/shadyshrif/country_pickers_backward_support
ref: 5d16109618f2a9bcc1ff49cfd6d53011f0217d67
If the package country_pickers is used by another package (you didn't add it to dependency by yourself) you can enforce flutter to replace the dependency using
dependency_overrides:
country_pickers :
git:
url: git://github.com/shadyshrif/country_pickers_backward_support
ref: 5d16109618f2a9bcc1ff49cfd6d53011f0217d67

Flutter - How to enable control-flow-collection?

I'm trying use control-flow-collections in Flutter(Google's UI toolkit) to enable the use of inline for loop, i.e:
for (int i = 0; i < globals.currentScaleList.scales.length; i++)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
globals.currentScaleList.scales[i].scaleType.toString(),
style: TextStyle(fontSize: 20.0),
),
],
),
], itemExtent: 23.0, onSelectedItemChanged: (index) {}),
I have seen the other questions on the topics in SO and followed all of the instructions that seem to work for others.
I am running Flutter 1.15.4-pre.248 on the Master channel and Dart 2.8.0
Flutter 1.15.4-pre.248 • channel master • https://github.com/flutter/flutter.git
Framework • revision 686d163420 (2 hours ago) • 2020-03-02 16:25:22 -0500
Engine • revision 5e474ee860
Tools • Dart 2.8.0 (build 2.8.0-dev.10.0 fbe9f6115d)
I have created a analysis_options.yaml file in my root app folder and added the following:
analyzer:
enable-experiment:
- control-flow-collections
I have also updated the min version of Dart in my pubspec.yaml, i.e.:
environment:
sdk: ">=2.5.0 <3.0.0"
However, I still get the error against my 'for' loop stating:
"This requires the 'control-flow-collections' experiment to be enabled.
Try enabling this experiment by adding it to the command line when compiling and running."
When I do enable the 3 lines in my analysis_options.yaml file, I get the warning:
"The option 'control-flow-collection' isn't supported by 'enable-experiment'."
What am I missing? Thanks
For those who are facing this issue and have tried creating the analysis_options.yaml, I did what Paul Toal said on the last comment.
Remove analysis_options.yaml (if created)
Run flutter clean command
Restart VSCode
This one worked for me, using the following.
environment:
sdk: ">=2.5.2 <3.0.0"
I had the same issue with the moor_database.g.dart, the Moor generated file. I got it fixed by:
1- Upgrading the sdk constraints with the following
environment:
sdk: ">=2.8.0 <3.0.0"
2- On DartAnalysis in the Android Studio, click on Restart Dart Analysis Server, the first icon button on top left of the DartAnalysis window.
Weird, but worked.

The Google Fonts Package in Flutter app is not working

First, I added the google_fonts package to your pubspec dependencies.
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
google_fonts: ^0.2.0
Then
import 'package:google_fonts/google_fonts.dart';
and apply to a Text widget
Text(
'This is Google Fonts',
style: GoogleFonts.lato(fontSize: 40),
),
Text(
'This is Google Fonts',
style: GoogleFonts.adventPro(fontSize: 40),
),
Please check internet connection- your emulator does not have internet connectivity. google fonts need internet connection on device/emulator.
After adding the dependency pubspec.yaml file
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
google_fonts: ^0.2.0
run the command in terminal\cmd console as :
> flutter packages get
this will fetch the dependency into your workspace.
Google Fonts are fetched from the internet in the runtime. So you observe this behaviour
To overcome this, download the font from google font and make it available in the asset folder by following the steps below.
Visit the https://fonts.google.com/ and download the lato font.
At the root directory, create a directory called google_fonts.
Copy-Paste lato.ttf file into the google_fonts folder.
Open the pubspec.yaml file, Under the assets: section add the -google_fonts/
And change the code from
// Online Mode
Text(
'This is hammersmithOne from Google Font'
style: GoogleFonts.lato(),
),
to
// Offline Mode
Text(
'This is hammersmithOne from Google Font',
style: TextStyle(fontFamily: 'lato') // This is loaded from assets
),
For futher reference refer this article.
Refer these stackoverflow answers aswell:
https://stackoverflow.com/a/74949875/13431819
https://stackoverflow.com/a/74950261/13431819
I fixed mine by deleting the emulator and installing a new one. My older emulator was not connecting to the internet for some reason and reinstalling it fixed it for me.
Unless you store the fonts in your assets, you need to define explicitly that runtime fetching is enabled for Google Fonts:
GoogleFonts.config.allowRuntimeFetching = true;