Flutter安全屏幕插件tbib_secure_screen的使用
Flutter安全屏幕插件tbib_secure_screen的使用
插件介绍
这个插件用于在保存截图或录制屏幕时,屏幕会显示空白。
开始使用
- Android配置:无需进行任何操作。
- iOS配置:前往 AppDelegate.swift 文件。
import UIKit
import Flutter
import tbib_secure_screen
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
TbibSecureScreenPlugin.register(with: self.registrar(forPlugin: "tbib_secure_screen")!)
TbibSecureScreenPlugin.shared?.initSecure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func applicationWillResignActive(
_ application: UIApplication
) {
TbibSecureScreenPlugin.shared?.blurScreen()
}
override func applicationDidBecomeActive(
_ application: UIApplication
) {
TbibSecureScreenPlugin.shared?.removeBlurScreen()
}
}
注意事项
在 iOS 上,屏幕将在应用程序中的任何地方变为空白,而不是特定的屏幕,这意味着它将自动激活。
在 Android 上,工作在特定的屏幕上。
在 Flutter (Android) 中激活插件
你需要调用以下代码来激活插件:
TBIBSecureScreen().setSecureScreen();
在 Flutter (Android) 中禁用插件
你需要调用以下代码来禁用插件:
TBIBSecureScreen().setUnsecureScreen();
示例代码
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:tbib_secure_screen/tbib_secure_screen.dart';
void main() {
TBIBSecureScreen().setSecureScreen();
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
[@override](/user/override)
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _platformVersion = 'Unknown';
final _tbibSecureScreenPlugin = TBIBSecureScreen();
[@override](/user/override)
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: Center(
child: Text('Running on: $_platformVersion\n'),
),
),
);
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
platformVersion = await _tbibSecureScreenPlugin.getPlatformVersion() ?? 'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
_platformVersion = platformVersion;
});
}
[@override](/user/override)
void initState() {
super.initState();
initPlatformState();
}
}
更多关于Flutter安全屏幕插件tbib_secure_screen的使用的实战教程也可以访问 https://www.itying.com/category-92-b0.html
1 回复