小编R R*_*ara的帖子

如何在 WebView Flutter 中显示加载指示器?

我想在屏幕上显示 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)

有人可以帮我解决这个问题吗?因为我已经搜索和研究过它仍然可以找到解决方案。

loading webview flutter

16
推荐指数
6
解决办法
1万
查看次数

如何在 CameraX 上的相机预览中裁剪图像矩形

我有一个自定义相机应用程序,它具有居中的矩形视图,如下所示:

在此处输入图片说明

当我拍照时,我想忽略矩形外的所有内容。这是我的 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)

crop kotlin android-camerax

10
推荐指数
3
解决办法
7793
查看次数

Flutter:未处理的异常:FileSystemException:创建失败,路径='目录:''(操作系统错误:只读文件系统,errno = 30)

我已经谷歌搜索,我找到的解决方案正在使用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)

camera local-storage flutter

10
推荐指数
1
解决办法
2万
查看次数

如何在 Flutter 中制作自定义底部导航栏

我有一个像这样的底部导航栏设计:

在此处输入图片说明

我尽力使用以下代码创建底部导航栏的自定义:

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)

flutter bottomappbar

9
推荐指数
2
解决办法
2万
查看次数

Flutter中如何进行模块化,将各个应用功能分开

在 Android 原生上分离每个应用程序功能,构建项目,实现架构组件并使其更容易在团队中工作,您可以使用模块化,这样每个人都可以通过只专注于模块来专注于各自的工作。如果我想使用 3 个应用程序功能(登录、注册、配置文件)的示例制作一个 Flutter 应用程序,并希望为每个功能实现模块化以使其更易于团队合作。你如何实现模块化?是否有参考其模块化 Flutter 的最佳实践?因为如果在 Android Native 上已经有很多相关的文章了,而我在检查 Flutter 时还没有找到。

modularization flutter

6
推荐指数
1
解决办法
2510
查看次数

如何使底页高度遵循JSON的数量

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)

dart flutter bottom-sheet

5
推荐指数
1
解决办法
201
查看次数

如何让 CameraX 预览在拍照时冻结?

我的自定义 CameraX 流程如下:

  • 打开相机预览(实时)
  • 点击按钮拍照
  • 单击该按钮时有一个过程(将路径转换为位图、旋转图像、自动裁剪图像、保存到设备中)
  • 运行所有进程并成功后,将图像发送到其他Fragment并将其显示为glide

问题是何时running all the process (in step 3)有 adelayed 2 seconds并且相机预览静止livenot freezelock)。怎么做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)

kotlin android-camerax

5
推荐指数
1
解决办法
6343
查看次数

在 Flutter 中发布的“flutter build apk”在打开应用程序时崩溃

我已经设置了构建应用程序版本,如 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)

installation release flutter

3
推荐指数
2
解决办法
8765
查看次数

Flutter:比较预期和实际的块测试问题

我有如下测试:

      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)

unit-testing flutter bloc-test

3
推荐指数
1
解决办法
1979
查看次数

未处理的异常:NoSuchMethodError:“String”类没有实例方法“forEach”

通过实现 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)

flutter bloc

2
推荐指数
1
解决办法
2万
查看次数

自生成 .dart_tool/package_config.json 文件后,pubspec.lock 文件已更改,请再次运行“pub get”

我尝试使用自定义预测试脚本在 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)

这是我的 flutter 项目结构: 在此输入图像描述

但是当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 codemagic build-runner

2
推荐指数
1
解决办法
3048
查看次数

如何在 Flutter 中将图像从 API 设置为 Carousel

我想在 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?

api carousel flutter

0
推荐指数
1
解决办法
2681
查看次数