GithubHelp home page GithubHelp logo

vincekruger / flutter_whatsapp_stickers Goto Github PK

View Code? Open in Web Editor NEW
38.0 7.0 29.0 1.91 MB

WhatsApp Stickers Plugin for Flutter

Home Page: https://pub.dev/packages/flutter_whatsapp_stickers

License: BSD 3-Clause "New" or "Revised" License

Java 59.81% Ruby 7.01% Swift 1.74% Objective-C 0.62% Dart 30.83%
flutter flutter-plugin whatsapp-stickers dart

flutter_whatsapp_stickers's Introduction

WhatsApp Stickers plugin for Flutter

pub package

Note: This plugin is still under development and for now, only Android is supported. Feedback and Pull Requests welcome!

Getting Started

Add flutter_whatsapp_stickers as a dependency in your pubspec.yaml file.

Check out the example directory for a sample app.

Android Configuration

Add the following option to your app\build.gradle file. This will prevent all WebP files from being compressed.

android {
    aaptOptions {
        noCompress "webp"
    }
}

Packaged Assess

You need to include your assets in your pubspec.yaml file.

flutter:
  assets:
    - sticker_packs/sticker_packs.json
    - sticker_packs/1/

Dynamic Content

If you are using assets that are not bundled in your build, then you need to add the following to your Manifest file. Note that you cannot use both.

<meta-data android:name="NonAssetContentProvider" android:value="true" />

Sticker Pack Contents File

To change the stickers packs file, add this Build Config Field to your app\build.gradle file. The default is sticker_packs.json.

buildConfigField("String", "STICKER_PACK_FILE", "\"sticker_packs.json\"")

iOS Integration

Currently, there is no iOS support. Pull requests for this are more than welcome for this.

Methods

Check if WhatsApp is installed.

bool whatsAppInstalled = await WhatsAppStickers.isWhatsAppInstalled;

Check if the WhatsApp Consumer package is installed

bool whatsAppConsumerAppInstalled = await WhatsAppStickers.isWhatsAppConsumerAppInstalled;

Check if the WhatsApp Business package app is installed

bool whatsAppSmbAppInstalled = await WhatsAppStickers.isWhatsAppSmbAppInstalled;

Check if a sticker pack is installed.

_stickerPackInstalled = await WhatsAppStickers().isStickerPackInstalled(_stickerPackIdentifier);

Add a sticker pack to WhatsApp.

WhatsAppStickers().addStickerPack(
  packageName: WhatsAppPackage.Consumer,
  stickerPackIdentifier: _stickerPackIdentifier,
  stickerPackName: _stickerPackName,
  listener: _listener,
);

Updated Sticker Pack contents and notify listeners

WhatsAppStickers().updatedStickerPacks(_stickerPackIdentifier);

The Add Sticker Pack Listener

Future<void> _listener(StickerPackResult action, bool result, {String error}) async {
    // Do what you must here
}

Here is an example of how to create a custom stickers_packs.json file.

void createLocalFile() async {
  String dir = (await getApplicationDocumentsDirectory()).path;
  Directory stickersDirectory = Directory("$dir/sticker_packs");
  if (!await stickersDirectory.exists()) {
    await stickersDirectory.create();
  }

  File jsonFile = File('$dir/sticker_packs/sticker_packs.json');
  String content = jsonEncode(stickerPacks);
  jsonFile.writeAsStringSync(content);
}

flutter_whatsapp_stickers's People

Contributors

anmolsethi avatar swapkumbhar31 avatar vincekruger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter_whatsapp_stickers's Issues

Null Safety

Can we please have null-safe version of this package?

i trying use dynamic with firebase Storage

hi,
I'm trying to add custom stickers from FirebaseStorage. I've been trying for several days. I wish someone can help me or any idea.
I check the WhatsApp stickers docs and app requirements. i don't see my issue at the moment.
Someone did try it?

Some code

