@@ -46,6 +46,10 @@ class CodeChunks {
46
46
/// Note: for desktop apps it is recommended to specify a unique [directory].
47
47
///
48
48
/// See [Store.new] for an explanation of all parameters.
49
+ ///
50
+ /// For Flutter apps, also calls `loadObjectBoxLibraryAndroidCompat()` from
51
+ /// the ObjectBox Flutter library to fix loading the native ObjectBox library
52
+ /// on Android 6 and older.
49
53
${openStore (model , pubspec )}
50
54
51
55
/// Returns the ObjectBox model definition for this project for use with
@@ -63,6 +67,11 @@ class CodeChunks {
63
67
${model .entities .mapIndexed (_metaClass ).join ("\n " )}
64
68
""" ;
65
69
70
+ /// Builds openStore method code string wrapping the [Store] constructor.
71
+ ///
72
+ /// If the ObjectBox Flutter dependency is detected in [pubspec] , will
73
+ /// add its compat loading for the Android library and use its default
74
+ /// directory detection. Also the method will become async.
66
75
static String openStore (ModelInfo model, Pubspec ? pubspec) {
67
76
final obxFlutter = pubspec? .hasObxFlutterDependency ?? false ;
68
77
return '''${obxFlutter ? 'Future<$obx .Store>' : '$obx .Store' } openStore(
@@ -71,15 +80,16 @@ class CodeChunks {
71
80
int? fileMode,
72
81
int? maxReaders,
73
82
bool queriesCaseSensitiveDefault = true,
74
- String? macosApplicationGroup})${obxFlutter ? ' async' : '' } =>
75
- $obx .Store(getObjectBoxModel(),
83
+ String? macosApplicationGroup})${obxFlutter ? ' async' : '' } {
84
+ ${obxFlutter ? 'await loadObjectBoxLibraryAndroidCompat();' : '' }
85
+ return $obx .Store(getObjectBoxModel(),
76
86
directory: directory${obxFlutter ? ' ?? (await defaultStoreDirectory()).path' : '' },
77
87
maxDBSizeInKB: maxDBSizeInKB,
78
88
fileMode: fileMode,
79
89
maxReaders: maxReaders,
80
90
queriesCaseSensitiveDefault: queriesCaseSensitiveDefault,
81
91
macosApplicationGroup: macosApplicationGroup);
82
- ''' ;
92
+ } ''' ;
83
93
}
84
94
85
95
static List <T > sorted <T >(List <T > list) {
0 commit comments