考虑以下build()函数:
Widget build(BuildContext context){
return MaterialApp(
home: Scaffold(
body: Center(
child: ListView.builder(
itemCount: 6,
itemBuilder: (context, i){
if(numberTruthList[i]){
return ListTile(
title: Text("$i"),
);
}
},
),
)
),
);
}
Run Code Online (Sandbox Code Playgroud)
如果 numberTruthList 是
List<bool> numberTruthList = [true, true, true, true , true, true];
然后输出是
如果 numberTruthList 是
List<bool> numberTruthList = [false, true, true, true , true, true];
输出结果是
我希望输出是带有项目的 ListView
ListTile( title: Text("$i"),);
Run Code Online (Sandbox Code Playgroud)
对于 i 的值,使得 numberTruthList[i] 为真,代码应该是什么?
我最近在我的 flutter 应用程序中安装了谷歌地图,但我一直收到这个错误,
MissingPluginException (MissingPluginException(在频道 plugins.flutter.io/google_maps_53 上没有找到方法 camera#animate 的实现))
这发生在我调用的每个地图控制器上,即使 oncreated 方法也给我带来了同样的问题,我第一次尝试 flutter clean 和 flutter pub get after 但无济于事,现在我不知道
这是我创建地图的主要 dart 文件
GoogleMap(
mapToolbarEnabled: false,
mapType: MapType.normal,
initialCameraPosition: CameraPosition(target:appState.initialPosition, zoom: 15.0),
markers: appState.markers,
onCameraMove: appState.onCameraMove,
polylines: appState.polyLines,
myLocationEnabled: true,
zoomControlsEnabled: false,
onMapCreated: appState.onCreated,compassEnabled: false,
myLocationButtonEnabled: false,
),
Run Code Online (Sandbox Code Playgroud)
这是我单独的 appstate.dart 文件
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:geolocator/geolocator.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:toladriver/requests/google_maps_requests.dart';
class AppState with ChangeNotifier {
static LatLng _initialPosition;
LatLng _lastPosition = _initialPosition;
bool locationServiceActive = true;
final Set<Marker> _markers …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现这样的功能:当我长按一个列表项时,动作模式应该开始,并且可以删除一个或多个项目.
我在MainActivity DocumentsActivity中开始搜索,它DocumentsFragment使用ListView及其项启动Fragment .ListAdapter setListAdapter(this.documentsAdapter)在Fragment的onCreate中通过方法调用进行初始化和设置.我onActivityCreated在片段中的listview上设置了各种监听器:
public void onActivityCreated(Bundle savedInstanceState) {
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
getListView().setItemChecked(position, true);
return true;
}});
getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
menu.clear();
((DocumentsActivity)getActivity()).getMenuInflater().inflate(R.menu.documents_context_menu, menu);
return true;
}
});
super.onActivityCreated(savedInstanceState);
}
Run Code Online (Sandbox Code Playgroud)
当我长时间点击listitem时,操作模式开始,菜单documents_context_menu显示为操作栏.但问题是,操作栏出现在工具栏上方,工具栏不会消失(参见图片).
我试图调用getSupportActionBar().hide()或将其设置为null或甚至使用其他样式/主题.一切都行不通.有时蓝色工具栏是完全白色的,但这就是全部.
我完全不知道为什么工具栏不会消失.你能提一些建议吗?
提前致谢!
_____更新1 _____
这是styles.xml
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:fitsSystemWindows">true</item>
<item name="colorAccent">@color/darkblue100</item>
<item name="android:actionOverflowButtonStyle">@style/ActionButtonOverflow</item>
<item name="actionOverflowButtonStyle">@style/ActionButtonOverflow</item>
<item …Run Code Online (Sandbox Code Playgroud) 我想在我的 PDF 中打印印地语,我也尝试过使用 Google 的 Raleway-Regular.ttf 字体,但它也不起作用。
\nfinal font = await rootBundle.load("fonts/ARIAL.TTF");\nfinal ttf = pw.Font.ttf(font);\n\npdf.addPage(\n pw.MultiPage(\n pageFormat: PdfPageFormat.a4,\n margin: pw.EdgeInsets.all(32),\n build: (pw.Context context){\n return <pw.Widget>[\n pw.Center(\n child: pw.Text("\xe0\xa4\xae\xe0\xa5\x87\xe0\xa4\xa8",style: pw.TextStyle(fontSize: 16,font: ttf))\n ),\n pw.SizedBox(height: 20),\n pw.Center(\n child: pw.Text("ABC",style: pw.TextStyle(fontSize: 16))\n ),\n ),\n),\nRun Code Online (Sandbox Code Playgroud)\n我收到以下错误:
\n***I/flutter (24862): 无法将字符串解码为 Latin1。\nI/flutter (24862): 此字体不支持 Unicode 字符。\nI/flutter (24862): 如果您想使用拉丁语以外的字符串字符串,请改用 TrueType (TTF) 字体。\nI/flutter (24862):请参阅https://github.com/DavBfr/dart_pdf/wiki/Fonts-Management \nI/flutter (24862):----- ----------------------------------------------------\nE/flutter (24862): [错误:flutter/lib/ui/ui_dart_state.cc(177)] 未处理的异常:无效参数(字符串):包含无效字符。:“\xe0\xa4\xae\xe0\xa5\x87\xe0\xa4\xa8”
\n我遇到的问题是,我无法从搭载 Android 9 的智能手机上选择的文件中提取文件扩展名。该问题不会出现在搭载 Android 8 或更低版本的设备上。
当用户选择任何类型的文件时,onActivityResult 被调用。在这个方法中,我从 FileUtils 类调用 getPath,所以我可以提取文件扩展名。
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Uri uri = new Uri.Builder().build();
if (resultCode == RESULT_OK) {
switch (requestCode) {
case PICKFILE_REQUEST_CODE: {
String path = new File(data.getData().getPath()).getAbsolutePath();
if (path != null) {
uri = data.getData();
path = FileUtils.getPath(getApplicationContext().getContentResolver(), uri);
name = path.substring(path.lastIndexOf("."));
extension = path.substring(path.lastIndexOf(".") + 1);
}
break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
FileUtils类(来自此 repo)的getPath()通过 URI 评估文件是哪种文件,但对这种情况负责的是以下部分:
public static String …Run Code Online (Sandbox Code Playgroud)