merlinofcha0s / generator-jhipster-flutter

A Flutter module for JHipster. It will generate mobile app (iOS, Android) with Flutter
https://cyril-casaucau.medium.com/get-started-with-the-flutter-generator-for-jhipster-11ed2b1f038d
54 stars 23 forks source link

Issues from test run #50

Open mraible opened 3 years ago

mraible commented 3 years ago

I installed this module tonight and tried to create an app and run it. First of all, am I supposed to run yo jhipster-flutter-merlin in a directory next to my JHipster app, or inside my JHipster app?

I'm using Java 8 because I got a NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema when I tried to use Java 11.

$ java -version
openjdk version "1.8.0_242"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_242-b08)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.242-b08, mixed mode)

I tried to create flutter-app next to my JHipster app. After I created the app, I tried to run it with flutter run on Chrome. The error I received:

$ flutter run
Multiple devices found:
Android SDK built for x86 (mobile) • emulator-5554                        • android-x86    • Android 10 (API 29)
(emulator)
iPhone 11 (mobile)                 • 53F2EA71-5273-40B7-8CCA-329E12B0D3E4 • ios            •
com.apple.CoreSimulator.SimRuntime.iOS-14-4 (simulator)
Chrome (web)                       • chrome                               • web-javascript • Google Chrome 89.0.4389.82
[1]: Android SDK built for x86 (emulator-5554)
[2]: iPhone 11 (53F2EA71-5273-40B7-8CCA-329E12B0D3E4)
[3]: Chrome (chrome)
Please choose one (To quit, press "q/Q"): 3

Launching lib/main.dart on Chrome in debug mode...
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:flutter_bloc
 - package:dart_json_mapper
 - package:bloc
 - package:provider
 - package:formz

For solutions, see https://dart.dev/go/unsound-null-safety
Unhandled exception:
Bad state: Unsupported Null Safety mode NonNullableByDefaultCompiledMode.Invalid, in null.
#0      ProgramCompiler.emitModule (package:dev_compiler/src/kernel/compiler.dart:435:9)
#1      JavaScriptBundler.compile (package:frontend_server/src/javascript_bundle.dart:144:33)
#2      FrontendCompiler.writeJavascriptBundle (package:frontend_server/frontend_server.dart:632:20)
<asynchronous suspension>
#3      FrontendCompiler.compile (package:frontend_server/frontend_server.dart:545:9)
<asynchronous suspension>
#4      listenAndCompile.<anonymous closure> (package:frontend_server/frontend_server.dart:1105:11)
<asynchronous suspension>
the Dart compiler exited unexpectedly.
Waiting for connection from debug service on Chrome...              7.2s
Failed to compile application.

Then, I tried Android. That fails too. I must be doing something wrong.

[1]: Android SDK built for x86 (emulator-5554)
[2]: iPhone 11 (53F2EA71-5273-40B7-8CCA-329E12B0D3E4)
[3]: Chrome (chrome)
Please choose one (To quit, press "q/Q"): 1

Using hardware rendering with device Android SDK built for x86. If you notice graphics artifacts, consider enabling
software rendering with "--enable-software-rendering".
Launching lib/main.dart on Android SDK built for x86 in debug mode...
Error: Cannot run with sound null safety, because the following dependencies
don't support null safety:

 - package:flutter_bloc
 - package:dart_json_mapper
 - package:bloc
 - package:provider
 - package:formz

For solutions, see https://dart.dev/go/unsound-null-safety

FAILURE: Build failed with an exception.

* Where:
Script '/usr/local/Caskroom/flutter/1.22.4/flutter/packages/flutter_tools/gradle/flutter.gradle' line: 991

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command '/usr/local/Caskroom/flutter/1.22.4/flutter/bin/flutter'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2m 19s
Running Gradle task 'assembleDebug'...
Running Gradle task 'assembleDebug'... Done                       140.3s
Exception: Gradle task assembleDebug failed with exit code 1

