I ran flutter upgrade today, and now I am getting an error that says-
[dart] The named parameter 'child' isn't defined.
The project is newly created and the default code is untouched, but it still has the same Error:
Clean the project cache by running
flutter clean cache
Then invalidate caches / restart Android Studio or VS Code.
Try Restarting your Analysis Dart Server.
At the bottom of Android Studio click on the Dart Analysis tab
Click on the Restart icon.
In my case it happens when I name the widget with the same name of a flutter component, like so:
class OutlineButton extends StatelessWidget {
#override
Widget build(BuildContext context) {
return OutlineButton(
child: Text('+R\$ 5'),
onPressed: () {},
borderSide: BorderSide(color: Colors.grey),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
);
}
}
You need to change the name of the created component with a different name, for example:
class CustomOutlineButton extends StatelessWidget {
#override
Widget build(BuildContext context) {
return OutlineButton(
child: Text('+R\$ 5'),
onPressed: () {},
borderSide: BorderSide(color: Colors.grey),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30.0),
),
);
}
}
Go to file Settings
Search Flutter (in the search bar)
Provide Flutter SDK path
Actually, I reinstalled the flutter SDK to solve the problem. After a few days, the same error occurred, but then I Started hovering over the red line, after a minute, the error was solved automatically. I guess the SDK connects with internet to check for all the libraries and syntax stuff once we open the IDE.
It happens because of the old cache. Just clean the cache with the following command
flutter clean cache
I just had the same issue. It looks like I changed a flutter lib file by mistake.
To fix this, without reinstalling Flutter SDK:
go to your Flutter SDK installation path
open terminal and type: git status
it will show the modified files in red (ex: modified: packages/flutter/lib/src/widgets/basic.dart
revert modifications file using: git checkout FILE_PATH (ex: git checkout packages/flutter/lib/src/widgets/basic.dart)
The solution is -
Change the name of the class in which you are using the Center widget because, according to the standards of flutter you cannot write the name of the class same as the widget you are using inside that class. If you do so, then you cannot be able to make child or children inside that widget.
Also, the solution of Felipe Augusto is correct.
Related
I am new to Flutter and I have an issue with a parameter.
I have got the following code from a tutorial:
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [const Color(0xff3C8CE7), const Color(0xff00EAFF)])),
The project is running fine on both platforms, but there is a warning at line:
colors: [const Color(0xff3C8CE7), const Color(0xff00EAFF)])),
This is the warning output at the Dart Analysis debug window:
I have searched for the right implementation of BoxDecoration and gradient colors and it says just the way I am doing it.
What is wrong in the code?
Please, make sure you're using the stable or beta channel of flutter. To do so, run these commands:
flutter channel stable
flutter upgrade
flutter clean
Restart your IDE and try to run again.
I'm building my first web project.
So the project is structured like so:
Web: Is a web site, one of the pages (RetailerAccess) is an actual app that should be compatible with all devices.
In order to do so I use platform check in main() and return the proper screen.
home: kIsWeb
? Stack(
children: [
Container(
// color: Colors.white,
child: AnimatedBackground(),
),
LayoutTemplate()
],
)
: RetailerAccess());
It works as expected.. When running on browser shows the web page and you can navigate to RetailerAccess while if running on iPad starts directly on RetailerAccess.
So far so good.
The weird part is that text widgets are drawn with a double green underline where running on device while when running on browser are drawn normally.
Are you aware of any bug that makes it behave like this or is there something I should set in a specific way?
I tried running it in Release mode on an old iPad 3 running iOS 9.3.5 but no changes..
Thank you very much for your help.
Update:
I realised I don't have a Scaffold in RetailerAccess wrapped it with a Material widget and it solved it.
Shouldn't a theme been passed to RetailerAccess anyways?
You are getting the error because you don't have a scaffold widget.
Try the code below:
It works perfectly:
home: kIsWeb
? Scaffold(
Stack(
children: [
Container(
// color: Colors.white,
child: AnimatedBackground(),
),
LayoutTemplate()
],
)
),
: Scaffold(
RetailerAccess()
);
I hope this helps.
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/basic.dart';
void main() {
runApp(
MaterialApp(
home: Scaffold(
backgroundColor: Colors.blueGrey,
appBar: AppBar(
backgroundColor: Colors.blueGrey[900],
title: Text("I AM RICH"),
),
body: Center(
child:Image(
image: NetworkImage('https://images.pexels.com/photos/462118/pexels-photo-462118.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500'),
),
),
),
debugShowCheckedModeBanner: false,
)
);
}
In debug mode service extension and multiple permissions are enabled by default(in flutter)
as you are in release mode you have to add internet permission in androidmanifest.xml manually.( Just like you add it in native development)
navigate to android-> app-> src-> main-> AndroidManifest.xml and add this line outside of application scope.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
This happened to me today and i figured that my emulator was not connected to the internet.if you are facing this issue make sure your device you are using is connected to the internet.
Even I was facing the same problem until I checked that my device was not connected to the Internet and later turned it On the NetworkImage loaded the image from the URL string passed
You should use the network constructor. Please change this:
Image(
image: NetworkImage('https://images.pexels.com/photos/462118/pexels-photo-462118.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500'),
)
to this:
Image.network('https://images.pexels.com/photos/462118/pexels-photo-462118.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500')
You can use in Container in your body like this and wrap your Container with Center Widget
Container(
height: 90,
width: 90,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage("https://images.pexels.com/photos/462118/pexels-photo-462118.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500"),
//whatever image you can put here
fit: BoxFit.cover,
),
),
),
Check if your emulator is able to access internet first. Try loading any url in Google Chrome inside emulator. If not, add the dns address 8.8.8.8 to your network settings.
Try adding below line in main/Manifest file.
android:usesCleartextTraffic="true"
You can get more detail by implementing errorBuilder listener in Image.network widget.
I think your code is fine, to resolve this shutdown android studio & Emulator and restart it again.
It works for me, and it keeps happening to me, I guess its because it couldn't load the photo
CircleAvatar(
backgroundImage: NetworkImage('https://www.pinclipart.com/picdir/big/218-2189254_free-online-avatars-kid-characters-family-vector-for.png'));
Also check if your phone connected to the internet.
n debug mode service extension and multiple permissions are enabled by default(in flutter)
as you are in release mode you have to add internet permission in androidmanifest.xml manually.( Just like you add it in native development)
navigate to android-> app-> src-> main-> AndroidManifest.xml and add this line outside of application scope.
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.
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].