int id = 1;

  InterstitialAd? myInterstitialAd;

  @override
  void onInit() {
    super.onInit();
    loadAd(); //some ads of the app
    prepareDirectory();
    checkInstallStatus();
    checkWhatsapp();
  }

  String _platformVersion = 'Unknown';
  bool _whatsAppInstalled = false;
  bool _whatsAppConsumerAppInstalled = false;
  bool _whatsAppSmbAppInstalled = false;

  Future<void> checkWhatsapp() async {
    String platformVersion;

    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await WhatsAppStickers.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    bool whatsAppInstalled = await WhatsAppStickers.isWhatsAppInstalled;
    bool whatsAppConsumerAppInstalled =
        await WhatsAppStickers.isWhatsAppConsumerAppInstalled;
    bool whatsAppSmbAppInstalled =
        await WhatsAppStickers.isWhatsAppSmbAppInstalled;

    _platformVersion = platformVersion;
    _whatsAppInstalled = whatsAppInstalled;
    _whatsAppConsumerAppInstalled = whatsAppConsumerAppInstalled;
    _whatsAppSmbAppInstalled = whatsAppSmbAppInstalled;

    print(_platformVersion);
    print(_whatsAppInstalled);
    print(_whatsAppConsumerAppInstalled);
    print(_whatsAppSmbAppInstalled);
  }

  Map<String, dynamic> jsonFilePack(List<Sticker> stickers) {
    return {
      "identifier": "$id",
      "name": "Chiringuito-Stickers-$id",
      "publisher": "Chiringuitostickers App",
      "tray_image_file": "tray-icon.png",
      "image_data_version": "1",
      "avoid_cache": false,
      "publisher_email": "",
      "publisher_website": "https://chiringuitostickers.com/",
      "privacy_policy_website":
          "https://coronayuda.blogspot.com/p/politica-de-privacidad.html",
      "license_agreement_website":
          "https://github.com/vincekruger/flutter_whatsapp_stickers",
      "stickers": List.generate(stickers.length, (index) {
        return {
          "image_file": "${stickers[index].id}.webp",
          "emojis": stickers[index].emojis
        };
      })
    };
  }

  final WhatsAppStickers _waStickers = WhatsAppStickers();

  Directory? _applicationDirectory;
  Directory? _stickerPacksDirectory;
  File? _stickerPacksConfigFile;

  Map<String, dynamic>? _stickerPacksConfig;
  List<dynamic>? _storedStickerPacks;

  bool packInstalled = false;

  prepareDirectory() async {
    _applicationDirectory = await getApplicationDocumentsDirectory();
    //Creamos las carpeta necesaria
    _stickerPacksDirectory =
        Directory("${_applicationDirectory?.path}/sticker_packs");
    _stickerPacksConfigFile =
        File("${_stickerPacksDirectory?.path}/sticker_packs.json");
    _stickerPacksConfigFile!.deleteSync();

    //Creamos el archivo de configuracion si no existe
    if (!await _stickerPacksConfigFile!.exists()) {
      _stickerPacksConfigFile!.createSync(recursive: true);
      _stickerPacksConfig = {
        "android_play_store_link": "",
        "ios_app_store_link": "",
        "sticker_packs": [],
      };
      String contentsOfFile = jsonEncode(_stickerPacksConfig) + "\n";
      _stickerPacksConfigFile!.writeAsStringSync(contentsOfFile, flush: true);
    }

    //Cargamos los packs de configuracion

    _stickerPacksConfig =
        jsonDecode((await _stickerPacksConfigFile!.readAsString()));
    _storedStickerPacks = _stickerPacksConfig!['sticker_packs'];
  }

  checkInstallStatus() async {
    packInstalled = await _waStickers.isStickerPackInstalled(id.toString());
    if (packInstalled) {
      id = id++;
    }
  }

  Future<bool> downloadSticker(List<Sticker> _stickers) async {
    Directory? packageDirectory =
        Directory('${_stickerPacksDirectory!.path}/' + id.toString())
          ..createSync(recursive: true);

    for (var _sticker in _stickers) {
      File file = File(packageDirectory.path + '/' + _sticker.id + '.webp')
        ..createSync(recursive: true);

      await FirebaseStorage.instance.ref(_sticker.id).writeToFile(file);

      print(file.path);
    }

    //añadimos el tray-image
    final byteData = await rootBundle.load('images/trayImage.png');
    List<int> bytes = Uint8List.view(
        byteData.buffer, byteData.offsetInBytes, byteData.lengthInBytes);
    File('${packageDirectory.path}/tray-icon.png')
      ..createSync(recursive: true)
      ..writeAsBytesSync(bytes);

    print(packageDirectory.listSync());

    Map<String, dynamic> packageContentsMap = jsonFilePack(_stickers);

    _storedStickerPacks!.removeWhere(
        (item) => item['identifier'] == packageContentsMap['identifier']);
    _storedStickerPacks!.add(packageContentsMap);

    //Añadimos a la configuracion y actualizamos
    _stickerPacksConfig!['sticker_packs'] = _storedStickerPacks;
    JsonEncoder encoder = new JsonEncoder.withIndent('  ');
    String contentsOfFile = encoder.convert(_stickerPacksConfig) + "\n";
    _stickerPacksConfigFile!.deleteSync();
    _stickerPacksConfigFile!.createSync(recursive: true);
    _stickerPacksConfigFile!.writeAsStringSync(contentsOfFile, flush: true);

    print(_stickerPacksConfig);
    _waStickers.updatedStickerPacks(id.toString());
    return true;
  }

  addPack(List<Sticker> _stickers) async {
    Get.dialog(AlertDialog(
      title: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: CircularProgressIndicator(),
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Text('Descargando espere...'),
          )
        ],
      ),
    ));

    bool sucess = await downloadSticker(_stickers);

    if (sucess) {
      _waStickers.addStickerPack(
          stickerPackIdentifier: id.toString(),
          stickerPackName: 'Chiringuito Stickers App',
          listener: _listener);
    }
  }

  Future<void> _listener(StickerPackResult action, bool result,
      {String? error}) async {
    print(error);
    print(action);
    print(result);
    Get.back();
    if (action == StickerPackResult.ADD_SUCCESSFUL) {
      print('succesful');
    }
  }

