我想在屏幕上显示 Web 视图数据之前先显示 Loading。怎么能这样?
这是我的代码:
class WebDetailPage extends StatelessWidget {
final String title;
final String webUrl;
final Completer<WebViewController> _controller =
Completer<WebViewController>();
WebDetailPage({
@required this.title,
@required this.webUrl,
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colour.white,
title: Text(title, style: TextStyle(color: Colour.midnightBlue)),
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colour.midnightBlue),
onPressed: () => Navigator.of(context).pop()),
),
body: Center(
child: WebView(
initialUrl: webUrl,
javascriptMode: JavascriptMode.unrestricted,
onWebViewCreated: (WebViewController webViewController) {
_controller.complete(webViewController);
},
),
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题吗?因为我已经搜索和研究过它仍然可以找到解决方案。
我有一个自定义相机应用程序,它具有居中的矩形视图,如下所示:
当我拍照时,我想忽略矩形外的所有内容。这是我的 XML 布局:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black_50">
<TextureView
android:id="@+id/viewFinder"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_margin="16dp"
android:background="@drawable/rectangle"
app:layout_constraintBottom_toTopOf="@+id/cameraBottomView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="@+id/cameraBottomView"
android:layout_width="match_parent"
android:layout_height="130dp"
android:background="@color/black_50"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ImageButton
android:id="@+id/cameraCaptureImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:src="@drawable/ic_capture_image"
app:layout_constraintBottom_toBottomOf="@id/cameraBottomView"
app:layout_constraintEnd_toEndOf="@id/cameraBottomView"
app:layout_constraintStart_toStartOf="@id/cameraBottomView"
app:layout_constraintTop_toTopOf="@id/cameraBottomView"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
这是我用于 cameraX 预览的 kotlin 代码:
class CameraFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the …Run Code Online (Sandbox Code Playgroud) 我已经谷歌搜索,我找到的解决方案正在使用path_provider,添加权限AndroidManifest.xml,是的,我已经尝试过。但我的仍然有错误。
这是我的功能
Future<File> _takePicture() async {
Directory root = await getTemporaryDirectory(); // this is using path_provider
String directoryPath = '$root/bozzetto_camera';
await Directory(directoryPath).create(recursive: true); // the error because of this line
String filePath = '$directoryPath/${DateTime.now()}.jpg';
try {
await _cameraController.takePicture(filePath);
} catch (e) {
return null;
}
return File(filePath);
}
Run Code Online (Sandbox Code Playgroud)
这是我的AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
...
android:requestLegacyExternalStorage="true">
...
</application>
Run Code Online (Sandbox Code Playgroud)
这充满了日志。
E/flutter (14879): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: FileSystemException: Creation failed, path = 'Directory: …Run Code Online (Sandbox Code Playgroud) 我有一个像这样的底部导航栏设计:
我尽力使用以下代码创建底部导航栏的自定义:
class FABBottomAppBarItem {
FABBottomAppBarItem({this.iconData, this.text});
IconData iconData;
String text;
}
class FABBottomAppBar extends StatefulWidget {
FABBottomAppBar({
this.items,
this.centerItemText,
this.height: 60.0,
this.iconSize: 24.0,
this.backgroundColor,
this.color,
this.selectedColor,
this.notchedShape,
this.onTabSelected,
}) {
assert(this.items.length == 2 || this.items.length == 4);
}
final List<FABBottomAppBarItem> items;
final String centerItemText;
final double height;
final double iconSize;
final Color backgroundColor;
final Color color;
final Color selectedColor;
final NotchedShape notchedShape;
final ValueChanged<int> onTabSelected;
@override
State<StatefulWidget> createState() => FABBottomAppBarState();
}
class FABBottomAppBarState extends State<FABBottomAppBar> {
int _selectedIndex = …Run Code Online (Sandbox Code Playgroud) 在 Android 原生上分离每个应用程序功能,构建项目,实现架构组件并使其更容易在团队中工作,您可以使用模块化,这样每个人都可以通过只专注于模块来专注于各自的工作。如果我想使用 3 个应用程序功能(登录、注册、配置文件)的示例制作一个 Flutter 应用程序,并希望为每个功能实现模块化以使其更易于团队合作。你如何实现模块化?是否有参考其模块化 Flutter 的最佳实践?因为如果在 Android Native 上已经有很多相关的文章了,而我在检查 Flutter 时还没有找到。
BottomSheet在Flutter中,以便高度跟随项数(来自JSON的数据)是什么?因为我使高度不跟随数据量,而是跟随每个手机屏幕的1/2。因此,如果电话很长,则底部会有空白空间。如果手机短,则下面的屏幕会剪切数据。
这是用于创建底部工作表的代码:
void _showModalBottomSheet(AsyncSnapshot<CatlistResult> snapshot) {
showModalBottomSheet(
context: context,
builder: (BuildContext bc) {
return Card(
elevation: 3.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.only(topLeft: Radius.circular(15), topRight: Radius.circular(15))),
child: Container(
padding: EdgeInsets.only(left: 16.0, top: 10.0, right: 16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
margin: EdgeInsets.only(bottom: 10.0),
child: Image.asset('assets/images/main/more_2lines_20dp.png', scale: 3.5),
),
Expanded(
child: GridView.builder(
physics: NeverScrollableScrollPhysics(), //kill scrollable
shrinkWrap: true,
itemCount: snapshot == null ? 0 : snapshot.data.catlist.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 4),
itemBuilder: (BuildContext context, int index) {
var numItems = …Run Code Online (Sandbox Code Playgroud) 我的自定义 CameraX 流程如下:
问题是何时running all the process (in step 3)有 adelayed 2 seconds并且相机预览静止live(not freeze或lock)。怎么做camera preview freeze or lock when running the process?
这是我在 Camera X 中运行相机预览的代码:
class CameraFragment : Fragment() {
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_camera, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) …Run Code Online (Sandbox Code Playgroud) 我已经设置了构建应用程序版本,如 pro-guard、icon、manifest 等,但没有flavor. 我将 dir 迁移/android到,AndroidX因为如果没有,运行时无法构建应用程序版本flutter build apk。所以我迁移它并成功。像下面这样:
rifafauzi6@Anonymous-X456UR:/media/rifafauzi6/NM/Materi/BackUp Aplikasi Android/Flutter Project/vallery$ flutter build apk
You are building a fat APK that includes binaries for android-arm, android-arm64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
To generate an app bundle, run:
flutter build appbundle --target-platform android-arm,android-arm64
Learn more on: https://developer.android.com/guide/app-bundle
To split the APKs per …Run Code Online (Sandbox Code Playgroud) 我有如下测试:
blocTest(
'emits [ViewData.loading and ViewData.loaded] when GetRepositories is added',
build: () {
when(
() => useCase.getRepositories(),
).thenAnswer((_) async => Right(repositoriesDummyEntityFromRemote));
return homeBloc;
},
act: (HomeBloc bloc) => bloc.add(GetRepositories()),
expect: () => [
HomeState(
statusRepositories: ViewData.loading(message: 'Loading'),
isShowTitle: false,
),
HomeState(
statusRepositories:
ViewData.loaded(data: repositoriesDummyEntityFromRemote),
isShowTitle: false,
),
],
);
Run Code Online (Sandbox Code Playgroud)
当我运行时出现错误:
package:bloc_test/src/bloc_test.dart 229:13 testBloc.<fn>.<fn>
dart:async _completeOnAsyncError
package:bloc_test/src/bloc_test.dart testBloc.<fn>.<fn>
===== asynchronous gap ===========================
dart:async _asyncThenWrapperHelper
package:bloc_test/src/bloc_test.dart testBloc.<fn>.<fn>
dart:async runZonedGuarded
package:bloc_test/src/bloc_test.dart 192:13 testBloc.<fn>
package:bloc_test/src/bloc_test.dart 191:5 testBloc.<fn>
dart:async runZoned
package:bloc/src/bloc_overrides.dart 46:26 BlocOverrides.runZoned
package:bloc_test/src/bloc_test.dart 190:23 …Run Code Online (Sandbox Code Playgroud) 通过实现 BLOC 和 RX Dart,我在我的应用程序上有一个文章搜索功能。我已经根据成为搜索关键字的“标题”成功搜索了文章,但是当我错误地填写“标题”时,结果并没有出现“文章不存在/其他任何东西”之类的错误根据关键“标题”的意思,结果不是实时的,而是在 LogCat 中得到如下错误:
E/flutter (25135): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: NoSuchMethodError: Class 'String' has no instance method 'forEach'.
E/flutter (25135): Receiver: "Data not found"
E/flutter (25135): Tried calling: forEach(Closure: (dynamic) => Null)
E/flutter (25135): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:50:5)
E/flutter (25135): #1 new Articles.fromJson (package:vallery/src/models/articles/articles.dart:11:22)
E/flutter (25135): #2 ApiProvider.searchArticle (package:vallery/src/resources/api/api_provider.dart:65:23)
E/flutter (25135): <asynchronous suspension>
E/flutter (25135): #3 Repository.searchArticlesRepository (package:vallery/src/resources/repository/repository.dart:19:74)
E/flutter (25135): #4 SearchArticleBloc.searchArticleBloc (package:vallery/src/blocs/article/articles_search_bloc.dart:12:42)
E/flutter (25135): <asynchronous suspension>
E/flutter (25135): #5 EditableTextState._formatAndSetValue (package:flutter/src/widgets/editable_text.dart:1335:14)
E/flutter (25135): #6 EditableTextState.updateEditingValue (package:flutter/src/widgets/editable_text.dart:971:5)
E/flutter (25135): …Run Code Online (Sandbox Code Playgroud) 我尝试使用自定义预测试脚本在 Codemagic 上运行测试。这是我的预测试脚本:
#!/bin/sh
cd libraries
cd dependencies
flutter pub get
cd ..
cd core
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
cd ..
cd ..
cd features
cd splash
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
cd ..
cd proposal
flutter pub get
flutter pub run build_runner build --delete-conflicting-outputs
Run Code Online (Sandbox Code Playgroud)
但是当pre-test运行时,我收到此错误:
Running "flutter pub get" in dependencies... 2.5s
Running "flutter pub get" in core... 4.9s
The pubspec.lock file has changed since …Run Code Online (Sandbox Code Playgroud) 我想在 Flutter 应用程序中使用横幅滑块,所以我找到了一个库来制作它,即Carousel. 这是一个很好的图书馆,但我发现这个图书馆有问题,How to set image from API into Carousel?或者have any library for support image from API (list), have dot indicator, autoplay like Carousel?
flutter ×10
kotlin ×2
api ×1
bloc ×1
bloc-test ×1
bottom-sheet ×1
bottomappbar ×1
build-runner ×1
camera ×1
carousel ×1
codemagic ×1
crop ×1
dart ×1
installation ×1
loading ×1
release ×1
unit-testing ×1
webview ×1