Skip to content
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

Flutter - ObjectBox - All data removed #700

Open
2 tasks done
EmixamZ opened this issue Dec 20, 2024 · 3 comments
Open
2 tasks done

Flutter - ObjectBox - All data removed #700

EmixamZ opened this issue Dec 20, 2024 · 3 comments
Labels
more info required Needs more info to become actionable. Auto-closed if no response.

Comments

@EmixamZ
Copy link

EmixamZ commented Dec 20, 2024

Is there an existing issue?

Build info

  • objectbox version: 4.0.2
  • Flutter/Dart version:
    Flutter 3.24.5 • channel stable • https://github.com/flutter/flutter.git
    Framework • revision dec2ee5c1f (5 weeks ago) • 2024-11-13 11:13:06 -0800
    Engine • revision a18df97ca5
    Tools • Dart 3.5.4 • DevTools 2.37.3
  • Build OS: macOS 15.2

Steps to reproduce

  1. Initialize ObjectBox and store data
  2. Execute : flutter build apk --release; flutter install
  3. Close the app
  4. Re-execute step 2
  5. Empty storage

Expected behavior

Data should be persisted.

Actual behavior

Data are not persisted

Code

Code
import 'package:flutter_riverpod/flutter_riverpod.dart';
// ignore: depend_on_referenced_packages
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
import 'package:appName/objectbox.g.dart';

class ObjectBox {
  /// The Store of this app.
  late final Store store;

  ObjectBox._create(this.store) {
    // Add any additional setup code, e.g. build queries.
  }

  /// Create an instance of ObjectBox to use throughout the app.
  static Future<ObjectBox> create() async {
    final docsDir = await getApplicationSupportDirectory();
    // Future<Store> openStore() {...} is defined in the generated objectbox.g.dart
    final store = await openStore(directory: p.join(docsDir.path, "appName"));
    return ObjectBox._create(store);
  }
}

final objectBoxProvider =
    Provider<ObjectBox>((ref) => throw UnimplementedError());

/// ... Into main

var o = await ObjectBox.create();
  runApp(
    ProviderScope(
      overrides: [objectBoxProvider.overrideWithValue(o)],
      child: App(),
    ),
  );

Notes

Somehow I might be related to the folder where the app is installed. It looks like object box database is stored under the container/{containerId} folder which changes everytime.

@EmixamZ EmixamZ added the bug Something isn't working label Dec 20, 2024
@greenrobot-team
Copy link
Member

Are you saying that getApplicationSupportDirectory or getApplicationDocumentsDirectory change every time your app runs? Then this is a Flutter bug, not an ObjectBox issue.

Note that these folders get removed when uninstalling an app on Android.

If you have more details on why this is an ObjectBox issue, please comment.

Note: I labeled this issue with "more info required" so it will auto-close in a few days if there are no follow-up comments.

@greenrobot-team greenrobot-team added more info required Needs more info to become actionable. Auto-closed if no response. and removed bug Something isn't working labels Jan 13, 2025
@EmixamZ
Copy link
Author

EmixamZ commented Jan 13, 2025

Hey,

I think it might be a little of both, since the documentation from objectBox is using the exact same function : https://docs.objectbox.io/getting-started#create-a-store.

@github-actions github-actions bot removed the more info required Needs more info to become actionable. Auto-closed if no response. label Jan 14, 2025
@greenrobot-team
Copy link
Member

How so? The ObjectBox docs use getApplicationDocumentsDirectory, which is preserved on app upgrades on Android.

Note: I labeled this issue with "more info required" so it will auto-close in a few days if there are no follow-up comments.

@greenrobot-team greenrobot-team added the more info required Needs more info to become actionable. Auto-closed if no response. label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
more info required Needs more info to become actionable. Auto-closed if no response.
Projects
None yet
Development

No branches or pull requests

2 participants