Any advice?
Thanks you so much.

although I have installed the new version, the message: Pack is not marked as animated pack but contains animated stickers still appears.

Hi! Congratulations on your efforts to this project.
Right now I have a doubt. There are any special configuration to use animated stickers?
I try to add one animated sticker using the default project, replacing one of the default images with other of my animateds images, but the error: "pack is not marked as animated pack but contains animated stickers." keeps appearing.

The Whatsapp testing version is 2.21.16.20
I using the ^1.0.1+5 version of flutter_whatsapp_stickers

Thank you!

Support for dynamically generated sticker packs.

Hello there. I have a little issue with my use case and it a show stopper 😅.

I am dynamically generating stickers on the fly and saving it as expected to STICKER_PACK_FILE and also following the laid out folder structure by WhatsApp

WhatsAppStickers().addStickerPack(
  packageName: WhatsAppPackage.Consumer,
  stickerPackIdentifier: _stickerPackIdentifier,
  stickerPackName: _stickerPackName,
  listener: _listener,
);

The above snippet won't work after I have generated the sticker files. But when I restart the app and try it again, It will add the previous dynamically generated sticker pack to WhatsApp.

https://stackoverflow.com/questions/18294401/contentprovider-and-listview-data-not-updating-after-content-changes

When underlying data changes, the data provided to your ListView by your ContentProvider won't automatically just update. You need to notify the application-wide ContentResolver that data for one of your registered contentProviders has changed.

I also find this link helpful.
WhatsApp/stickers#291

How will I go about doing this?

Eager for a response,
Thanks.

please upgrade the android embedding

your code is working well, but when i'm running the software it tells me that the pluggin used deprecated version of android embedding.. please upgrade it

Serious plugin fix

Ohh am sorry for the trouble sir. But this is my problem sir.. I really love your plugin am a fan.. I just don't know how to use it in a real life situation.. So am getting the stickers I want to use from my firebase and I want to upload unto my whatsapp like you have done.. But with your plugin you are using only images in the assets folder.. (which is not what I want to do cause I am downloading them). And since am doing that. The sticker.json file also needs to be changing each time a new sticker is uploaded or new sticker pack is created. I also think it would be nice to be able to check the number of stickers in each pack so that when the limit of 30 is reach a new pack can be made and a new json file also(I believe that is what the application "Sticker Maker" does ) .. Thank you sir.. Really hope you can help me solve this issue..

Custom Package Not Supported

The plugin doesn't support modded versions of whatsapp.
It will be better if you add support to add custom whatsapp package names

Problem adding sticker pack to Whatsapp

Hello fellow developers,

I have been having a challenge using this plugin to add stickers to WhatsApp. The Android version on the WhatsApp GitHub repository is working fine with the same files.

Error:
There's a problem with this sticker pack and it can't be added to WhatsApp

The plugin uses a deprecated version of the Android embedding

Error when running app:
The plugin flutter_whatsapp_stickers uses a deprecated version of the Android embedding.
To avoid unexpected runtime failures, or future build failures, try to see if this plugin supports the Android V2 embedding. Otherwise, consider removing it since a future release of Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

Issue while using this plugin

Just me an example how can use this plugin in a simple flutter app where i can show the stickers in listtile formate and if the user click button to add sticker then it automatically get added to its whats app ,

sticker pack invocke method is not working and crashing the app

Unhandled Exception: MissingPluginException(No implementation found for method isStickerPackInstalled on channel io.github.vincekruger/whatsapp_stickers)
E/flutter (25309): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157:7)
E/flutter (25309):
E/flutter (25309): #1 WhatsAppStickers.isStickerPackInstalled (package:whatsapp_status_story_saver/model/flutter_whatsapp_stickers.dart:65:25)
E/flutter (25309):
E/flutter (25309): #2 _Page5State._checkInstallationStatuses (package:whatsapp_status_story_saver/pages/page5.dart:122:26)
E/flutter (25309):
E/flutter (25309):
W

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.