feat: add fluttertoast localization with HarmonyOS support and ToastService

This commit is contained in:
Developer
2026-04-08 01:46:45 +08:00
parent efaff0c692
commit b9a39ed2f1
7 changed files with 490 additions and 0 deletions

1
packages/fluttertoast Submodule

Submodule packages/fluttertoast added at 60bfbda748

View File

@@ -0,0 +1,7 @@
import 'fluttertoast_platform_interface.dart';
class FluttertoastOhos extends FluttertoastPlatform {
static void registerWith() {
FluttertoastPlatform.instance = FluttertoastOhos();
}
}

View File

@@ -0,0 +1,46 @@
import 'package:flutter/services.dart';
abstract class FluttertoastPlatform {
static FluttertoastPlatform? instance;
static const MethodChannel _channel =
MethodChannel('PonnamKarthik/fluttertoast');
Future<bool?> showToast({
required String msg,
String? toastLength,
int timeInSecForIosWeb = 1,
double? fontSize,
String? fontAsset,
String? gravity,
int? backgroundColor,
int? textColor,
bool webShowClose = false,
String webBgColor = "linear-gradient(to right, #00b09b, #96c93d)",
String webPosition = "right",
}) async {
final Map<String, dynamic> params = <String, dynamic>{
'msg': msg,
'length': toastLength,
'time': timeInSecForIosWeb,
'gravity': gravity,
'bgcolor': backgroundColor,
'iosBgcolor': backgroundColor,
'textcolor': textColor,
'iosTextcolor': textColor,
'fontSize': fontSize,
'fontAsset': fontAsset,
'webShowClose': webShowClose,
'webBgColor': webBgColor,
'webPosition': webPosition
};
bool? res = await _channel.invokeMethod('showToast', params);
return res;
}
Future<bool?> cancel() async {
bool? res = await _channel.invokeMethod("cancel");
return res;
}
}

View File

@@ -0,0 +1,28 @@
name: fluttertoast_ohos
description: Ohos implementation of the fluttertoast plugin.
repository: https://github.com/PonnamKarthik/FlutterToast
issue_tracker: https://github.com/ponnamkarthik/FlutterToast/issues
version: 9.0.0
environment:
sdk: ">=2.12.0 <4.0.0"
flutter: ">=1.10.0"
flutter:
plugin:
implements: fluttertoast
platforms:
ohos:
package: io.github.ponnamkarthik.toast.fluttertoast
pluginClass: FlutterToastPlugin
dartPluginClass: FluttertoastOhos
dependencies:
flutter:
sdk: flutter
fluttertoast:
path: ../fluttertoast
dev_dependencies:
flutter_test:
sdk: flutter