FWIW, here's the backend I created with JHipster 7 main branch.

/*
 * 21-Points (https://github.com/mraible/21-points) as a WebFlux + React app
 */

application {
  config {
    applicationType monolith
    reactive true
    baseName HealthPoints
    packageName com.okta.developer
    authenticationType oauth2
    prodDatabaseType postgresql
    buildTool gradle
    testFrameworks [cypress]
    clientFramework react
    enableTranslation true
    nativeLanguage en
    languages [en, es]
  }
  entities Points, BloodPressure, Weight, Preferences
}

// JDL definition for application 'TwentyOnePoints' generated with command 'jhipster export-jdl'

entity BloodPressure {
  timestamp ZonedDateTime required,
  systolic Integer required,
  diastolic Integer required
}
entity Weight {
  timestamp ZonedDateTime required,
  weight Double required
}
entity Points {
  date LocalDate required,
  exercise Integer,
  meals Integer,
  alcohol Integer,
  notes String maxlength(140)
}
entity Preferences {
  weeklyGoal Integer required min(10) max(21),
  weightUnits Units required
}

enum Units {
  KG,
  LB
}

relationship OneToOne {
  Preferences{user(login)} to User
}
relationship ManyToOne {
  BloodPressure{user(login)} to User,
  Weight{user(login)} to User,
  Points{user(login)} to User
}

paginate BloodPressure, Weight with infinite-scroll
paginate Points with pagination

I'm guessing you don't support OIDC auth yet since there are open issues for Keycloak and Okta. If it helps to create bug bounties for these, I'd be happy to do that.

If I generate a reactive app with JWT for auth, should it work?

merlinofcha0s commented 3 years ago

Hi,

Sorry for the late answer.

Yes, you are supposed to launch yo jhipster-flutter-merlin in your generated jhipster project.

Normally you are supposed to use the java version linked with the Android SDK that you downloaded. I'm not sure that it will work with regular JDK but not 100% sure (see screen capture below).

image

For your last problem, You have either to use the generated launcher present in the run configuration (.idea) it's because all the libraries are not ready for null safety so you have to add --no-sound-null-safety with your flutter run : flutter run --no-sound-null-safety.

Sure, for the bug bounties, it will be awesome !

And yes it will work with JWT reactive or not.

Tell me if something wasn't clear enough.

mraible commented 2 years ago

I tried this again tonight with my jhipster7-demo app that uses JHipster v7.0.1 and JWT for auth.

When I run flutter run --no-sound-null-safety, I get the following error:

    ** BUILD FAILED **

Xcode's output:
↳
    lib/main.dart:4:8: Error: Error when reading 'lib/main.mapper.g.dart': No such file or directory
    import 'main.mapper.g.dart' show initializeJsonMapper;
           ^
    lib/main.dart:9:3: Error: Method not found: 'initializeJsonMapper'.
      initializeJsonMapper();
      ^^^^^^^^^^^^^^^^^^^^
    Failed to package /Users/mraible/dev/jhipster7-demo/flutter-app.

You can see the code for this in https://github.com/mraible/jhipster7-demo/pull/7, or by cloning the repo/branch:

git clone -b flutter https://github.com/mraible/jhipster7-demo
Djamdev commented 2 years ago

I tried this again tonight with my jhipster7-demo app that uses JHipster v7.0.1 and JWT for auth.

When I run flutter run --no-sound-null-safety, I get the following error:

    ** BUILD FAILED **

Xcode's output:
↳
    lib/main.dart:4:8: Error: Error when reading 'lib/main.mapper.g.dart': No such file or directory
    import 'main.mapper.g.dart' show initializeJsonMapper;
           ^
    lib/main.dart:9:3: Error: Method not found: 'initializeJsonMapper'.
      initializeJsonMapper();
      ^^^^^^^^^^^^^^^^^^^^
    Failed to package /Users/mraible/dev/jhipster7-demo/flutter-app.

