搜尋套件、儲存庫與 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());
}

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。