所以我的球图像显示在模拟器上,而不是我添加的我的magic.jpg。我的pubspec.yaml很好。我知道。有人知道怎么了吗? my folder tree
pubspec.yaml文件:
name: magic_8_ball
description: A new Flutter application.
version: 1.0.0+1
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/images/magic.jpg
我的代码:
import 'package:flutter/material.dart';
import 'dart:math';
void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: BallPage(),
),
);
class BallPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.blue[900],
title: Text('Ask Me Anything'),
),
body: Stack(children: [
Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/magic"),
fit: BoxFit.cover,
),
),
),
Ball()
]),
);
}
}
class Ball extends StatefulWidget {
@override
_BallState createState() => _BallState();
}
class _BallState extends State<Ball> {
int ballNum = 1;
@override
Widget build(BuildContext context) {
return Center(
child: FlatButton(
onPressed: () {
setState(() {
ballNum = Random().nextInt(5) + 1;
});
},
child: Image.asset('assets/images/ball$ballNum.png')));
}
}
错误日志:
I/flutter (22530): ══╡ EXCEPTION CAUGHT BY IMAGE RESOURCE SERVICE ╞════════════════════════════════════════════════════
I/flutter (22530): The following assertion was thrown resolving an image codec:
I/flutter (22530): Unable to load asset: assets/images/magic
I/flutter (22530):
I/flutter (22530): When the exception was thrown, this was the stack:
I/flutter (22530): #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:221:7)
I/flutter (22530): <asynchronous suspension>
I/flutter (22530): #1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:464:44)
I/flutter (22530): <asynchronous suspension>
I/flutter (22530): #2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:449:14)
I/flutter (22530): #3 ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:316:48)
I/flutter (22530): #4 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:160:22)
I/flutter (22530): #5 ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:316:25)
I/flutter (22530): (elided 13 frames from package dart:async)
I/flutter (22530):
I/flutter (22530): Image provider: AssetImage(bundle: null, name: "assets/images/magic")
I/flutter (22530): Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#77a87(), name: "assets/images/magic",
I/flutter (22530): scale: 1.0)
I/flutter (22530): ════════════════════════════════════════════════════════════════════════════════════════════════════
答案 0 :(得分:1)
您没有将图像rootView = inflater.inflate(R.layout.book_chapter_custom_cab_view, container, false);
webView = rootView.findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webview.evaluateJavascript("(function(){return window.getSelection().toString()})()",
new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
Log.v(TAG, "SELECTION:" + value);
}
});
的扩展名放在小部件String htmlBegin = "<!DOCTYPE html><head><meta charset=\"utf-8\" /> " +
" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"> " +
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"></head><body>";
String htmlEnd = "<br/><br/><br/></body></html>";
webView.loadDataWithBaseURL("", htmlBegin + content + htmlEnd, "text/html", "UTF-8", "");
中。
简单地说,像这样magic
,它应该可以正常工作。