You can see the code for this in mraible/jhipster7-demo#7, or by cloning the repo/branch:

git clone -b flutter https://github.com/mraible/jhipster7-demo

You should run " flutter pub run build_runner build --delete-conflicting-outputs", this will update (or create if not exist) the file main.mapper.g.dart, that's because of dart_json_mapper_flutter lib. It is an issue of build runner that didn't display some errors! (in this case, dart version between your drat sdk and targeted by the generated code)

Also, notice that this jhipster module does not support JHipster 7, but with some workaround it will as I did for one of my projects based on JHipster 7, notice also the null safety issues with generated pubspec, here it mine after updating some libs: ` environment: sdk: ">=2.14.0 <3.0.0"

dependencies: flutter: sdk: flutter flutter_localizations: sdk: flutter cupertino_icons: ^1.0.3 http: any dart_json_mapper: ^2.1.16 dart_json_mapper_flutter: ^1.0.3 flutter_secure_storage: ^4.2.1 url_launcher: ^6.0.12 datetime_picker_formfield: ^2.0.0 introduction_screen: ^2.1.0

toggle_switch: ^1.2.0

cached_network_image: ^3.1.0

BLoC pattern related

formz: ^0.4.1 equatable: ^2.0.0 flutter_bloc: ^7.3.1

google_maps_flutter: ^2.0.11 custom_info_window: ^1.0.1 clippy_flutter: ^2.0.0-nullsafety.1

qr_flutter: ^4.0.0 glob: ^2.0.2 reflectable: ^3.0.4 intl: ^0.17.0 search_choices: ^2.0.14 video_player: ^2.2.6 firebase_core: "^1.10.0" firebase_messaging: "^11.1.0" form_builder_phone_field: ^1.0.0-beta.0

barcode_widgets: ^2.0.0 flutter_svg: maps_launcher: ^2.0.1 ...... ` Hope this could help you

mraible commented 2 years ago

I tried updating my dependencies. See https://github.com/mraible/jhipster7-demo/pull/7/commits/c9f4babfa7ddb84a4d88260b9b078f7b637ce2a9 for specific versions.

Now if I run:

flutter pub run build_runner build --delete-conflicting-outputs

It seems to succeed:

[INFO] Succeeded after 12.7s with 1 outputs (1 actions)

When I try flutter run, it seems to want to connect to Chrome. Is there something I need to do after running this command to see the app?

flutter run
Launching lib/main.dart on Chrome in debug mode...
lib/account/login/login_repository.dart:12:23: Error: A value of type 'JWTToken?' can't be returned from an async
function with return type 'Future<JWTToken>' because 'JWTToken?' is nullable and 'Future<JWTToken>' isn't.
 - 'JWTToken' is from 'package:Flickr/shared/models/jwt_token.dart' ('lib/shared/models/jwt_token.dart').
 - 'Future' is from 'dart:async'.
    return JsonMapper.deserialize<JWTToken>(authenticateRequest.body);
                      ^
lib/shared/repository/account_repository.dart:25:23: Error: A value of type 'User?' can't be returned from an async
function with return type 'Future<User>' because 'User?' is nullable and 'Future<User>' isn't.
 - 'User' is from 'package:Flickr/shared/models/user.dart' ('lib/shared/models/user.dart').
 - 'Future' is from 'dart:async'.
    return JsonMapper.deserialize<User>(saveRequest.body);
                      ^
Waiting for connection from debug service on Chrome...             17.6s
Failed to compile application.
mrtklein commented 2 years ago

I tried updating my dependencies. See mraible/jhipster7-demo@c9f4bab for specific versions.

Now if I run:

flutter pub run build_runner build --delete-conflicting-outputs

It seems to succeed:

[INFO] Succeeded after 12.7s with 1 outputs (1 actions)

When I try flutter run, it seems to want to connect to Chrome. Is there something I need to do after running this command to see the app?

