-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An error FormatterException
occurred while formatting the generated source
#1739
Comments
➤ PM Bot commented: Jira ticket: RDART-1065 |
Error (Xcode): lib/app/modules/inventory/models/consignmentSchema.realm.dart:330:8: Error: Expected an identifier, but got 'switch'. Could not build the application for the simulator. |
Switch expressions should be supported - can you make sure you've updated to the current versions of dart and flutter? |
Yes, Current version is 3.22.0 , I've checked and update to 3.22.2 which is latest stable version. Still facing this issue. |
See https://dart.dev/language/branches#switch-expressions So flutter is 3.22.2, but what does |
Dart SDK version: 3.4.3 (stable) (Tue Jun 4 19:51:39 2024 +0000) on "macos_arm64" |
What is the min SDK version in your pubspec.yaml? |
environment: |
Can you you upload your |
I had the same issue today with introducing Realm to my existing project. Same latest Flutter and Dart under Windows. I had tried downgrading but it continued to error. I cleared the pubspec.lock file and had it regenerate, after that the command |
Found the issue, Switch expressions require a language version of at least 3.0, In my pubspec.yaml the environment sdk version was sdk: '>=2.19.0 <3.0.0' , because of which the switch expression was throwing the error. Changing it to sdk: '>=3.0.0 <=3.4.3' solved my issue. |
@shashankmathur8 I was confused by you earlier comment that indicated you already had valid sdk constraints. Realm has required Dart 3.0, since version 1.3, which was released roughly a year ago (see https://pub.dev/packages/realm/versions). Latest version actually requires Dart 3.3, a requirement that was introduced with realm version 2.2.0. Also, I would recommend loosing the upper bound a bit. 3.4.3 is the current stable version of Dart. Something like: environment:
sdk: '>=3.3.0 <4.0.0' |
What happened?
while running generate command for realm models in version 3.1.0. The part file is generated but got this error
[SEVERE] realm:realm_generator on lib/app/data/model/mongo_schema_model/app_logger.dart:
An error
FormatterException
occurred while formatting the generated source forpackage:slb_gt_mobile/app/data/model/mongo_schema_model/app_logger.dart
which was output to
lib/app/data/model/mongo_schema_model/app_logger.realm.dart
.This may indicate an issue in the generator, the input source code, or in the
source formatter.
Could not format because the source could not be parsed:
line 90, column 8 of .: Expected an identifier.
╷
90 │ return switch (ejson) {
│ ^^^^^^
╵
line 90, column 1 of .: Expected to find ';'.
╷
90 │ return switch (ejson) {
│ ^^^^^^
╵
line 91, column 1 of .: Expected to find 'case'.
╷
91 │ {
│ ^
╵
Repro steps
Version
3.22.0,
What Atlas Services are you using?
Atlas Device Sync
What type of application is this?
Flutter Application
Client OS and version
13.6
Code snippets
import 'package:realm/realm.dart';
part 'app_logger.realm.dart';
// NOTE: These Realm models are private and therefore should be copied into the same .dart file.
@RealmModel()
class _AppLogger {
@PrimaryKey()
@mapto('_id')
ObjectId? id;
String? alias;
String? date;
String? message;
String? origin;
String? type;
String? userTruckMappingId;
}
Stacktrace of the exception/crash you're getting
Relevant log output
No response
The text was updated successfully, but these errors were encountered: