I'm using classes from a new dart file in flutter, but it doesn't use the same dependencies and autocompletes as my main.dart file even after importing import 'package:flutter/material.dart'; and import 'package:flutter/services.dart';. What am I doing wrong?
I refactored my new files as dart files and they all ended with .dart. This wasn't an explicit direction on any of the tutorials.
Related
It comes all of my Flutter Projects. Is the folder necessary or not ?
Do I delete the folder ?
Basically runApp() method(inside main.dart) contains a class and it should be same as defined in this tester.pumpWidget(....) method. If they don't match, it causes this error.
e.g
In your main.dart if runApp() method is having a class HomePage
runApp(const HomePage()); then inside widget_test.dart file it should be like await tester.pumpWidget(const HomePage());
I got the same error and when i move my mouse on it,it shows that MyApp() links to another project,e.g:
and it links to library'package:try_base_flutter/main.dart',then I found every dart file in the lib links to the try_base_flutter.So I search the key word "try_base_flutter",finally I found the wrong code in the pubspec.yaml's first line
,I write the name: try_base_flutter,because I copy the file from the project try_base_flutter,so just change the name,my problem will be fine.
Remove const. like await tester.pumpWidget(MyApp());
I have a question about a reusable font awesome widget for Flutter that I am trying to create.
I am getting an error in Android Studio for Windows that, "The method 'FaIcon' isn't defined for the type 'IconContent'."
Below is how I set up the reusable widget. I found this advice but not sure how to implement: "Use the FaIcon Widget + FontAwesomeIcons class for the IconData"
https://gist.github.com/countrymusicfy/3c5aa155063b49bf5d07e89241bc637b
Any suggestions would be greatly appreciated!
You are missing import statement
You should include both in pubspec.yaml file and in your dart file.
Add import statement on your dart file
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
Add dependecy on your pubspec.yaml
dependencies:
font_awesome_flutter: ^9.1.0
In my project when I create a new widget then AndroinStudio suggests me to import cuppertino library for the widget.
How to use material library for imports by default as my project is only Android project?
"as my project is only Android project"
What difference does that make? You can use Material Design with every Flutter platform.
Some editors could suggest you to import that library, but to remove errors when creating a new Widget class, you should:
import 'package:flutter/widgets.dart';
I got an error Error: Entrypoint doesn't contain a main function Flutter, I tried to restart android studio but it did not work
Depends on what the program is support to do. There should be a main class that is initiated. As an example:
import 'package:flutter/material.dart';
import 'package:english_words/english_words.dart';
void main() => runApp(MyApp()); // initiate MyApp as StatelessWidget
// Main class
class MyApp extends StatelessWidget {
// creating main screen and building list of wordpairs
#override
This worked for me:
When new project is created then got the error "Entrypoint doesn't contain a main function Flutter".
To resolve this I followed below step
First make sure your flutter and dart sdk paths are properly configured.
You can re-include the files/project root folder.
Goto File -> Project Structure -> Module
And then add the root folder of the project by clicking + icon, then it will detect a flutter app again.
Build the project and check for the error.
add main function to your project. you might miss that
void main() => runApp(MyApp());
There's another case where this is possible, because of dart package file
delete all that .packages files, should get resolved.
Just do this
File -> Project structure -> Modules
From right select
Sources
form [Source, Paths, Dependencies] Tabs
Select Plus Icon -> Apply -> ok button
Make sure you use same name of project and pubspec.yaml file name Sometime it happens when we copy one pubspec file for another project.
in my case the launching function was named something else, renamed it to main, then it worked.
Add this if its missing in your main.dart file
void main() => runApp(MyApp());
This function tells Dart where the program starts, and it must be in the file that is considered the "entry point" for you program.
I cut some text above the main function and that included a closing } which made the main inside some class above it. That caused the above error. I put back the } above main and everything became ok.
I would like to show the native date picker depending on the device. For example UIDatePicker if it's iOS.
I've tried to add SelectDateTextField inside my widget and it works, but it looks like the Android one. Does anyone have any recommendations?
You should check the Platform then need to write specific widgets as per your need.
Use the APIs provided by the Dart.
Example:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
Your Widget
Platform.isIOS ? CupertinoWidget() : MaterialWidget()