Flutter核心功能扩展插件aether_core的使用
Flutter核心功能扩展插件aether_core的使用
aether_core
Aether Core 是一个为 Flutter 开发设计的全面应用程序框架。它提供了多种功能,帮助开发者简化工作流程,包括简化 ORM 用于管理实体,基于流行的 Getx 包的无上下文路由,以及在上下文中内置的身份验证管理支持。
除了这些功能,Aether Core 还包括对话框和 Snackbar 的简化集成,使开发者能够轻松地向他们的应用程序添加这些常见的用户界面元素。它还通过与 DIO 包无缝集成,允许开发者轻松地进行 REST 或 GraphQL 调用。
总体而言,Aether Core 是一个强大且灵活的框架,可以帮助开发者轻松创建高质量的 Flutter 应用程序。通过简化许多应用开发中常见的任务,它可以帮助开发者节省时间并专注于构建应用的核心功能。
设置文件
创建以下三个文件:
assets\system\settings.json
assets\system\settings.staging.json
assets\system\settings.debug.json
逻辑流程如下:
- 系统将首先加载
settings.json
。 - 如果处于暂存模式,将加载
settings.staging.json
并覆盖任何现有的设置。 - 如果处于调试模式,将加载
settings.debug.json
并覆盖任何现有的设置。
示例:
{
"ApiBaseUrl": "https://viqcommunity.com",
"ApiKey": "<Api Key>",
"ApiConnectTimeoutInSec": 15,
"GooglePlayURL": "https://play.google.com/store/apps/details?id=com.viqcore.community_live",
"AppleAppStoreURL": "https://apps.apple.com/my/app/viqcore-community/id1499329657",
"HuaweiAppGalleryURL": "https://appgallery.cloud.huawei.com/marketshare/app/C102024395?locale=en_GB&source=appshare&subsource=C102024395"
}
构建应用服务
在调用 RunApp
之前,通过 AppBuilder
构建应用服务。
final builder = AppBuilder(appName: 'VIQ Community Admin');
// 自定义凭证操作
// 继承自 AppCredential
class CustomAppCredential extends AppCredential {
// 自定义实现
}
builder.useAppCredential(CustomAppCredential());
// 自定义对话框设置
// 继承自 AppDialog
class CustomAppDialog extends AppDialog {
// 自定义实现
}
builder.useAppDialog(CustomAppDialog());
// 构建应用服务
await builder.build();
对话框、Snackbar 和进度指示器
// 显示对话框
App.dialog.show({
String? title,
String? description,
String? cancelTitle,
Color? cancelTitleColor,
String? buttonTitle,
Color? buttonTitleColor,
bool barrierDismissible = false,
DialogPlatform? dialogPlatform
});
// 显示确认对话框
App.dialog.showConfirm(String question, {
String? title,
String? buttonTitle,
String? cancelButtonTitle
});
// 显示通知
App.dialog.showInfo(String info, {String? title});
App.dialog.showError(dynamic error, {String? title});
// 显示进度指示器
App.showProgressIndicator({String? status});
App.dismissProgressIndicator();
实体
class Company extends Entity {
late final Field<DateTime> name = field('name');
late final Field<DateTime> time = field('time');
late final Field<int> capacity = field('capacity');
late final Field<double> kpi = field('kpi');
late final ListField<Machine> machines = fieldList('machines');
late final Field<Settings> settings = field('settings');
late final Field<PlanQuality> planQuality = field('planQuality');
Company() {
print('Company constructor');
capacity.computed(
bindings: [machines],
compute: () => machines.fold(0, (p, e) => p! + e.capacity()),
);
machines.register(() => Machine());
settings.register(() => Settings(), auto: true);
print('End of Company constructor');
}
}
class Machine extends Entity {
late final Field<String> name = field('name');
late final Field<int> capacity = field('capacity');
}
class Settings extends Entity {
late final Field<int> minCapacity = field('minCapacity', defaultValue: 10);
}
class PlanQuality extends Entity {}
API 连接
快速 REST API 访问
final result = await '/api/login'.api(body: request.data).post(
timeout: Duration(seconds: 5),
headers: {"AppToken": request["appToken"]});
默认情况下,它将通过 App.api
进行连接。您可以覆盖它以访问外部 API。
final response = await 'https://oauth2.googleapis.com/token'
.api(body: {
'code': code,
'client_id': clientID,
'client_secret': clientSecret,
'redirect_uri': redirectUri,
'grant_type': 'authorization_code',
})
.external() // 指示这是一个外部 API
.post();
快速 GraphQL API 访问
'community'
.gql([...data.fragment, 'location'.gql(Location().fragment)],
params: {'id': communityId})
.query()
.then((response) {
if (response.hasError) {
App.error(response.errorText);
return;
}
if (response.isOk) {
data.load(response.body);
}
});
更多关于Flutter核心功能扩展插件aether_core的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
更多关于Flutter核心功能扩展插件aether_core的使用的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
aether_core
是一个 Flutter 插件,旨在扩展 Flutter 的核心功能,提供一些常见但 Flutter 本身不直接支持的实用功能。虽然截至 2023 年 12 月,aether_core
并不是 Flutter 官方维护的插件,但它的目标是简化开发者的工作流程,并提供一些有用的工具和扩展。
以下是 aether_core
的一些核心功能和使用方法:
1. 安装插件
在 pubspec.yaml
文件中添加 aether_core
依赖:
dependencies:
aether_core: ^latest_version
然后运行 flutter pub get
安装依赖。
2. 核心功能
aether_core
提供了以下功能:
2.1 扩展方法
-
字符串处理:例如,将字符串转换为驼峰命名、检查是否为电子邮件等。
String str = "hello_world"; print(str.toCamelCase()); // 输出: helloWorld
-
列表操作:例如,快速找到重复项、过滤空值等。
List<int> numbers = [1, 2, 2, 3]; print(numbers.findDuplicates()); // 输出: [2]
-
日期处理:例如,格式化日期、计算日期差等。
DateTime now = DateTime.now(); print(now.format("yyyy-MM-dd")); // 输出: 2023-12-01
2.2 网络请求封装
aether_core
提供了一个简化的网络请求工具,支持 GET、POST 等方法。
import 'package:aether_core/aether_core.dart';
void fetchData() async {
var response = await AetherHttp.get("https://jsonplaceholder.typicode.com/posts");
print(response.data);
}
2.3 状态管理工具
aether_core
提供了一个轻量级的状态管理工具,避免使用复杂的框架。
class CounterController extends AetherController {
int count = 0;
void increment() {
count++;
notifyListeners();
}
}
2.4 本地存储
封装了本地存储的常用方法,支持键值对存储。
void saveData() async {
await AetherStorage.save("key", "value");
var value = await AetherStorage.get("key");
print(value); // 输出: value
}
2.5 UI 组件扩展
提供了一些常用的 UI 组件扩展,例如更灵活的按钮、卡片等。
AetherButton(
onPressed: () {},
child: Text("Click Me"),
);
3. 使用示例
以下是一个完整的示例,展示如何使用 aether_core
的功能:
import 'package:flutter/material.dart';
import 'package:aether_core/aether_core.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text("Aether Core Example")),
body: Center(
child: Column(
children: [
AetherButton(
onPressed: () async {
var response = await AetherHttp.get("https://jsonplaceholder.typicode.com/posts");
print(response.data);
},
child: Text("Fetch Data"),
),
SizedBox(height: 16),
Text("Hello World".toCamelCase()),
],
),
),
),
);
}
}