flutter run
Launching lib/main.dart on Chrome in debug mode...
lib/account/login/login_repository.dart:12:23: Error: A value of type 'JWTToken?' can't be returned from an async
function with return type 'Future<JWTToken>' because 'JWTToken?' is nullable and 'Future<JWTToken>' isn't.
 - 'JWTToken' is from 'package:Flickr/shared/models/jwt_token.dart' ('lib/shared/models/jwt_token.dart').
 - 'Future' is from 'dart:async'.
    return JsonMapper.deserialize<JWTToken>(authenticateRequest.body);
                      ^
lib/shared/repository/account_repository.dart:25:23: Error: A value of type 'User?' can't be returned from an async
function with return type 'Future<User>' because 'User?' is nullable and 'Future<User>' isn't.
 - 'User' is from 'package:Flickr/shared/models/user.dart' ('lib/shared/models/user.dart').
 - 'Future' is from 'dart:async'.
    return JsonMapper.deserialize<User>(saveRequest.body);
                      ^
Waiting for connection from debug service on Chrome...             17.6s
Failed to compile application.

After solving the above error by catching null values, I get the following error:

════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by gesture ═══════════════════════════════════════════════════════════════
The following StateError was thrown while handling a gesture:
Bad state: add(TermsAndConditionsChanged) was called without a registered event handler.
Make sure to register a handler via on<TermsAndConditionsChanged>((event, emit) {...})

When the exception was thrown, this was the stack: 
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49  throw_
packages/bloc/src/bloc.dart 75:9                                                                                           <fn>
packages/bloc/src/bloc.dart 80:14                                                                                          add
packages/eyeCare/account/register/register_screen.dart 136:53                                                              <fn>
packages/flutter/src/material/toggleable.dart 229:9                                                                        [_handleTap]
packages/flutter/src/gestures/recognizer.dart 198:24                                                                       invokeCallback
packages/flutter/src/gestures/tap.dart 608:48                                                                              handleTapUp
packages/flutter/src/gestures/tap.dart 296:5                                                                               [_checkUp]
packages/flutter/src/gestures/tap.dart 230:7                                                                               handlePrimaryPointer
packages/flutter/src/gestures/recognizer.dart 563:9                                                                        handleEvent
packages/flutter/src/gestures/pointer_router.dart 94:12                                                                    [_dispatch]
packages/flutter/src/gestures/pointer_router.dart 139:9                                                                    <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/linked_hash_map.dart 21:13      forEach
packages/flutter/src/gestures/pointer_router.dart 137:17                                                                   [_dispatchEventToRoutes]
packages/flutter/src/gestures/pointer_router.dart 123:7                                                                    route
packages/flutter/src/gestures/binding.dart 439:19                                                                          handleEvent
packages/flutter/src/gestures/binding.dart 419:14                                                                          dispatchEvent
packages/flutter/src/rendering/binding.dart 322:11                                                                         dispatchEvent
packages/flutter/src/gestures/binding.dart 374:7                                                                           [_handlePointerEventImmediately]
packages/flutter/src/gestures/binding.dart 338:5                                                                           handlePointerEvent
packages/flutter/src/gestures/binding.dart 296:7                                                                           [_flushPointerEventQueue]
packages/flutter/src/gestures/binding.dart 279:32                                                                          [_handlePointerDataPacket]
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/platform_dispatcher.dart 1020:13           invoke1
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/platform_dispatcher.dart 184:5             invokeOnPointerDataPacket
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/pointer_binding.dart 130:39                [_onPointerData]
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/pointer_binding.dart 558:18                <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/pointer_binding.dart 511:21                <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/flutter_web_sdk/lib/_engine/engine/pointer_binding.dart 217:16                loggedHandler
Handler: "onTap"
Recognizer: TapGestureRecognizer#6610a
  debugOwner: GestureDetector
  state: possible
  won arena
  finalPosition: Offset(32.0, 711.0)
  finalLocalPosition: Offset(17.0, 10.9)
  button: 1
  sent tap down