Tag Archives: Flutter

Flutter Error: Cannot run with sound null safety, because the following dependencies don‘t support

Since flutter 2, flutter has enabled null security by default in the configuration. By incorporating null checking into the type system, these errors can be caught during development, so as to prevent crashes caused by the reproduction environment. If empty security is enabled in the current project and the imported third-party plug-in is not adapted, the operation returns the following error.

Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:provider

For solutions, see https://dart.dev/go/unsound-null-safety
Restarted application in 341ms.

At this time, you can check whether the new version of the imported plug-in supports empty security. If the plug-in supports empty security, the plug-in platform will mark it as empty security:

if the imported plug-in does not support empty security, you can execute the following commands on the terminal to run the software

flutter run --no-sound-null-safety

The problem of error reporting caused by fluent swift

flutter oc-based flutter project using swift-based plugin leads to error reporting problem
Xcode’s output:

ld: warning: Could not find or use auto-linked library ‘swiftCoreGraphics’
ld: warning: Could not find or use auto-linked library ‘swiftDarwin’
ld: warning: Could not find or use auto-linked library ‘swiftUIKit’
ld: warning: Could not find or use auto-linked library ‘swiftFoundation’
ld: warning: Could not find or use auto-linked library ‘swiftCompatibility51’
ld: warning: Could not find or use auto-linked library ‘swiftMetal’
ld: warning: Could not find or use auto-linked library ‘swiftObjectiveC’
ld: warning: Could not find or use auto-linked library ‘swiftCoreFoundation’
ld: warning: Could not find or use auto-linked library ‘swiftCompatibility50’
ld: warning: Could not find or use auto-linked library ‘swiftCoreImage’
ld: warning: Could not find or use auto-linked library
‘swiftCompatibilityDynamicReplacements’
ld: warning: Could not find or use auto-linked library ‘swiftDispatch’
ld: warning: Could not find or use auto-linked library ‘swiftCoreMedia’
ld: warning: Could not find or use auto-linked library ‘swiftQuartzCore’
ld: warning: Could not find or use auto-linked library ‘swiftCore’
ld: warning: Could not find or use auto-linked library ‘swiftCoreAudio’
ld: warning: Could not find or use auto-linked library ‘swiftSwiftOnoneSupport’
Undefined symbols for architecture x86_64:
“value witness table for Builtin.UnknownObject”, referenced from:
full type metadata for kzcity_picker.SwiftKzcityPickerPlugin in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
“_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 69: …rom: _̲_swift_FORCE_LO…swiftCompatibilityDynamicReplacementsKaTeX parse error: Expected group after ‘_’ at position 111: …eant: _̲_swift_FORCE_LO…swiftCompatibilityDynamicReplacementsKaTeX parse error: Expected group after ‘_’ at position 24: …picker) “_̲_swift_FORCE_LO…_swiftCompatibility51”, referenced from:
_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 22: …Compatibility51_̲_kzcity_picker in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
(maybe you meant: _swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 22: …Compatibility51_̲_kzcity_picker)
“_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 52: …rom: _̲_swift_FORCE_LO…swiftCompatibility50KaTeX parse error: Expected group after ‘_’ at position 102: …ybe you meant: _̲_swift_FORCE_LO…swiftCompatibility50KaTeX parse error: Expected group after ‘_’ at position 24: …picker) “_̲_swift_FORCE_LO…_swiftQuartzCore”, referenced from:
_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 17: …swiftQuartzCore_̲_kzcity_picker in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
(maybe you meant: _swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 17: …swiftQuartzCore_̲_kzcity_picker)
“_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 46: …rom: _̲_swift_FORCE_LO…swiftCoreImageKaTeX parse error: Expected group after ‘_’ at position 102: …ybe you meant: _̲_swift_FORCE_LO…swiftCoreImageKaTeX parse error: Expected group after ‘_’ at position 24: …picker) “_̲_swift_FORCE_LO…_swiftCoreGraphics”, referenced from:
_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 19: …iftCoreGraphics_̲_kzcity_picker in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
(maybe you meant: _swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 19: …iftCoreGraphics_̲_kzcity_picker)
“_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 51: …rom: _̲_swift_FORCE_LO…swiftCoreFoundationKaTeX parse error: Expected group after ‘_’ at position 102: …ybe you meant: _̲_swift_FORCE_LO…swiftCoreFoundationKaTeX parse error: Expected group after ‘_’ at position 144: …ith: _̲_C.FlutterPlugi…_swiftUIKit”, referenced from:
_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 12: _swiftUIKit_̲_kzcity_picker in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
(maybe you meant: _swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 12: _swiftUIKit_̲_kzcity_picker)
“swift_allocObject”, referenced from:
@objc kzcity_picker.SwiftKzcityPickerPlugin.handle(: __C.FlutterMethodCall, result:
(Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
“static (extension in
Foundation):Swift.String.unconditionallyBridgeFromObjectiveC(__C.NSString?) ->
Swift.String”, referenced from:
kzcity_picker.SwiftKzcityPickerPlugin.handle(: __C.FlutterMethodCall, result:
(Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
“swift_getInitializedObjCClass”, referenced from:
type metadata accessor for __C.FlutterMethodChannel in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
type metadata accessor for kzcity_picker.SwiftKzcityPickerPlugin in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
kzcity_picker.SwiftKzcityPickerPlugin.handle(: __C.FlutterMethodCall, result:
(Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
“_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 47: …rom: _̲_swift_FORCE_LO…swiftFoundationKaTeX parse error: Expected group after ‘_’ at position 102: …ybe you meant: _̲_swift_FORCE_LO…swiftFoundationKaTeX parse error: Expected group after ‘_’ at position 24: …picker) “_̲_swift_FORCE_LO…_swiftCoreAudio”, referenced from:
_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 16: _swiftCoreAudio_̲_kzcity_picker in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
(maybe you meant: _swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 16: _swiftCoreAudio_̲kzcity_picker)
“static Swift.String.+ infix(Swift.String, Swift.String) -> Swift.String”, referenced
from:
kzcity_picker.SwiftKzcityPickerPlugin.handle(: __C.FlutterMethodCall, result:
(Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
“_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 43: …rom: _̲_swift_FORCE_LO…swiftDarwinKaTeX parse error: Expected group after ‘_’ at position 102: …ybe you meant: _̲_swift_FORCE_LO…swiftDarwinKaTeX parse error: Expected group after ‘_’ at position 151: …ith: _̲_C.FlutterPlugi…_swiftDispatch”, referenced from:
_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 15: _swiftDispatch_̲_kzcity_picker in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
(maybe you meant: _swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 15: _swiftDispatch_̲_kzcity_picker)
“swift_release”, referenced from:
kzcity_picker.SwiftKzcityPickerPlugin.handle(: __C.FlutterMethodCall, result:
(Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
__swift_destroy_boxed_opaque_existential_0 in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
@objc kzcity_picker.SwiftKzcityPickerPlugin.handle(: __C.FlutterMethodCall, result:
(Any?) -> ()) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
“_swift_deallocObject”, referenced from:
l_objectdestroy in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
“_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 42: …rom: _̲_swift_FORCE_LO…swiftMetalKaTeX parse error: Expected group after ‘_’ at position 102: …ybe you meant: _̲_swift_FORCE_LO…swiftMetalKaTeX parse error: Double subscript at position 115: …ugin.handle(_: _̲_C.FlutterMetho…_swiftObjectiveC”, referenced from:
_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 17: …swiftObjectiveC_̲_kzcity_picker in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
(maybe you meant: _swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 17: …swiftObjectiveC_̲_kzcity_picker)
“_swift_unknownObjectRetain”, referenced from:
@objc static kzcity_picker.SwiftKzcityPickerPlugin.register(with:
__C.FlutterPluginRegistrar) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
“Swift._bridgeAnythingToObjectiveC(A) -> Swift.AnyObject”, referenced from:
reabstraction thunk helper from @escaping @callee_unowned @convention(block)
(@unowned Swift.AnyObject?) -> () to @escaping @callee_guaranteed (@in_guaranteed
Any?) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
“_swift_getObjCClassMetadata”, referenced from:
type metadata accessor for __C.FlutterMethodChannel in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
@objc static kzcity_picker.SwiftKzcityPickerPlugin.register(with:
__C.FlutterPluginRegistrar) -> () in libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
“(extension in Foundation):Swift.String._bridgeToObjectiveC() -> __C.NSString”,
referenced from:
@nonobjc __C.FlutterMethodChannel.__allocating_init(name: Swift.String,
binaryMessenger: __C.FlutterBinaryMessenger) -> __C.FlutterMethodChannel in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
“_swift_getObjCClassFromMetadata”, referenced from:
@nonobjc __C.FlutterMethodChannel.__allocating_init(name: Swift.String,
binaryMessenger: __C.FlutterBinaryMessenger) -> __C.FlutterMethodChannel in
libkzcity_picker.a(SwiftKzcityPickerPlugin.o)
“_swift_FORCE_LOADKaTeX parse error: Expected group after ‘_’ at position 46: …rom: _̲_swift_FORCE_LO…swiftCoreMediaKaTeX parse error: Expected group after ‘_’ at position 102: …ybe you meant: _̲_swift_FORCE_LO…swiftCoreMedia$kzcity_picker)
“type metadata for Swift.S

Unable to find bundled Java version =>Mac Flutter [Android Studio Arctic Fox 2020.3.1]

Terminal: flutter doctor -v
1. problem: android studio prompts Unable to find bundled Java version

[!] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio Preview.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    ✗ Unable to find bundled Java version.
    • Try updating or re-installing Android Studio.

Treatment method:

cd /Applications/Android\ Studio.app/Contents/jre
ln -s ../jre jdk
ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk

Perfect result:

[✓] Android Studio (version 2020.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)

2 questions

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    ✗ Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.

Terminal input: Shuttle doctor — Android licenses. The following error is reported

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema

at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(SchemaModule.java:156)

at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)

at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHandler.java:81)

at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:73)

at com.android.sdklib.tool.sdkmanager.SdkManagerCli.main(SdkManagerCli.java:48)

Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema

at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)

at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)

at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)

... 5 more

Treatment method

one   Update the SDK manager in the tools/bin directory of the Android SDK

Terminal input:/users/* * */tools/bin/sdkmanager — update

2. Configure Java_ HOME

JDK under MAC is installed under /library/Java/javavirtualmachines by default. The real path is shown in the figure below:

WJdeMacBook-Pro:~ wj$ cd /Library/Java/JavaVirtualMachines
WJdeMacBook-Pro:JavaVirtualMachines wj$ ls -la
total 0
drwxr-xr-x  3 root  wheel   96  3 21 15:25 .
drwxr-xr-x  4 root  wheel  128  1  1  2020 ..
drwxr-xr-x  3 root  wheel   96  4  3  2019 jdk1.8.0_77.jdk

Refer to Apple’s documentation for the command/usr/libexec/Java_ Use the – V option after home to list all versions of Java_ Home, i.e. the following results:

WJdeMacBook-Pro:JavaVirtualMachines wj$ /usr/libexec/java_home -V
Matching Java Virtual Machines (2):
    1.8.77.03 (x86_64) "Oracle Corporation" - "Java" /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
    1.8.0_77 (x86_64) "Oracle Corporation" - "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk/Contents/Home
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home

Select the JDK version you need and configure it to. Bash_ In profile

Terminal input:

one     open .bash_ profile

two     export JAVA_ HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_ 212.jdk/Contents/Home

export PATH=$JAVA_ HOME/bin:$PATH

three   The above 2 configuration paths are copied with. Bash_ In profile file

four   After saving, in order for the configuration to take effect immediately, you need to execute: source ~ /. Bash_ Profile command

Input: fluent doctor at the terminal again

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    ! Some Android licenses not accepted.  To resolve this, run: flutter doctor
      --android-licenses

Terminal input: fluent doctor — Android liceses

Multiple occurrences: review licenses that have not been accepted (Y/N)?        All input: y and then press enter

Perfect result:

WJdeMacBook-Pro:~ wj$ flutter doctor
***
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
***

[Solved] Error: Cannot run with sound null safety, because the following dependenciesdon‘t support null safe

Today, I use flutter SDK 2.2.2   +  fish_ Redux: ^ 0.3.4 to encode this error, as shown in the following figure:

After checking, it is caused by the wrong selection of the SDK version,

sdk: ">=2.12.0 <3.0.0" Change to   sdk: ">=2.8.0 <3.0.0"

OK, the version above 2.12 has empty security requirements

pubspec.yaml

name: fish_redux_demo02
description: A new Flutter project.

# The following line prevents the package from being accidentally published to
# pub.dev using `pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.0.0+1

environment:
  #sdk: ">=2.12.0 <3.0.0"
  sdk: ">=2.8.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter


  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2

  fish_redux: ^0.3.4
  #Demo list of libraries to be used
  dio: ^3.0.9 #network request framework
  json_annotation: ^2.4.0 #json serialization and deserialization for

dev_dependencies:
  flutter_test:
    sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec

# The following section is specific to Flutter.
flutter:

  # The following line ensures that the Material Icons font is
  # included with your application, so that you can use the icons in
  # the material Icons class.
  uses-material-design: true

  # To add assets to your application, add an assets section, like this:
  # assets:
  #   - images/a_dot_burr.jpeg
  #   - images/a_dot_ham.jpeg

  # An image asset can refer to one or more resolution-specific "variants", see
  # https://flutter.dev/assets-and-images/#resolution-aware.

  # For details regarding adding assets from package dependencies, see
  # https://flutter.dev/assets-and-images/#from-packages

  # To add custom fonts to your application, add a fonts section here,
  # in this "flutter" section. Each entry in this list should have a
  # "family" key with the font family name, and a "fonts" key with a
  # list giving the asset and other descriptors for the font. For
  # example:
  # fonts:
  #   - family: Schyler
  #     fonts:
  #       - asset: fonts/Schyler-Regular.ttf
  #       - asset: fonts/Schyler-Italic.ttf
  #         style: italic
  #   - family: Trajan Pro
  #     fonts:
  #       - asset: fonts/TrajanPro.ttf
  #       - asset: fonts/TrajanPro_Bold.ttf
  #         weight: 700
  #
  # For details regarding fonts from package dependencies,
  # see https://flutter.dev/custom-fonts/#from-packages

Flutter SocketException: OS Error: No route to host, errno = 113, address = XXX

Or flutter   WebSocketChannelException: SocketException: OS Error: No route to host, errno = 113, address = XX

This type of access problem,

1. First of all, whether the port on the server side is open or not, MacOS or windows, please do it yourself

2. The problems encountered here, I will explain my situation. First of all, the test I did belongs to the type of LAN, and I know that my server IP and real mobile phone, including web page test, are all in the same network segment. For example, 192.168.1.xx to 192.168.1.250. There is no problem with the access of the extension computer, but the mobile phone has this problem, The IP of the mobile phone is also in the same segment with the server we tested, but why is the problem of not finding the host mentioned above?

Finally, we found that the mobile phone is linked in the 5g band of the router, which may be due to the IP isolation between 5g band and other IP when the router is set up, resulting in mutual inaccessibility

It’s OK to enter 2.4G

Realization of breakpoint download based on DIO in flutter

As there are not many articles downloaded from the shutter breakpoint, and there are few cases, I found them on the DIO case after searching for them for a long time, and it took me some time to be wronged
based on DIO: ^ 4.0.0 and Path_ Provider: ^ 2.0.2 implements the function of downloading a large file

Core code

import 'dart:async';
import 'dart:io';
import 'dart:typed_data';
import 'package:dio/dio.dart';
import 'package:path_provider/path_provider.dart';

class DownloadFile {
  /// Used to record the url being downloaded to avoid duplicate downloads
  static var downloadingUrls = Map<String, CancelToken>();

  /// Breakpoint downloading of large files
  static Future<void> download({
    required String url,
    required String savePath,
    ProgressCallback?onReceiveProgress,
    void Function()?done,
    void Function(DioError)?failed,
  }) async {
    int downloadStart = 0;
    bool fileExists = false;
    File f = File(savePath);
    if (await f.exists()) {
      downloadStart = f.lengthSync();
      fileExists = true;
    }
    print("start: $downloadStart");
    if (fileExists && downloadingUrls.containsKey(url)) {
      return;
    }
    var dio = Dio();
    CancelToken cancelToken = CancelToken();
    downloadingUrls[url] = cancelToken;
    try {
      var response = await dio.get<ResponseBody>(
        url,
        options: Options(
          /// Receive response data as a stream
          responseType: ResponseType.stream,
          followRedirects: false,
          headers: {
            /// Downloading key locations in segments
            "range": "bytes=$downloadStart-",
          },
        ),
      );
      File file = File(savePath);
      RandomAccessFile raf = file.openSync(mode: FileMode.append);
      int received = downloadStart;
      int total = await _getContentLength(response);
      Stream<Uint8List> stream = response.data!.stream;
      StreamSubscription<Uint8List>?subscription;
      subscription = stream.listen(
        (data) {
          /// Write files must be synchronized
          raf.writeFromSync(data);
          received += data.length;
          onReceiveProgress?.call(received, total);
        },
        onDone: () async {
          downloadingUrls.remove(url);
          await raf.close();
          done?.call();
        },
        onError: (e) async {
          await raf.close();
          downloadingUrls.remove(url);
          failed?.call(e as DioError);
        },
        cancelOnError: true,
      );
      cancelToken.whenCancel.then((_) async {
        await subscription?.cancel();
        await raf.close();
      });
    } on DioError catch (error) {
      /// The request has been sent and the server responds with a status code that it is not in the range of 200
      if (CancelToken.isCancel(error)) {
        print("Download cancelled");
      } else {
        failed?.call(error);
      }
      downloadingUrls.remove(url);
    }
  }

  /// Get the size of the downloaded file
  static Future<int> _getContentLength(Response<ResponseBody> response) async {
    try {
      var headerContent =
          response.headers.value(HttpHeaders.contentRangeHeader);
      print("download files: $headerContent");
      if (headerContent != null) {
        return int.parse(headerContent.split('/').last);
      } else {
        return 0;
      }
    } catch (e) {
      return 0;
    }
  }

  /// Cancel Mission
  static void cancelDownload(String url) {
    downloadingUrls[url]?.cancel();
    downloadingUrls.remove(url);
  }
}

Call case

void main() {
  runApp(TestMyApp());
}

class TestMyApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _TestMyAppState();
  }
}

class _TestMyAppState extends State<TestMyApp> {
  void download() async {
    var url = "mp4";
    Directory dir = await getApplicationDocumentsDirectory();
    var sDCardDir = dir.path;
    var savePath = sDCardDir + "/video/1.mp4";
    File f = File(sDCardDir + "/video");
    if (!await f.exists()) {
      new Directory(sDCardDir + "/video").createSync();
    }

    await DownLoadManage().download(
      url: url,
      savePath: savePath,
      onReceiveProgress: (received, total) {
        if (total != -1) {
          print("Download1Received:" +
              received.toString() +
              "Total:" +
              total.toString() +
              "Progress.+${(received/total * 100).floor()}%");
        }
      },
      done: () {
        print("Download 1 completed");
      },
      failed: (e) {
        print("Download 1 failed:" + e.toString());
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Center(
        child: GestureDetector(
          onTap: () {
            download();
          },
          child: Container(
            width: 150,
            height: 150,
            color: Colors.red,
          ),
        ),
      ),
    );
  }
}

Automatically assigning platform `iOS` with version `8.0` on target `Runner`

Environment: MAC, when running the flutter run in vscode, the following error is reported:

before , the code was logged off, now release it. Podfile is a folder brought by the MAC running itself, and then running the flutter run will report an error
. Go to the configuration file and configure the code

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '9.0'
      config.build_settings['ENABLE_BITCODE'] = 'NO'
    end
  end
end

Then run the flutter run to start the project successfully

Integrate native IOS plug-ins into the flutter project

Modify signature

First, open the flutter project, open IOS module in Xcode, open the IOS folder in Xcode, modify the team, and change the signature to your IOS app signature.

In Android studio, run it on IOS simulator, and make sure there is no problem.

Add plug-in dependency

In pubspec.yaml, add plug-ins under dependencies to integrate zhgd with source code_ native_ Take the plugin native plug-in as an example

zhgd_native_plugin:
path: ../zhgd_native_plugin

Note: the plug-in project is located in the same level directory of the flutter project.

common problem

    file not found with < angled> include; Use "quotes" instead select target, build settings – & gt; Header search paths, add the corresponding header file search path, such as “${pods_ CONFIGURATION_ BUILD_ DIR}/Masonry/Masonry.framework/Headers” 'Masonry.h' file not found with < angled> include; Use is used in the use "quotes" instead podfile file_ frameworks!( Because several pods are swift libraries, and swift can only be integrated by framework. Therefore, the import method of header file has changed. It can only be imported through # import “masonry. H”, not # Import & lt; Masonry.h> Import in the same way:-1: Undefined symbol: _ OBJC_ CLASS_$_ Fluttermethodchannel and : - 1: undefined symbol:_ OBJC_ CLASS_$_ The fluttermethodchannel compiler cannot find the flutter. H header file. Most likely, use is used in podfile_ frameworks!( Because a swift plug-in is referenced in the project. This problem is the problem of flutter itself https://github.com/flutter/flutter/issues/10968 。

Flutter development: prompt error parsing localfile when running the project: ‘/ users / xxx / Android / APP / SRC / main / androidmanifest. XML’… Solution

preface

At the beginning of the development of flutter, there are all kinds of problems. At this time, it is a little difficult for the developers who have just contacted the development of flutter. Therefore, in the early stage of the development of flutter, we should accumulate more, consult more and step on more holes, so that we can start to develop the flutter project quickly. This article will share a relatively simple problem encountered in the development of flutter, the error prompted after the operation of flutter packages get.

 
Error message

After running the flutter packages get, the flutter project will prompt the following error prompt:

After executing the command flutter packages get, an error is reported. It is about the Android related prompt in the flutter project

Error parsing LocalFile: '/Users/xxx/xxxxxx/android/app/src/main/AndroidManifest.xml' Please ensure that the android manifest is a valid XML document and try again.

exit code 1

analysis

Through the above error prompt, the editor has told the specific location of the error file, so follow the file path of the prompt and enter the corresponding file to check the specific location of the error. However, after checking, no error is found. After performing the flitter clean, the editor runs the flitter run again, and the error is still reported. The corresponding writing method of the specific file is as follows:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

    package="com.example.platform_app">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application

        android:name="io.flutter.app.FlutterApplication"

        android:label="platform_app">

        <activity

            android:name=".MainActivity"

            android:launchMode="singleTop"

            android:theme="@style/LaunchTheme"

           android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"

            android:hardwareAccelerated="true"

            android:windowSoftInputMode="adjustResize">

            <intent-filter>

                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>

            </intent-filter>

        </activity>

        <meta-data

            android:name="flutterEmbedding"

            android:value="2" />

    </application>

</manifest>

Through repeated investigation, we finally found out the problem, label & lt/ manifest> The end tag of is missing one, as shown in the following figure:

 
resolvent

In & gt; And then it was lost android:icon= “@mipmap/ic_ So it should be like this:

<application

    android:name="io.flutter.app.FlutterApplication"

    android:label="platform_app"

    android:icon="@mipmap/ic_launcher">

<activity...

Finally, click save file, run the project again, and no error will be reported directly. The project flutter is successfully started, and the problem is perfectly solved.

 
The above is the whole content of this chapter. Welcome to WeChat official account of the three shopkeeper, “program ape by three shopkeeper”, three shopkeeper’s Sina micro-blog “three shopkeeper 666”, welcome to pay attention!

Three WeChat’s official account:

Sina Weibo of three shopkeepers:

 

Flutter solves the problem of incorrect use of parent datawidget and boundary constraint

Flutter solves the problem of incorrect use of parent datawidget and boundary constraint

The error information is as follows:

What about this kind of error

1 tells us that this error is related to the parent component, and then we can see 2 errors, and we can analyze the column – & gt under the page when loading the homepage written by ourselves; Container-> ConstrainedBox-> Expanded-> There is a problem with the subcomponents in the path of constrainedbox
the solution is to remove the expanded control and directly use it in constrainedbox
original code:

Container(
          // width: MediaQuery.of(context).size.width,
          height: 36.0,
          child: Expanded(
            flex: 1,
            child: ConstrainedBox(
              constraints: BoxConstraints.expand(),
              child: Stack(
                alignment: AlignmentDirectional.topCenter,
                children: [
                  Positioned(
                    child: Text("Recommendation",textDirection: TextDirection.ltr,style: TextStyle(fontSize: 20),),
                    left: 3.0,
                    top: 3.0,
                  ),
                  Positioned(
                      right: 3.0,
                      top: 3.0,
                      child: Container(
                        child:  Text("More",textDirection: TextDirection.rtl,style: TextStyle(fontSize: 16),),
                        /*Padding(
                        padding: EdgeInsets.all(4),
                        child:
                      ),*/
                        decoration: BoxDecoration(
                            border: Border.all(color: Colors.black87,width: 1.0,style: BorderStyle.solid),
                            borderRadius: BorderRadius.circular(20)
                        ),
                      )
                  )
                ],
              ),
            ),
          ),
       )

Modified code:

Container(
          // width: MediaQuery.of(context).size.width,
          height: 36.0,
          child: ConstrainedBox(
            constraints: BoxConstraints.expand(),
            child: Stack(
              alignment: AlignmentDirectional.topCenter,
              children: [
                Positioned(
                  child: Text("Recommendation",textDirection: TextDirection.ltr,style: TextStyle(fontSize: 20),),
                  left: 3.0,
                  top: 3.0,
                ),
                Positioned(
                    right: 3.0,
                    top: 3.0,
                    child: Container(
                      child:  Text("More",textDirection: TextDirection.rtl,style: TextStyle(fontSize: 16),),
                      /*Padding(
                        padding: EdgeInsets.all(4),
                        child:
                      ),*/
                      decoration: BoxDecoration(
                          border: Border.all(color: Colors.black87,width: 1.0,style: BorderStyle.solid),
                          borderRadius: BorderRadius.circular(20)
                      ),
                    )
                )
              ],
            ),
          )
       )

Why is this right
after a variety of baidu searches, it is found that the widget in flutter is rendered by the renderbox object at its bottom. The render box is constrained by its parent widget, and its size is adjusted according to these constraints. Constraints are composed of minimum width, maximum width, minimum height and maximum height; The size is composed of specific width and height