diff --git a/example/pubspec.lock b/example/pubspec.lock index caf3e20..0bc43c4 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -124,7 +124,7 @@ packages: path: ".." relative: true source: path - version: "8.0.0-pre-1" + version: "8.0.2" glob: dependency: transitive description: @@ -193,18 +193,18 @@ packages: dependency: transitive description: name: material_color_utilities - sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41" + sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a" url: "https://pub.dev" source: hosted - version: "0.5.0" + version: "0.8.0" meta: dependency: transitive description: name: meta - sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e + sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136" url: "https://pub.dev" source: hosted - version: "1.10.0" + version: "1.12.0" mime: dependency: transitive description: @@ -402,14 +402,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" - web: - dependency: transitive - description: - name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 - url: "https://pub.dev" - source: hosted - version: "0.3.0" web_socket_channel: dependency: transitive description: @@ -435,4 +427,4 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.2.0-194.0.dev <4.0.0" + dart: ">=3.3.0-0 <4.0.0" diff --git a/example/windows/flutter/CMakeLists.txt b/example/windows/flutter/CMakeLists.txt index 930d207..903f489 100644 --- a/example/windows/flutter/CMakeLists.txt +++ b/example/windows/flutter/CMakeLists.txt @@ -10,6 +10,11 @@ include(${EPHEMERAL_DIR}/generated_config.cmake) # https://github.com/flutter/flutter/issues/57146. set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") +# Set fallback configurations for older versions of the flutter tool. +if (NOT DEFINED FLUTTER_TARGET_PLATFORM) + set(FLUTTER_TARGET_PLATFORM "windows-x64") +endif() + # === Flutter Library === set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") @@ -92,7 +97,7 @@ add_custom_command( COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" - windows-x64 $ + ${FLUTTER_TARGET_PLATFORM} $ VERBATIM ) add_custom_target(flutter_assemble DEPENDS diff --git a/example/windows/runner/flutter_window.cpp b/example/windows/runner/flutter_window.cpp index b25e363..955ee30 100644 --- a/example/windows/runner/flutter_window.cpp +++ b/example/windows/runner/flutter_window.cpp @@ -31,6 +31,11 @@ bool FlutterWindow::OnCreate() { this->Show(); }); + // Flutter can complete the first frame before the "show window" callback is + // registered. The following call ensures a frame is pending to ensure the + // window is shown. It is a no-op if the first frame hasn't completed yet. + flutter_controller_->ForceRedraw(); + return true; } diff --git a/test/async_test.dart b/test/async_test.dart index d15963d..a25b28d 100644 --- a/test/async_test.dart +++ b/test/async_test.dart @@ -19,11 +19,13 @@ class TestClassParam { class TestClass extends TestBaseClass { GetIt? getIt; bool initCompleted = false; + int initMsDelay; /// if we do the initialisation from inside the constructor the init function has to signal GetIt /// that it has finished. For that we need to pass in the completer that we got from the factory call /// that we set up in the registration. - TestClass({required bool internalCompletion, this.getIt}) { + TestClass( + {required bool internalCompletion, this.initMsDelay = 10, this.getIt}) { constructorCounter++; if (internalCompletion) { assert(getIt != null); @@ -33,7 +35,7 @@ class TestClass extends TestBaseClass { /// This one signals after a delay Future initWithSignal() { - return Future.delayed(const Duration(milliseconds: 10)).then((_) { + return Future.delayed(Duration(milliseconds: initMsDelay)).then((_) { getIt!.signalReady(this); initCompleted = true; }); @@ -41,13 +43,13 @@ class TestClass extends TestBaseClass { // We use this as dummy init that will return a future Future init() async { - await Future.delayed(const Duration(milliseconds: 10)); + await Future.delayed(Duration(milliseconds: initMsDelay)); initCompleted = true; return this; } Future initWithExeption() async { - await Future.delayed(const Duration(milliseconds: 10)); + await Future.delayed(Duration(milliseconds: initMsDelay)); throw StateError('Intentional'); } @@ -73,6 +75,7 @@ class TestClassWillSignalReady2 extends TestClass implements WillSignalReady { class TestClass2 extends TestClass { TestClass2({ required super.internalCompletion, + super.initMsDelay = 10, super.getIt, }); } @@ -346,29 +349,45 @@ void main() { }); test('ready automatic signalling for async Singletons', () async { - final getIt = GetIt.instance; - getIt.reset(); + try { + final getIt = GetIt.instance; + await getIt.reset(); - getIt.registerSingletonAsync( - () async => TestClass(internalCompletion: false).init(), - ); - getIt.registerSingletonAsync( - () async { - final instance = TestClass2(internalCompletion: false); - await instance.init(); - return instance; - }, - ); - getIt.registerSingletonAsync( - () async => TestClass2(internalCompletion: false)..init(), - instanceName: 'Second Instance', - ); - expect(getIt.allReady(), completes); + getIt.registerSingletonAsync( + () async => TestClass(internalCompletion: false).init(), + ); + getIt.registerSingletonAsync( + () async { + final instance = + TestClass2(internalCompletion: false, initMsDelay: 50); + await instance.init(); + return instance; + }, + ); + getIt.registerSingletonAsync( + () async => TestClass2(internalCompletion: false).init(), + instanceName: 'Second Instance', + ); + + expect(getIt.isReadySync(), false); + expect(getIt.isReadySync(), false); + expect( + getIt.isReadySync(instanceName: 'Second Instance'), false); + + await getIt.allReady(); + + expect(getIt.isReadySync(), true); + expect(getIt.isReadySync(), true); + expect( + getIt.isReadySync(instanceName: 'Second Instance'), true); + } on Exception catch (e) { + print(e); + } }); test('isReady propagates Error', () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); getIt.registerSingletonAsync( () async => TestClass(internalCompletion: false).initWithExeption(), @@ -379,7 +398,7 @@ void main() { test('allReady propagades Exceptions that occur in the factory functions', () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); getIt.registerSingletonAsync( () async => TestClass(internalCompletion: false).init(), @@ -400,7 +419,7 @@ void main() { }); test('ready manual synchronisation of sequence', () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); errorCounter = 0; var flag1 = false; var flag2 = false; @@ -659,7 +678,7 @@ void main() { test('asyncFactory called with getAsync', () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); getIt.registerFactoryAsync( () => Future.value(TestClass(internalCompletion: false)), @@ -754,9 +773,9 @@ void main() { expect(instance2.param2, null); }); - test('register factory with Params with wrong type', () { + test('register factory with Params with wrong type', () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); constructorCounter = 0; getIt.registerFactoryParamAsync( @@ -770,9 +789,9 @@ void main() { }); test('register factory with Params with non-nullable type but not pass it', - () { + () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); constructorCounter = 0; getIt.registerFactoryParamAsync( @@ -787,7 +806,7 @@ void main() { test('asyncFactory called with get instead of getAsync', () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); getIt.registerFactoryAsync( () => Future.value(TestClass(internalCompletion: false)), @@ -801,7 +820,7 @@ void main() { test('asyncLazySingleton called with get before it was ready', () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); getIt.registerLazySingletonAsync( () => Future.value(TestClass(internalCompletion: false)), @@ -816,7 +835,7 @@ void main() { test('asyncLazySingleton called with getAsync', () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); getIt.registerLazySingletonAsync( () => Future.value(TestClass(internalCompletion: false)..init()), @@ -843,7 +862,7 @@ void main() { test('isReady called on asyncLazySingleton ', () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); getIt.registerLazySingletonAsync( () => Future.value(TestClass(internalCompletion: false)), diff --git a/test/skip_double_registration_test.dart b/test/skip_double_registration_test.dart index ed1421c..7cea02e 100644 --- a/test/skip_double_registration_test.dart +++ b/test/skip_double_registration_test.dart @@ -6,7 +6,7 @@ void main() { final getIt = GetIt.instance; getIt.allowReassignment = false; getIt.skipDoubleRegistration = false; - getIt.reset(); + await getIt.reset(); getIt.registerSingleton(MockDataStore()); expect( @@ -17,7 +17,7 @@ void main() { test(' replaces dependency safely ', () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); getIt.allowReassignment = true; getIt.skipDoubleRegistration = false; getIt.registerSingleton(MockDataStore()); @@ -28,7 +28,7 @@ void main() { test(' Ignores Double registration error ', () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); getIt.allowReassignment = false; getIt.skipDoubleRegistration = true; getIt.registerSingleton(MockDataStore()); @@ -41,7 +41,7 @@ void main() { test(' Ignores Double named registration error ', () async { final getIt = GetIt.instance; const instanceName = 'named'; - getIt.reset(); + await getIt.reset(); getIt.allowReassignment = false; getIt.skipDoubleRegistration = true; getIt.registerSingleton(RemoteDataStore()); @@ -61,7 +61,7 @@ void main() { test(' does not care about [skipDoubleRegistration] varibale ', () async { final getIt = GetIt.instance; - getIt.reset(); + await getIt.reset(); getIt.allowReassignment = true; getIt.skipDoubleRegistration = true; getIt.registerSingleton(MockDataStore());