skip to Main Content

I have a problem integrating payment gateway-related packages into my Flutter app. The app is targeted at two platforms: Android and Web

I am using the RevenueCat package for the Android app and Stripe for the Web. There is a service facade that hides this from the rest of the app. In the service class I am using the following conditional import.

import '../repository/dummy/dummy_purchase_repository.dart' if (dart.library.io) '../repository/revenuecat/revenue_cat_purchases.dart' if (dart.library.html) '../../repository/stripe/stripe_purchase_repository.dart';

This compiles fine for the web, but when I try to compile for Android I get the following error

Invalid depfile: D:IanDocumentsgithubgood_day.dart_toolflutter_build61995fbac7f59d1b417808c42764f11ckernel_snapshot.d
Invalid depfile: D:IanDocumentsgithubgood_day.dart_toolflutter_build61995fbac7f59d1b417808c42764f11ckernel_snapshot.d
/C:/Users/Ian/AppData/Local/Pub/Cache/hosted/pub.dev/flutter_stripe_web-5.1.0/lib/src/widgets/payment_element.dart:2:8: Error: Dart library 'dart:ui_web' is not available on this platform.
import 'dart:ui_web' as ui;
       ^
Context: The unavailable library 'dart:ui_web' is imported through these packages:

    package:good_day => package:flutter_stripe_web => package:flutter_web_plugins => dart:ui_web
    package:good_day => package:flutter_stripe_web => dart:ui_web

Any suggestions?

2

Answers


  1. Chosen as BEST ANSWER

    My mistake...

    The conditional import does work, but I had a reference to another part of the Stripe package for UI widgets that needed to be translated to use conditional imports.


  2. I could be wrong, but I think conditional imports are not possible. Using if like that should be done with exports. So what you can do is to have in your dummy_purchase_repository.dart only these lines

    export '../repository/revenuecat/revenue_cat_purchases.dart'
    if (dart.library.html) '../../repository/stripe/stripe_purchase_repository.dart';
    

    and nothing else. And wherever you want to use it just write

    import '../repository/dummy/dummy_purchase_repository.dart'
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search