I not sure why there is a cap symbol in pubspec.yaml file under dependencies. See below image.
The project is working even without the cap symbol.
This is called caret syntax:
Caret syntax provides a more compact way of expressing the most common sort of version constraint. ^version means "the range of all versions guaranteed to be backwards compatible with the specified version", and follows pub’s convention for semantic versioning.
So in your example, you've got:
meta: ^1.1.6 - equivalent to >=1.1.6 <2.0
equatable: ^0.2.3 - equivalent to >=0.2.3 <0.3.0
cupertino_icons: ^0.1.2 - equivalent to >=0.1.2 <0.2.0
When i go to copy or paste on textfield, the tooltip is always on english language, and my device is on Pt-Br. How can i change or fix that ?
Add flutter_localizations to your pubspec.yaml:
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
In your MaterialApp:
return MaterialApp(
...
locale: const Locale('de'), // change to locale you want. not all locales are supported
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
);
image not displaying in flutter app.
But I got some errors in debug console.
I/FlutterActivityDelegate(22603): onResume setting current activity to this
I/FlutterActivityDelegate(22603): onResume setting current activity to this
I/Timeline(22603): Timeline: Activity_idle id: android.os.BinderProxy#3eb59326 time:39937973
I/flutter (22603): ══╡ EXCEPTION CAUGHT BY SERVICES ╞══════════════════════════════════════════════════════════════════
I/flutter (22603): The following assertion was thrown resolving an image codec:
I/flutter (22603): Unable to load asset: assets/images/logo.png
I/flutter (22603): When the exception was thrown, this was the stack:
I/flutter (22603): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter (22603): <asynchronous suspension>
I/flutter (22603): #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:383:44)
I/flutter (22603): <asynchronous suspension>
I/flutter (22603): #2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:368:14)
I/flutter (22603): #3 ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:265:86)
I/flutter (22603): #4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:82:22)
I/flutter (22603): #5 ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:265:63)
I/flutter (22603): (elided 8 frames from package dart:async)
I/flutter (22603): Image provider: AssetImage(bundle: null, name: "assets/images/logo.png")
I/flutter (22603): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#19ce7(), name: "assets/images/logo.png",
I/flutter (22603): scale: 1.0)
I/flutter (22603): ════════════════════════════════════════════════════════════════════════════════════════════════════
D/ViewRootImpl(22603): ViewPostImeInputStage ACTION_DOWN
D/ViewRootImpl(22603): ViewPostImeInputStage ACTION_DOWN
My Pubspec.yaml file
assets:
- assets/images/logo.png
login.dart code
new Image.asset("assets/images/logo.png", width: 60.0,
height: 24.0,
fit: BoxFit.cover)
directory structure
pubspec.yaml file
i mentioned images files in wrong way. i put space between '-' and image name instead of tab.
assets:
- assets/images/logo.png
Don't put spaces between the character instead of tab in pubspec.yaml file
There may be two issues:
1.) Either you pubspec.yaml file is not having proper indention. Attaching snippet for reference.
flutter:
uses-material-design: true
assets:
- assets/
- assets/ will consider all the images in the directory.
2.) If you are using .jpg image then please change it to .jpeg wherever you are calling it.
Attaching the snippet for you reference
class _UserLoginState extends State<UserLogin> {
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
children: <Widget>[
Image(image: AssetImage("assets/christmas.jpeg"),
fit: BoxFit.cover,
],
)
);
}
}
Make sure the folder you are referring in Image.asset contains the file.
For example:
Image.asset(
"./assets/images/loading.gif",
height: 125.0,
width: 125.0,
)
The folder should be:
C:\your_app_folder\assets\images
pubspec.yaml:
assets:
- assets/
- assets/images/
Run flutter clean
to clean the intermediate files and refresh.
Hot Reload was the issue in my case. I simply restarted the Android studio and re-run the app, it all worked!.
I assume you copied your files inside assets/images/ folder right?
Also you need to reference your images into the pubspec.yaml file.
flutter:
...
assets:
- assets/images/logo.png
Make sure your image folder is in project folder.
Refer https://api.flutter.dev/flutter/painting/AssetImage-class.html
Add assets images in pubspec.yaml file and in the asset mention the path from images and it works fine.
new AssetImage("images/logo.png")
For example
CircleAvatar(
radius: 80,
backgroundImage: AssetImage('images/logo.png'),
),
I just replaced
Image.asset("assets\images\_Lightweight.jpeg"),
To
Image.asset("assets/images/_Lightweight.jpeg"),
my problem was indentation of assets section. I wrote it at the beginning of the line, whereas it should be indented with a Tab after flutter: section.
Robie
I faced the same issue after adding a new image to the asset folder. I was doing "Hot Reload", I destroyed the app from the background, re-run the app and the problem got resolved.
Your pubspec.yaml is not intended properly
flutter:
uses-material-design: true
assets:
- images/
Check if it's intended this way.
There are several opportunities to make the mistake, higher chance that it's in the pubspec.yaml declaration.
Most of the time it's better to specify the directory of your assets. This way you'll edit pubspec.yaml less frequently.
The asset directory/item is not declared properly (e.g. wrong indent)
If your IDE is Android Studio and you edited the pubspec, hitting the Run button won't cut it. Execute flutter run in the Terminal to run the app.
If you can't type in the Terminal, flutter may already be running. Press ctrl + c to terminate the process then run. No need to restart your IDE.
These changings will definately work.
AssetImage('mypicture.jpg')
Above is my code, I have not used "assets" folder name with my image file name and it works perfect.
and these are my assets in 'pubspec.yaml' file.
assets:
- assets/cat.png
- assets/mypicture.jpg```
Flutter doesn't support jpg files.
Try the complete path of the file with '/'(forward slash).
I have an app that I've primarily built in AngularDart v0.12 that was building into and running in JS just fine, but after upgrading to AngularDart v1.0 and accounting for the breaking changes, it fails to run in JS now after building to it without a problem. When attempting to run in Chrome the console gives the following error:
Uncaught Type "QueryService" not found in generated typeFactory maps
The following is my pubspec.yaml config:
name: ###
author: ###
description: ###
homepage: ###
transformers:
- angular:
dart_sdk: "C:/dart/dart-sdk"
suppressWarnings: false
- $dart2js:
suppressWarnings: false
minify: false
checked: true
dependencies:
angular: any
angular_dart_ui_bootstrap: any
bootjack: any
browser: any
chrome: any
di: any
dquery: any
google_oauth2_client: any
http_server: any
inject: any
js: any
logging: any
mock: any
mongo_dart: any
route: any
shadow_dom: any
shelf: any
shelf_route: any
shelf_web_socket: any
sqljocky: any
unittest: any
The following is my module class:
class AppModule extends Module{
AppModule(){
/*
* Services, Routers, and Controller
*/
bind(QueryService);
bind(RoutingService);
bind(RouteInitializerFn, toValue: initRoutes);
bind(NgRoutingUsePushState, toValue: new NgRoutingUsePushState.value(false));
/*
* Components
*/
bind(Login);
bind(Dashboard);
bind(SideNav);
}
}
The following is the QueryService class:
#Injectable()
class QueryService{
Http _http;
Scope _scope;
QueryService(Http this._http, Scope this._scope){
someFunction();
}
}
Just to reiterate, this application is working fine when run using the DartVM, but doesn't seem to want to inject the QueryService when built into JS.
Also, I'm aware this may be very similar to this question, but the solution doesn't appear to have any effect in my case, and the AngularDart version is newer.
The #Injectable annotation should trigger the generation of the factory.
If it's not may be you are not running the angular transformer ?
You pubspec should list this transformer, ie:
name: myApp
dependencies:
angular: ">=1.0.0 <2.0.0"
transformers:
- angular
Apparently I was importing my app's library directly via a relative path in my main.dart file instead of importing it as a package. This caused a duplicate declaration of the library which must have given the transformer some issues. I basically just had to change my import on my main.dart file from
import '../library/src/app.dart';
to
import 'package:myPackage/app.dart'
I just migrated to angular-0.10.0. My application works as expected in Dartium but in js through dart2js I get the follow unminified error in web console :
No getter for 'ctrl'.
STACKTRACE:
Error
at dart.wrapException (http://localhost:8080/app/main.dart.js:2390:15)
at StaticClosureMap.lookupGetter$1 (http://localhost:8080/app/main.dart.js:8926:17)
at DynamicParserBackend.newAccessScope$1 (http://localhost:8080/app/main.dart.js:7177:21)
at DynamicParserImpl.parseAccessOrCallScope$0 (http://localhost:8080/app/main.dart.js:7531:29)
at DynamicParserImpl.parsePrimary$0 (http://localhost:8080/app/main.dart.js:7507:21)
at DynamicParserImpl.parseAccessOrCallMember$0 (http://localhost:8080/app/main.dart.js:7464:21)
at DynamicParserImpl.parsePrefix$0 (http://localhost:8080/app/main.dart.js:7460:21)
at DynamicParserImpl.parseMultiplicative$0 (http://localhost:8080/app/main.dart.js:7439:21)
at DynamicParserImpl.parseAdditive$0 (http://localhost:8080/app/main.dart.js:7428:21)
at DynamicParserImpl.parseRelational$0 (http://localhost:8080/app/main.dart.js:7413:21)
The pubspec.yaml
name: app
version: 0.0.1-dev
dependencies:
angular: any
browser: any
dev_dependencies:
unittest: any
transformers:
- angular
The controller :
#Controller(selector: '[myCtrl]', publishAs: 'ctrl')
class MyController {
String search = 'test';
}
The html template :
<div myCtrl>
<input ng-model="ctrl.search"></input>
{{ ctrl.search }}
</div>
The error only appear inside an <ng-view>. If I add the above html directly in the main html the js error does not appear.
Pavel Jbanov indicates in this post :
I believe expression_generator transformer is unable to discover your template file, so you might need to manually include it: https://github.com/angular/angular.dart/blob/master/lib/tools/transformer/options.dart#L17
and further :
The transformer will hopefully get better at identifying template files so you don't have to manually list them. Right now, afaik, it only picks up template files of components.
So for now you have to manually add all untracked html templates inside your pubspec.yaml like this in the html_files section :
name: app
version: 0.0.1-dev
dependencies:
angular: any
browser: any
dev_dependencies:
unittest: any
transformers:
- angular:
html_files:
- web/template1.html
- web/template2.html
- web/template3.html