Token导航 LogoToken导航TokenDH.com
前端设计需要联网github未标认证来源可访问许可证需确认审计通过

flutter-adding-home-screen-widgetsFlutter adding home screen widgets 命令行

Agent Skill

flutter-adding-home-screen-widgets 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

195,216

周安装

8,259

GitHub Stars

1,317

下载量

68,392
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:flutter-adding-home-screen-widgets(Flutter adding home screen widgets 命令行)
来源仓库:https://github.com/flutter/skills
仓库路径:skills/flutter-adding-home-screen-widgets
安装命令:
npx skills add https://github.com/flutter/skills --skill flutter-adding-home-screen-widgets
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/flutter/skills --skill flutter-adding-home-screen-widgets

简介

通过本机 UI 和共享数据同步,将主屏幕小部件添加到适用于 Android 和 iOS 的 Flutter 应用程序。

  • Flutter 使用 home_widget 通过共享本地存储(iOS 上的 UserDefaults,Android 上的 SharedPreferences)与本机小部件进行通信
  • 包装;数据流从 Flutter 写入到操作系统触发的本机小部件读取。
  • iOS 实现使用具有 App Groups 功能的 Xcode、SwiftUI 和 Widget Extension 目标; Android 使用带有 AppWidgetProvider、XML 布局和 RemoteView 的 Android Studio。
  • 支持将复杂的 Flutter 小部件渲染为图像以在本机小部件中显示,以及在 iOS 上注册自定义字体。
  • 包括 Flutter 集成、iOS SwiftUI 设置和 Android Kotlin 设置的分步清单,以及数据更新和小部件提供程序的代码示例。

SKILL.md

Implementing Flutter Home Screen Widgets

Contents

Architecture & Data Flow

Home Screen Widgets require native UI implementation (SwiftUI for iOS, XML/Kotlin for Android). The Flutter app communicates with these native widgets via shared local storage (UserDefaults on iOS, SharedPreferences on Android) using the home_widget package.

  • Data Write: Flutter app writes key-value pairs or renders images to a shared container.
  • Trigger: Flutter app signals the native OS to update the widget.
  • Data Read: Native widget wakes up, reads the key-value pairs or images from the shared container, and updates its UI.

Flutter Integration Workflow

Use this checklist to implement the Dart side of the Home Screen Widget integration.

  • Step 1: Initialize the App Group. Call HomeWidget.setAppGroupId('<YOUR_APP_GROUP>') in initState() or app startup.
  • Step 2: Save Data. Use HomeWidget.saveWidgetData<T>('key', value) to write data to shared storage.
  • Step 3: Trigger Update. Call HomeWidget.updateWidget(iOSName: 'YourIOSWidget', androidName: 'YourAndroidWidget') to notify the OS.
  • Step 4: Validate. Run Flutter build -> review console for missing plugin registrations -> fix.

iOS Implementation Workflow

If targeting iOS, implement the widget using Xcode and SwiftUI.

  • Step 1: Create Target. Open ios/Runner.xcworkspace in Xcode. Add a new Widget Extension target. Disable "Include Live Activity" and "Include Configuration Intent" unless explicitly required.
  • Step 2: Configure App Groups. Add the App Groups capability to *both* the Runner target and the Widget Extension target. Ensure the App Group ID matches the one used in Dart.
  • Step 3: Define TimelineEntry. Create a struct conforming to TimelineEntry to hold the data passed from shared storage.
  • Step 4: Implement TimelineProvider.

- In getSnapshot and getTimeline, instantiate UserDefaults(suiteName: "<YOUR_APP_GROUP>"). - Extract values using userDefaults?.string(forKey: "your_key"). - Return the populated TimelineEntry.

  • Step 5: Build UI. Implement the SwiftUI View to display the data from the TimelineEntry.
  • Step 6: Validate. Run Xcode build for the Widget Extension -> review provisioning/App Group errors -> fix.

Android Implementation Workflow

If targeting Android, implement the widget using Android Studio and XML/Kotlin.

  • Step 1: Create App Widget. Open the android folder in Android Studio. Right-click the app directory -> New -> Widget -> App Widget.
  • Step 2: Define Layout. Edit res/layout/<widget_name>.xml to define the UI using standard Android XML layouts (e.g., RelativeLayout, TextView, ImageView).
  • Step 3: Implement AppWidgetProvider.

- Open the generated Kotlin class extending AppWidgetProvider. - In the onUpdate method, retrieve shared data using HomeWidgetPlugin.getData(context). - Extract values using widgetData.getString("your_key", null). - Update the UI using RemoteViews and setTextViewText or setImageViewBitmap. - Call appWidgetManager.updateAppWidget(appWidgetId, views).

  • Step 4: Validate. Run Android build -> review Manifest registration errors -> fix.

