搜索插件、代码仓与 APP 分类

插件详情v0.3.3

telegram_web_app

Telegram 网页/小程序 API 的表示和实现

Web
近 30 天下载
4940
喜欢数
67
Pub 分数
150

安装插件

flutter pub add telegram_web_app

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,提供 Telegram Web App 和 Mini Apps API 的表示和实现,可无缝集成到 Telegram 的基于网络的应用程序中。它使开发者能够访问 Telegram 特有的功能,如用户数据、主题设置和深度链接,适用于 Flutter 网页应用。该包专为网页环境设计,通过 Dart 接口支持 Telegram Mini App 的全部功能。

适合场景

  • 将 Flutter Web 应用与 Telegram 集成
  • 构建 Telegram 小程序
  • 访问 Telegram 用户和主题数据
  • 在 Telegram 中启用深度链接
  • 在 Telegram 中创建交互式网络体验

主要特点

  • Telegram Web App API 绑定
  • 主题和用户数据访问
  • 深度链接支持
  • 仅限网络平台
  • 简单的 Dart 接口

适合对象

  • Flutter 开发人员构建 Telegram 小程序
  • 面向Telegram用户的Web应用开发者
  • 需要 Telegram 特定集成的应用程序

使用建议

  • 仅限网页平台
  • 需要 Telegram 环境
  • 不支持移动或桌面端
  • 依赖 Telegram 网页应用上下文
  • 不适用于独立的Web应用程序

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Telegram Web App

telegram_web_app version

Build telegram web apps in flutter using telegram_web_app library

Getting Started

  1. Import Library in your pubspec.yaml
  2. And add this line in web/index.html
<head>
    <script src="https://telegram.org/js/telegram-web-app.js" defer=""></script>
</head>

Checkout details of available telegram_web apis here You can also find detailed examples in example project.

Setup for development

  1. Enable debugging in telegram web app. Checkout this post for more details
  2. Then navigate to \example folder
  3. Deploy the example app via firebase or any other hosting service. You can find firebase hosting documentation here
  4. Create web app in telegram
  5. Use the website url to load the webapp in telegram
  6. You can also inspect the app with Javascript logs via debugging as described here
  7. For more info and support, you can join telegram group flutter_telegram

Here is an article on how to deploy web to Firebase and link to Telegram web app 👉 Telegram Mini Apps

How to use

There is a class TelegramWebApp which contains all the telegram web apis. You can call the methods via TelegramWebApp.instance You can also mock TelegramWebApp by extending it if you are trying to test outside telegram platform. Alternatively, TelegramWebAppFake object can also be used for the same purpose.

Example
// current telegram version
Text(TelegramWebApp.instance.version)

// telegram colors associated with the user's app
Text(TelegramWebApp.instance.themeParams)

// Object containing user details and user validation hash
Text(TelegramWebApp.instance.initData.toString())

You can find full list of api examples in example folder. Please feel free to contribute for improvements and any updates.

Note
  1. All the apis are only available inside telegram web app. You can't use the apis outside the platform.

  2. In Android, Web App is sometimes not loading (only grey/white screen showing up). If this happens to you, there is a 'hacky' workaround. You can also find it in example app:

void main() async {
  try {
    if (TelegramWebApp.instance.isSupported) {
      TelegramWebApp.instance.ready();
      Future.delayed(const Duration(seconds: 1), TelegramWebApp.instance.expand);
    }
  } catch (e) {
    print("Error happened in Flutter while loading Telegram $e");
    // add delay for 'Telegram seldom not loading' bug
    await Future.delayed(const Duration(milliseconds: 200));
    main();
    return;
  }

  FlutterError.onError = (details) {
    print("Flutter error happened: $details");
  };

  runApp(const MyApp());
}

所属分类

源码仓库

使用此插件的项目

暂无相关数据。