Flutter "import framework:dart" throws error - flutter

my Flutter dart script requires 'import framework:dart'. But Visual Studio Code's "Problems Tab" indicates this error:
Target of URI doesn't exist: 'framework:dart'.
Try creating the file referenced by the URI, or Try using a URI for a file that does exist.
Needing suggestions to remedy this.
Thanks!

If you use the flutter framework for dart, the import must be:
import 'package:flutter/material.dart';
if you want to use the Cupertino-style (==iOS theme) than you have to make following import:
import 'package:flutter/cupertino.dart';
If you have Flutter installed, this imports should work.

Because framework.dart is in the widgets.dart library packages, I think you need to import the widgets.dart library.
import 'package:flutter/widgets.dart';
For the usage, you can read the docs here.
I hope it will help.

Related

Undefined name 'Provider' in flutter

I am getting an error called "Undefined name 'Provider' in flutter. Here is the code snippet for it:
addData() async {
UserProvider _userProvider = Provider.of(context, listen : false);
await _userProvider.refreshUser();}
Can someone help me figure this out?
You need to import the provider package on the current page
import 'package:provider/provider.dart';
Provider is a powerful State Management package which has to be added to the project and imported in order to use it.
If you haven't added the package, then add it by the following command in the project folder in Terminal/Command Prompt:
flutter pub add provider
Then in the file containing the snippet, import the package at the top like the following:
import 'package:provider/provider.dart';
Check if you have following dependency added in your pubspec.yaml file
dependencies:
provider: ^6.0.3
If not add it or simply run in your terminal
flutter pub add provider
After getting your dependency import the provider package in your page:
import 'package:provider/provider.dart';

Importing packages in flutter using dart

for other packages like the flutter package we use the following import:
import 'package:flutter/material.dart';
but why are we doing this for dart packages?
import 'dart:io';
why can't it be same like flutter?:
import 'package:dart/io/platform.dart';
The package: prefix is used to import libraries found in packages while the dart: prefix is used to import the core libraries (such as io, collection, convert...).
Consequently, we don't use the package prefix for the core libraries because they're already built-in and no need to add them to the pubspec file.

Flutter Location Import Errors

I am trying to use the Location plugin (https://pub.dev/packages/location#-readme-tab-)
I have included all dependencies in the analysis and tried to test using the example however, the following imports are throwing errors "Target of URI doesn't exist..."
import 'get_location.dart';
import 'listen_location.dart';
import 'permission_status.dart';
import 'service_enabled.dart';
I tried to import dependencies and changed my settings.gradle with no success. Any advice is greatly appreciated.

VSCode dart code auto completion doesn't work properly for packages

I use VSCode for flutter development everything is good but autocompletion is not working properly for packages.I wonder what is wrong with my IDE settings
If I import packages without as keyword the code completion doesn't work but if I import them as something it works for example if I import like following :
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:http/http.dart'
The intellisense doesn't recognize FireStore and http but if I import like:
import 'package:cloud_firestore/cloud_firestore.dart' as fire;
import 'package:http/http.dart' as http;
now when I call fire It shows firestore class and methods and same is for http and every other package
Since you're not getting auto-suggestions, please check these guidelines
Please ensure, you have included your package in pubspec.yaml
Did you executed flutter pub get
Usually, we can use Ctrl+Space to get auto-suggestion on VSCode

Failed to minify the code ./node_modules/#material-ui/core/es/styles/createMuiTheme.js

Hey i i am working with the latest version of material UI, i have a problem when i am trying to create build (react-scripts build).
this is the error that i got:
Creating an optimized production build...
Failed to compile.
Failed to minify the code from this file:
./node_modules/#material-ui/core/es/styles/createMuiTheme.js:17
i didn't found any solution for my problem. i am using createMuiTheme for override some components.
thank you very much.
This is a common error with material-ui that occurs when you import a component with /es in the path.
Search on your code if at some point you import createMuiTheme. You most likely import it from #material-ui/core/es/styles..., instead, import it this way:
import { createMuiTheme } from '#material-ui/core/styles';