alive_flutter_plugin 0.2.2 alive_flutter_plugin: ^0.2.2 copied to clipboard
A new Flutter plugin.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:alive_flutter_plugin_example/alivePage.dart';
import 'package:permission_handler/permission_handler.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
routes: {'/other': (BuildContext context) => LivePage()},
home: HomePage());
}
}
class HomePage extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<HomePage> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
// routes: {'/livePage':(BuildContext context)=>LivePage()},
home: Scaffold(
// appBar: AppBar(
// title: const Text('易盾活体检测'),
// ),
body: Center(
child: _buildContent(context),
),
),
);
}
Widget _buildContent(BuildContext context) {
return new Column(children: [
showFaceImage(),
showContentWidget(),
startDetectButton(context),
]);
}
Widget showFaceImage() {
return Row(
textDirection: TextDirection.rtl,
children: [
Padding(
padding: EdgeInsets.all(20),
child: Image.asset(
'images/pic_demo.png',
width: 160,
height: 160,
))
],
);
}
Widget showContentWidget() {
return Column(
children: [
SizedBox(height: 30),
showLogo(),
showText(),
showText1(),
SizedBox(height: 30),
showDetail()
],
);
}
Widget showLogo() {
return Container(
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
alignment: Alignment.topLeft,
child: Image.asset(
'images/ico_logo_bar_white.png',
width: 40,
height: 40,
alignment: Alignment.topLeft,
));
}
Widget showText() {
return Container(
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
alignment: Alignment.topLeft,
child: Text(
"欢迎体检,",
style: TextStyle(
color: Colors.black,
fontSize: 24,
fontFamily: "PingFangSC-Semibold"),
maxLines: 5,
));
}
Widget showText1() {
return Container(
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
alignment: Alignment.topLeft,
child: Text(
"易盾活体检测Demo",
style: TextStyle(
color: Colors.black,
fontSize: 24,
fontFamily: "PingFangSC-Semibold"),
maxLines: 5,
));
}
Widget showDetail() {
return Column(
children: [
addContent("明亮的光线环境下使用"),
SizedBox(height: 10),
addContent("不要遮挡面部"),
SizedBox(height: 10),
addContent("正握手机,人脸正对屏幕")
],
);
}
Widget addContent(String content) {
return Row(
children: [
Padding(
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
child: Image.asset(
'images/ico_green.png',
width: 20,
height: 20,
alignment: Alignment.topLeft,
)),
Text(content,
style: TextStyle(
color: Colors.grey,
fontSize: 14,
fontFamily: "PingFangSC-Semibold"))
],
);
}
Widget startDetectButton(BuildContext context) {
return new Container(
child: SizedBox(
child: new CustomButton(
onPressed: () {
if (defaultTargetPlatform == TargetPlatform.android) {
checkPermission().then((value) => {
if (value) {Navigator.pushNamed(context, '/other')}
});
} else {
Navigator.pushNamed(context, '/other');
}
},
title: "开始检测",
),
width: double.infinity,
height: 49,
),
margin: EdgeInsets.fromLTRB(40, 40, 40, 5),
);
}
}
// ignore: missing_return
Future<bool> checkPermission() async {
//当前权限
Permission permission = Permission.camera;
//权限的状态
PermissionStatus status = await permission.status;
if (status.isDenied) {
//发起权限申请
PermissionStatus status = await permission.request();
if (status.isGranted) {
return true;
} else {
return false;
}
} else {
return true;
}
}
/// 封装 按钮
class CustomButton extends StatelessWidget {
final VoidCallback onPressed;
final String title;
const CustomButton({required this.onPressed, required this.title});
@override
Widget build(BuildContext context) {
return new TextButton(
onPressed: onPressed,
style: ButtonStyle(
backgroundColor:
WidgetStateProperty.resolveWith((states) => Colors.blue)),
child: new Text(
"$title",
style: TextStyle(fontSize: 13, color: Colors.white),
),
);
}
}