Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
[ad_1]
Steps to breed
NO.1 Create the next Dart program:
(1) important.dart
import 'bundle:flutter/materials.dart';
void important() => runApp(const MyApp());
@pragma('vm:entry-point')
void take a look at() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : tremendous(key: key);
@override
Widget construct(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colours.blue,
),
house: Scaffold(
physique: const Middle(
youngster: Textual content('Flutter Demo'),
),
),
);
}
}
(2) pubspec.yaml
model: 1.0.0+1
atmosphere:
sdk: ">=2.16.2 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The next provides the Cupertino Icons font to your software.
# Use with the CupertinoIcons class for iOS fashion icons.
cupertino_icons: ^1.0.2
shared_preferences: ^2.0.13
(3) flutter physician
/Customers/dqs/Paperwork/CompanyProjects/Flutter/flutter/bin/flutter physician --verbose
[✓] Flutter (Channel steady, 2.10.4, on macOS 12.0.1 21A559 darwin-x64, locale zh-Hans-CN)
• Flutter model 2.10.4 at /Customers/dqs/Paperwork/CompanyProjects/Flutter/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision c860cba910 (4 weeks in the past), 2022-03-25 00:23:12 -0500
• Engine revision 57d3bac3dd
• Dart model 2.16.2
• DevTools model 2.9.2
• Pub obtain mirror https://pub.flutter-io.cn
• Flutter obtain mirror https://storage.flutter-io.cn
NO.2 ~ Create the next iOS program:
(1) BaseFlutterController.swift
import UIKit
import Flutter
class BaseFlutterController: FlutterViewController {
override init(engine: FlutterEngine, nibName: String?, bundle nibBundle: Bundle?) {
tremendous.init(engine: engine, nibName: nibName, bundle: nibBundle)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been carried out")
}
override func viewDidLoad() {
tremendous.viewDidLoad()
}
}
(2) TestController.swift
import UIKit
import FlutterPluginRegistrant
class TestController: BaseFlutterController {
init(withEntrypoint entryPoint: String?) {
let appDelegate: AppDelegate = UIApplication.shared.delegate as! AppDelegate
let newEngine = appDelegate.flutterEngines.makeEngine(withEntrypoint: entryPoint, libraryURI: nil)
// register third-party packages
GeneratedPluginRegistrant.register(with: newEngine)
tremendous.init(engine: newEngine, nibName: nil, bundle: nil)
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been carried out")
}
override func viewDidLoad() {
tremendous.viewDidLoad()
}
}
(3) AppDelegate.swift
import UIKit
import Flutter
@UIApplicationMain
class AppDelegate: FlutterAppDelegate {
//MARK: Flutter Engines
lazy var flutterEngines = FlutterEngineGroup(title: "native_flutter_engine_group", undertaking: nil)
(4) enter flutter display
let testVC = TestController(withEntrypoint: "take a look at")
navigationController?.pushViewController(testVC, animated: true)
…then run the app on an iOS system.
Anticipated conduct
Anticipate take a look at() to be run as this system’s entry-point, yielding a traditional flutter display.
Precise conduct
The app runs properly in debug mode, however fails in launch mode with the next error:
[768:219965] [VERBOSE-2:shell.cc(93)] Dart Unhandled Exception: NoSuchMethodError: No top-level getter 'take a look at' declared.
Receiver: top-level
Tried calling: take a look at, stack hint: #0 NoSuchMethodError._throwNew (dart:core-patch/errors_patch.dart:222)
[768:219965] [VERBOSE-2:dart_isolate.cc(681)] Couldn't resolve important entrypoint perform.
[VERBOSE-2:dart_isolate.cc(165)] Couldn't run the run important Dart entrypoint.
[768:219965] [VERBOSE-2:runtime_controller.cc(381)] Couldn't create root isolate.
[768:219965] [VERBOSE-2:shell.cc(580)] Couldn't launch engine with configuration.
My strive
After I eliminated the ‘shared_preferences: ^2.0.13’ bundle from the ‘pubspec.yaml’, it labored properly in each debug and launch mode.
Then I additionally tried different packages(local-storage associated and others), I discovered that after I used packages about native storage (e.g. shared_preferences、cached_network_image …), the issue confirmed up undoubtedly, and once I eliminated them, every part was okay. (All of the local- storage associated packages, just like the shared_preferences, works properly in pure Flutter undertaking in each debug and launch mode, however not labored in iOS x Flutter undertaking in launch mode.)
[ad_2]