Flutter内容聚合插件feedify的使用
Flutter内容聚合插件Feedify的使用
开始使用(Android)
在你的Firebase控制台中添加应用。你可以参考以下指南进行操作:
- 添加应用到Firebase控制台。
- 下载
google-services.json
文件。
将下载的google-services.json
文件复制到你的应用的assets目录的根目录中。这是重要的一步。
为了在我们的Android应用中启用Firebase服务,我们需要在Gradle文件中添加google-services
插件。
首先,在项目级别的Gradle文件(android/build.gradle
)中,添加规则以包含Google Services Gradle插件:
buildscript {
ext.kotlin_version = '1.8.0'
repositories {
google()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.8'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
现在,在模块级别的Gradle文件(android/app/build.gradle
)中,应用Google Services Gradle插件。为此,将以下代码片段中的高亮部分添加到项目的./android/app/build.gradle
文件中:
dependencies {
implementation platform('com.google.firebase:firebase-bom:29.0.0')
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.android.support:multidex:2.0.1'
}
apply plugin: 'com.google.gms.google-services'
然后运行以下命令,以便进行一些自动配置:
flutter pub get
使用Feedify,你还可以通过通知发送http/https URL。因此,为了支持这些URL,Android现在引入了在AndroidManifest.xml
中添加查询参数,如下所示:
<queries>
<!-- 如果你的应用打开https URL -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent>
</queries>
你可以阅读更多关于Android开发者网站上的信息。
使用(适用于Android和iOS)
void main() async {
initFeedSDK();
runApp(const MyApp());
}
void initFeedSDK() async {
WidgetsFlutterBinding.ensureInitialized();
var sdk = FeedSDK.getInstance(
feedifyKey: 'key',
feedifyDomain: 'domain',
feedifyUser: 'userKey');
// 确保所有屏幕尺寸的通知图标都可用,否则通知可能无法显示!
FeedSDK.setNotificationIcon('resource://drawable/ic_notification');
Logs.setEnabled(true);
await sdk.init(
appName: 'your app name',
projectId: 'firebase project Id',
firebaseCurrentApiKey: 'firebase api key',
firebaseMobileSdkAppId: 'firebase mobile app sdk id',
firebaseStorageBucket: 'firebase storage key url',
firebaseUrl: '',
firebaseProjectNumber: 'firebase project number',
notificationDataCallback: (p0) {
Logs.d("data notification $p0");
},
);
}
注意:上述所有信息都可以在从Google Firebase控制台下载的google-services.json
和info.plist
文件中找到。
如果传递了notificationDataCallback
,则所有数据都将发送回主调用应用,并且SDK的默认行为将被覆盖。你可以根据Constants类中的键读取数据。
如何在应用中读取通知数据?
当设置了FeedSDK.startScreen = '#any text'
时,数据会被传递到应用的根部件。然后,你可以像下面这样读取数据,这可以用于基于通知数据进行深度链接或导航:
void initFeedSDK() async {
WidgetsFlutterBinding.ensureInitialized();
var sdk = FeedSDK.getInstance(
feedifyKey: 'key',
feedifyDomain: 'domain',
feedifyUser: 'userKey');
// 确保所有屏幕尺寸的通知图标都可用,否则通知可能无法显示!
FeedSDK.setNotificationIcon('resource://drawable/ic_notification');
Logs.setEnabled(true);
await sdk.init(
appName: 'your app name',
projectId: 'firebase project Id',
firebaseCurrentApiKey: 'firebase api key',
firebaseMobileSdkAppId: 'firebase mobile app sdk id',
firebaseStorageBucket: 'firebase storage key url',
firebaseUrl: '',
firebaseProjectNumber: 'firebase project number',
notificationDataCallback: (p0) {
var icon = p0[Constants.icon];
var title = p0[Constants.title];
var body = p0[Constants.body];
var type = p0[Constants.type];
// 其他数据...
},
);
}
更多关于Flutter内容聚合插件feedify的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter内容聚合插件feedify的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
Feedify
是一个用于 Flutter 的内容聚合插件,它可以帮助开发者轻松地集成和管理内容流。通过 Feedify
,开发者可以轻松地从不同的数据源(如RSS、API等)获取内容,并将其展示在应用中。
安装
首先,你需要在 pubspec.yaml
文件中添加 feedify
依赖:
dependencies:
feedify: ^latest_version
然后运行 flutter pub get
来安装依赖。
基本用法
以下是一个简单的示例,展示如何使用 Feedify
来获取和显示内容。
import 'package:flutter/material.dart';
import 'package:feedify/feedify.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
title: 'Feedify Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
final Feedify _feedify = Feedify();
Future<List<FeedItem>> fetchData() async {
// Replace with your data source
return await _feedify.fetchFeed('https://example.com/feed');
}
[@override](/user/override)
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Feedify Example'),
),
body: FutureBuilder<List<FeedItem>>(
future: fetchData(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
} else if (!snapshot.hasData || snapshot.data!.isEmpty) {
return Center(child: Text('No data available.'));
} else {
return ListView.builder(
itemCount: snapshot.data!.length,
itemBuilder: (context, index) {
final item = snapshot.data![index];
return ListTile(
title: Text(item.title ?? 'No Title'),
subtitle: Text(item.description ?? 'No Description'),
);
},
);
}
},
),
);
}
}