flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
164.33k stars 27.12k forks source link

Allow using dart:indexed_db in flutter apps #44937

Closed simc closed 2 days ago

simc commented 4 years ago

The dart analyzer fails with the following message when I try to import dart:indexed_db:

Target of URI doesn't exist: 'dart:indexed_db'.
Try creating the file referenced by the URI, or Try using a URI for a file that does exist.

The package compiles without errors and can use the dart:indexed_db library just fine but the error message from the analyzer (and possible pana penalty) is still a problem.

Steps to Reproduce

import dart:indexed_db in a flutter app or package

flutter doctor -v

Flutter (Channel master, v1.11.1-pre.57, on Mac OS X 10.14.5 18F132, locale en-DE)
    • Flutter version 1.11.1-pre.57 at /Users/simon/flutter
    • Framework revision eae05c7daf (36 minutes ago), 2019-11-14 13:19:40 -0800
    • Engine revision 7d6e376d83
    • Dart version 2.7.0
iapicca commented 4 years ago

Hi @leisim thank you for your contribution (hive is the best)

simc commented 4 years ago

@goderbauer Is this more work than just "flipping a switch"? Is there something I can help with?

simc commented 4 years ago

@iapicca Anything I can help with?

PavelPZ commented 4 years ago

The same problem, how can I solve it? Using 1.13.6-pre.44

@iapicca, I cannot agree with severe: new feature or proposal flag in this issue, it seems to be an error.

This singleline .dart file in project:

import 'dart:indexed_db';

With this pubspec.yaml is everything OK:

name: test

environment:
  sdk: ^2.6.0

dependencies:

dev_dependencies:
  test: 

This pubspec.yaml shows error:

name: test

environment:
  sdk: ^2.6.0

dependencies:
  flutter:
    sdk: flutter

dev_dependencies:
  test: 

Error:

Target of URI doesn't exist: 'dart:indexed_db'.
Try creating the file referenced by the URI, or Try using a URI for a file that does exist.dart(uri_does_not_exist)
PavelPZ commented 4 years ago

Any news @iapicca? It is blocking error for me. Is any chance for fixing this or is it possible to estimate time for solution?

Try pls this:

  1. run flutter create test_app
  2. open created test_app folder in vs code
  3. in lib/main.dart file insert import 'dart:indexeddb'; into the first line (there is no problem to import other files, e.g. import 'dart:html';)
  4. after that, no running and debugging app is possible`

Thanks a lot for help.

Levi-Lesches commented 4 years ago

Is there a reason indexed_db is blocked on Flutter in the first place?

I'm trying to get some internal DB working for my Flutter app and with the mess of plugins I just want to do conditional imports and be done with it, but that seems to not be an option.

AsteriskZuo commented 3 years ago

I had the same problem, right? Does anybody know how to do that?

Levi-Lesches commented 3 years ago

I personally use package:idb_shim.

It has an API that pretty much exactly matches the indexed_db api, but has implementations for every platform. All you need to do is provide it with a different IdbFactory depending on the platform.

On mobile:

import "package:idb_shim/idb_shim.dart";
import "package:idb_shim/idb_io.dart";
import "package:path_provider/path_provider.dart";

/// Provides access to an IndexedDB implementation. 
/// 
/// The mobile implementation is based on a .json file.
Future<IdbFactory> get idbFactory async => getIdbFactoryPersistent(
    (await getApplicationDocumentsDirectory()).path
);

On web:

import "package:idb_shim/idb_shim.dart";
import "package:idb_shim/idb_browser.dart";

/// Provides access to an IndexedDB implementation. 
/// 
/// The browser has an implementation built-in. 
Future<IdbFactory> get idbFactory async => idbFactoryBrowser;

To coordinate it all, simply include these lines to import the correct IdbFactory:

import "idb_factory_stub.dart"
    if (dart.library.io) "idb_factory_io.dart"
    if (dart.library.html) "idb_factory_web.dart";

Future<Database> getDatabase async => (await idbFactory).open(/* initialization logic here */);

This approach does work once set up and, with a mobile implementation as well, may be simpler than a native indexed_db.

AsteriskZuo commented 3 years ago

ref: https://www.gitmemory.com/issue/flutter/flutter/44937/570559644

According to what is said above, the reason has been found.

Levi-Lesches commented 3 years ago

Isn't that just a link to the above comment? It just says the indexed_bd is blocked on Flutter, but not why, or if it can be put back.

JaredEzz commented 2 years ago

+1. Still hoping to use indexed_db in Flutter Web apps.

Jordan-Nelson commented 2 years ago

Is there a specific reason this isn't supported? Is this as simple as adding dart:indexed_db to the copy of the Dart SDK used for analysis as was done in https://github.com/flutter/engine/pull/12435 for dart:html, dart:js, & dart:js_util? If so, are you open to contributions?

CC: @devoncarew

tomasweigenast commented 6 months ago

Still waiting for this lol

MarcoPellicciottaOSF commented 5 months ago

Adding a comment here because since web browser supports this, all other platforms can easily support. Please provide a solution, since adding more and more packages makes the app grow in complexity. Using standard core libraries should be preferred.

jonahwilliams commented 2 days ago

indexed_db was only ever available in flutter_web applications, it does not work in flutter as we did not ship an indexed_db implementation in the engine. We have no plans to do so in the future.