我有一个文本文件(.txt),我想成为一个资产,我可以在以后扫描.
在pubspec.yaml中,我确保:
flutter:
assets:
- res/my_file.txt
Run Code Online (Sandbox Code Playgroud)
存在.该文件位于res/
我创建的文件夹中,与lib/android/
和的级别相同ios/
我正在尝试从自定义类中读取文件,而不是小部件.
根据文档,我将使用此导入:
import 'package:flutter/services.dart' show rootBundle;
Run Code Online (Sandbox Code Playgroud)
并开始阅读:
/// Assumes the given path is a text-file-asset.
Future<String> getFileData(String path) async {
return await rootBundle.loadString(path);
}
Run Code Online (Sandbox Code Playgroud)
要获得实际数据,请执行以下操作:
String data = await getFileData(fileName);
Run Code Online (Sandbox Code Playgroud)
但是,当我使用fileName
like时'assets/res/my_file.txt'
,我收到一个错误:Unable to load asset: assets/res/my_file.txt
.
值得注意的是,我正试图通过单元测试来做到这一点.关于如何正确地做到这一点的任何想法?谢谢!
我想使用选择器进行布局和图像视图.但它不适合我.当我将图像视图更改为图像按钮或按钮时,它工作正常.任何帮助将不胜感激..提前感谢..
这里是我使用的xmls ..
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@drawable/bg"
/>
<item
android:drawable="@drawable/bg_01" />
</selector>
Run Code Online (Sandbox Code Playgroud)
布局xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_height="fill_parent">
<ImageButton
android:layout_width="100dp"
android:layout_height="50dp"
android:text="layout tester"
android:textColor="#000000"
android:textStyle="bold"
android:paddingTop="10dp"
android:src="@drawable/testselector"
android:layout_gravity="center_horizontal" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我正在使用PopupWindow
,效果很好,但是问题是在放大显示有黑色边框的布局视图之后。
final PopupWindow popupWindow = new PopupWindow(context);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.pop_up_window_menu_layout, null);
popupWindow.setContentView(view);
Run Code Online (Sandbox Code Playgroud)
pop_up_window_menu_layout.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/solid_white"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:text="SAVE"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:textColor="@color/black"
android:textSize="@dimen/txt_size_sliding_list" />
Run Code Online (Sandbox Code Playgroud)
我尝试使用删除边框popupWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT))
,但问题仍然相同。
谁能告诉我如何删除不需要的黑色边框?
我shared_preferences
在 Flutter 应用程序中使用了插件。从某一刻开始(可能是在 Flutter 升级之后),它开始抛出异常:
E/flutter (27778): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (27778): type '_InternalLinkedHashMap' is not a subtype of type 'Map<String, Object>' where
E/flutter (27778): _InternalLinkedHashMap is from dart:collection
E/flutter (27778): Map is from dart:core
E/flutter (27778): String is from dart:core
E/flutter (27778): Object is from dart:core
E/flutter (27778):
E/flutter (27778): #0 SharedPreferences.getInstance (package:shared_preferences/shared_preferences.dart)
E/flutter (27778): <asynchronous suspension>
E/flutter (27778): #1 loadFirstUse (**path**/lib/main.dart:29:53)
E/flutter (27778): <asynchronous suspension>
E/flutter (27778): #2 main (**path**/lib/main.dart:17:9)
E/flutter (27778): <asynchronous suspension>
E/flutter (27778): …
Run Code Online (Sandbox Code Playgroud)