Advanced Techniques

Rendering Flutter Widgets as Images

If the UI is too complex to recreate natively (e.g., custom charts), render the Flutter widget to an image and display the image in the native widget.

  1. Wrap the target Flutter widget with a GlobalKey.
  2. Call HomeWidget.renderFlutterWidget(), passing the widget, a filename, and the key.
  3. iOS: Read the file path from UserDefaults and render using UIImage(contentsOfFile:) inside a SwiftUI Image.
  4. Android: Read the file path from SharedPreferences, decode using BitmapFactory.decodeFile(), and render using setImageViewBitmap().

Using Custom Flutter Fonts (iOS Only)

If utilizing custom fonts defined in Flutter on iOS Home Screen Widgets:

  1. Extract the Flutter asset bundle path in Swift.
  2. Register the font using CTFontManagerRegisterFontsForURL.
  3. Apply the font in SwiftUI using Font.custom().

Examples

Example: Flutter Data Update

import 'package:home_widget/home_widget.dart';

const String appGroupId = 'group.com.example.app';
const String iOSWidgetName = 'NewsWidgets';
const String androidWidgetName = 'NewsWidget';

Future<void> updateWidgetData(String title, String description) async {
  await HomeWidget.setAppGroupId(appGroupId);
  await HomeWidget.saveWidgetData<String>('headline_title', title);
  await HomeWidget.saveWidgetData<String>('headline_description', description);
  await HomeWidget.updateWidget(
    iOSName: iOSWidgetName,
    androidName: androidWidgetName,
  );
}

Example: iOS SwiftUI Provider & View

import WidgetKit
import SwiftUI

struct NewsArticleEntry: TimelineEntry {
    let date: Date
    let title: String
    let description: String
}

struct Provider: TimelineProvider {
    func placeholder(in context: Context) -> NewsArticleEntry {
        NewsArticleEntry(date: Date(), title: "Loading...", description: "Loading...")
    }

    func getSnapshot(in context: Context, completion: @escaping (NewsArticleEntry) -> ()) {
        let userDefaults = UserDefaults(suiteName: "group.com.example.app")
        let title = userDefaults?.string(forKey: "headline_title") ?? "No Title"
        let description = userDefaults?.string(forKey: "headline_description") ?? "No Description"

        let entry = NewsArticleEntry(date: Date(), title: title, description: description)
        completion(entry)
    }

    func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> ()) {
        getSnapshot(in: context) { (entry) in
            let timeline = Timeline(entries: [entry], policy: .atEnd)
            completion(timeline)
        }
    }
}

struct NewsWidgetsEntryView : View {
    var entry: Provider.Entry

    var body: some View {
        VStack(alignment: .leading) {
            Text(entry.title).font(.headline)
            Text(entry.description).font(.subheadline)
        }
    }
}

Example: Android Kotlin Provider

package com.example.app.widgets

import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.content.Context
import android.widget.RemoteViews
import es.antonborri.home_widget.HomeWidgetPlugin
import com.example.app.R

class NewsWidget : AppWidgetProvider() {
    override fun onUpdate(
        context: Context,
        appWidgetManager: AppWidgetManager,
        appWidgetIds: IntArray,
    ) {
        for (appWidgetId in appWidgetIds) {
            val widgetData = HomeWidgetPlugin.getData(context)
            val views = RemoteViews(context.packageName, R.layout.news_widget).apply {
                val title = widgetData.getString("headline_title", "No Title")
                setTextViewText(R.id.headline_title, title)

                val description = widgetData.getString("headline_description", "No Description")
                setTextViewText(R.id.headline_description, description)
            }
            appWidgetManager.updateAppWidget(appWidgetId, views)
        }
    }
}
// Add this to your SwiftUI View struct
var bundle: URL {
    let bundle = Bundle.main
    if bundle.bundleURL.pathExtension == "appex" {
        var url = bundle.bundleURL.deletingLastPathComponent().deletingLastPathComponent()
        url.append(component: "Frameworks/App.framework/flutter_assets")
        return url
    }
    return bundle.bundleURL
}

init(entry: Provider.Entry) {
    self.entry = entry
    CTFontManagerRegisterFontsForURL(
        bundle.appending(path: "/fonts/YourCustomFont.ttf") as CFURL,
        CTFontManagerScope.process,
        nil
    )
}

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.39%
按下载量换算24,888

Claude

29.04%
按下载量换算19,861

Cursor

18.92%
按下载量换算12,940

Gemini CLI

9.91%
按下载量换算6,778

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills