This commit is contained in:
zhutao
2025-08-22 14:15:02 +08:00
parent 5853bdf004
commit 99a1ce601e
120 changed files with 5297 additions and 101 deletions

View File

@@ -0,0 +1,23 @@
import 'package:flutter/material.dart';
import 'package:webview_flutter/webview_flutter.dart';
class AgreePage extends StatelessWidget {
final String title;
final String url;
const AgreePage({super.key, required this.title, required this.url});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: WebViewWidget(
controller: WebViewController()
..setJavaScriptMode(JavaScriptMode.unrestricted)
..loadRequest(Uri.parse(url)),
),
);
}
}

View File

@@ -0,0 +1,115 @@
import 'package:derma_flutter/api/endpoints/user_api.dart';
import 'package:derma_flutter/api/network/safe.dart';
import 'package:derma_flutter/page/system/login/widget/widget.dart';
import 'package:derma_flutter/router/config/route_paths.dart';
import 'package:derma_flutter/widgets/ui_kit/button/custom_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import '../../../providers/app_store.dart';
class LoginCodePage extends StatefulWidget {
final String email;
final String password;
const LoginCodePage({super.key, required this.email, required this.password});
@override
State<LoginCodePage> createState() => _LoginCodePageState();
}
class _LoginCodePageState extends State<LoginCodePage> {
final _codeController = TextEditingController();
var _subLoading = false;
@override
void initState() {
super.initState();
_handSendCode();
}
///发送验证码
void _handSendCode() {
sendEmailCodeApi(widget.email);
EasyLoading.showSuccess("Send success");
}
///提交
void _handSubmit() async {
if (_codeController.text.isNotEmpty) {
setState(() {
_subLoading = true;
});
var res = await safeRequest(
registerApi(
widget.email,
widget.password,
_codeController.text,
),
onError: (error) {
setState(() {
_subLoading = false;
});
},
);
var appStore = context.read<AppStore>();
await appStore.setInfo(res);
context.go(RoutePaths.layout);
setState(() {
_subLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
width: double.infinity,
padding: EdgeInsets.only(left: 20, right: 20, top: 40),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
"Check your inbox",
style: Theme.of(context).textTheme.titleLarge,
),
Container(
margin: EdgeInsets.only(top: 20, bottom: 40),
child: Text(
"Enter the verification code we just sent to ${widget.email}.",
textAlign: TextAlign.center,
style: Theme.of(context).textTheme.labelMedium,
),
),
InputBox(hintText: "Code", controller: _codeController),
Container(
margin: EdgeInsets.only(top: 20),
child: CustomButton(
loading: _subLoading,
onPressed: _handSubmit,
child: Text("Continue"),
),
),
Container(
margin: EdgeInsets.only(top: 20),
child: TextButton(
onPressed: () {
_handSendCode();
},
child: Text(
"Resend code",
style: Theme.of(context).textTheme.labelSmall,
),
),
),
],
),
),
),
);
}
}

View File

@@ -0,0 +1,236 @@
import 'package:derma_flutter/api/endpoints/user_api.dart';
import 'package:derma_flutter/data/models/other_login_type.dart';
import 'package:derma_flutter/router/config/route_paths.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:go_router/go_router.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:provider/provider.dart';
import 'package:remixicon/remixicon.dart';
import '../../../providers/app_store.dart';
import '../../../widgets/common/app_backend.dart';
import '../../../widgets/ui_kit/button/custom_button.dart';
import 'widget/agreement_box.dart';
import 'widget/widget.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
State<LoginPage> createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
var _subLoading = false;
///协议
bool _agree = false;
///谷歌登陆
final GoogleSignIn _googleSignIn = GoogleSignIn.instance;
///邮箱输入框
final TextEditingController _emailController = TextEditingController(text: "18207394@qq.com");
final TextEditingController _passwordController = TextEditingController(text: "111");
//显示密码
var _hidePassword = true;
@override
void initState() {
super.initState();
_initGoogleSign();
}
void _initGoogleSign() {
_googleSignIn.initialize(
clientId: null,
serverClientId: "497244455669-sl271gkb1polqd8kqtnb6co82n95aerq.apps.googleusercontent.com",
);
_googleSignIn.authenticationEvents
.listen((_) {
print("登陆成功");
})
.onError((error) {
print('登录错误: $error');
});
}
void _handleSignIn() async {
if (!_agree) {
EasyLoading.showToast('Please read and agree to the terms first.');
return;
}
try {
// 如果用户未登录,则启动标准的 Google 登录
if (_googleSignIn.supportsAuthenticate()) {
// 使用 authenticate() 进行认证
GoogleSignInAccount? user = await _googleSignIn.authenticate();
var auth = user.authentication;
// var res = await Dio().get("https://oauth2.googleapis.com/tokeninfo?id_token=${auth.idToken}");
//登陆
EasyLoading.show(status: "Logging in...");
var res = await thirdLoginApi(auth.idToken!, OtherLoginType.google);
EasyLoading.dismiss();
_onLogin(res);
}
// } catch (e) {
// if (e is GoogleSignInException) {
// if (e.code == GoogleSignInExceptionCode.canceled) {
// // 用户取消登录
// print("User canceled login.");
// } else {
// // 其他错误
// print("Google Sign-In error: $e");
// }
// } else {
// print("Unknown error: $e");
// }
// }
} catch (e) {
EasyLoading.showError("Login failed");
print("登录错误: $e");
}
}
void _handSubmit() async {
if (!_agree) {
EasyLoading.showToast('Please read and agree to the terms first.');
return;
}
if (_emailController.text.isEmpty) {
//请输入邮箱
EasyLoading.showError("Please enter your email");
return;
} else if (_passwordController.text.isEmpty) {
EasyLoading.showError("Please enter your Password");
return;
}
try {
setState(() {
_subLoading = true;
});
var isRegister = await checkRegisterApi(_emailController.text);
if (!isRegister) {
context.push(
RoutePaths.loginCode,
extra: {
"email": _emailController.text,
"password": _passwordController.text,
},
);
} else {
var res = await loginApi(_emailController.text, _passwordController.text);
_onLogin(res);
}
setState(() {
_subLoading = false;
});
} catch (e) {
setState(() {
_subLoading = false;
});
}
}
///登陆的操作
void _onLogin(dynamic res) {
var appStore = context.read<AppStore>();
appStore.setInfo(res);
context.go(RoutePaths.layout);
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => FocusScope.of(context).unfocus(),
child: AppBackend(
child: Scaffold(
resizeToAvoidBottomInset: false,
body: SafeArea(
child: Stack(
alignment: Alignment.center,
children: [
Container(
width: double.infinity,
padding: EdgeInsets.only(
top: 0.1.sh,
left: 20,
right: 20,
),
child: Column(
children: [
LogoBox(),
PageHeader(),
InputBox(
hintText: "Email",
controller: _emailController,
),
SizedBox(height: 15),
InputBox(
obscureText: _hidePassword,
hintText: "Password",
controller: _passwordController,
suffix: InkWell(
onTap: () {
setState(() {
_hidePassword = !_hidePassword;
});
},
child: Icon(
_hidePassword ? RemixIcons.eye_off_fill : RemixIcons.eye_fill,
size: 20,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
Container(
margin: EdgeInsets.only(top: 20),
height: 45,
child: CustomButton(
loading: _subLoading,
round: false,
onPressed: _handSubmit,
child: Text("Continue"),
),
),
LoginDivider(),
OtherButton(
title: "Continue with Google",
icon: "assets/image/google.png",
onTap: () {
_handleSignIn();
},
),
SizedBox(height: 15),
// OtherButton(
// title: "Continue with Apple",
// icon: "assets/image/apple.png",
// onTap: () {},
// ),
],
),
),
Positioned(
bottom: 20,
child: AgreementBox(
checked: _agree,
onChanged: (value) {
setState(() {
_agree = value;
});
},
),
),
],
),
),
),
),
);
}
}

View File

@@ -0,0 +1,77 @@
import 'package:derma_flutter/router/config/route_paths.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
///勾中协议
class AgreementBox extends StatelessWidget {
final bool checked;
final Function(bool) onChanged;
const AgreementBox({
super.key,
this.checked = false,
required this.onChanged,
});
@override
Widget build(BuildContext context) {
return Row(
children: [
SizedBox(
width: 25,
child: Transform.scale(
scale: 0.8,
child: Checkbox(
value: checked,
shape: CircleBorder(),
onChanged: (value) {
onChanged(value!);
},
),
),
),
RichText(
text: TextSpan(
style: Theme.of(context).textTheme.labelSmall,
children: [
TextSpan(
text: "我已阅读并同意",
recognizer: TapGestureRecognizer()
..onTap = () {
onChanged(!checked);
},
),
TextSpan(
text: "《用户协议》",
style: TextStyle(
color: Theme.of(context).primaryColor,
),
recognizer: TapGestureRecognizer()
..onTap = () {
context.push(
RoutePaths.agreement,
extra: {"title": "用户协议", "url": "https://keyang2.tuzuu.com/ak-health/agreement/user_agreement.html"},
);
},
),
TextSpan(
text: "《隐私协议》",
style: TextStyle(
color: Theme.of(context).primaryColor,
),
recognizer: TapGestureRecognizer()
..onTap = () {
context.push(
RoutePaths.agreement,
extra: {"title": "隐私政策", "url": "https://keyang2.tuzuu.com/ak-health/agreement/privacy_policy.html"},
);
},
),
],
),
),
],
);
}
}

View File

@@ -0,0 +1,166 @@
import 'package:flutter/material.dart';
///登陆Box
class LogoBox extends StatelessWidget {
const LogoBox({super.key});
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(bottom: 60),
child: Column(
children: [
Image.asset(
"assets/image/logo.png",
width: 43,
),
Text(
"Demacare",
style: Theme.of(context).textTheme.titleSmall,
),
],
),
);
}
}
///头部文案
class PageHeader extends StatelessWidget {
const PageHeader({super.key});
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(bottom: 30),
child: Column(
children: [
Text(
"Create an account",
style: TextStyle(fontWeight: FontWeight.w700),
),
Text(
"Enter your email to sign up for this app",
style: Theme.of(context).textTheme.bodySmall,
),
],
),
);
}
}
///输入框
class InputBox extends StatelessWidget {
final bool obscureText;
final String hintText;
final TextEditingController controller;
final Widget? suffix;
const InputBox({
super.key,
this.obscureText = false,
required this.hintText,
required this.controller,
this.suffix,
});
@override
Widget build(BuildContext context) {
//边框
var inputBorder = OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Theme.of(context).colorScheme.surfaceContainer,
),
);
return TextField(
controller: controller,
maxLength: 20,
obscureText: obscureText,
style: Theme.of(context).textTheme.bodyMedium,
decoration: InputDecoration(
hintText: hintText,
hintStyle: Theme.of(context).textTheme.labelMedium,
counterText: '',
border: inputBorder,
enabledBorder: inputBorder,
suffix: suffix,
suffixIconConstraints: BoxConstraints(
minWidth: 0,
minHeight: 0,
),
),
);
}
}
///分割线
class LoginDivider extends StatelessWidget {
const LoginDivider({super.key});
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 20, bottom: 20),
child: Row(
spacing: 8,
children: [
Expanded(
child: Container(
height: 1,
color: Theme.of(context).colorScheme.surfaceContainer,
),
),
Text(
"or",
style: Theme.of(context).textTheme.labelMedium,
),
Expanded(
child: Container(
height: 1,
color: Theme.of(context).colorScheme.surfaceContainer,
),
),
],
),
);
}
}
///其他登陆按钮
class OtherButton extends StatelessWidget {
final Function() onTap;
final String title;
final String icon;
const OtherButton({
super.key,
required this.onTap,
required this.title,
required this.icon,
});
@override
Widget build(BuildContext context) {
return InkWell(
onTap: onTap,
child: Container(
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Theme.of(context).colorScheme.surfaceContainer,
),
child: Row(
spacing: 10,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(icon, width: 20),
Text(
title,
style: Theme.of(context).textTheme.bodySmall,
),
],
),
),
);
}
}

View File

@@ -0,0 +1,65 @@
import 'package:derma_flutter/providers/app_store.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:go_router/go_router.dart';
import 'package:provider/provider.dart';
import '../../../config/app_context.dart';
import '../../../router/config/route_paths.dart';
import '../../../router/routes.dart';
class SplashPage extends StatefulWidget {
const SplashPage({super.key});
@override
State<SplashPage> createState() => _SplashPageState();
}
class _SplashPageState extends State<SplashPage> {
@override
void initState() {
super.initState();
init();
}
void init() {
WidgetsBinding.instance.addPostFrameCallback((_) async {
AppContext.setContent(navigatorKey.currentState!.context);
//效验
AppStore appStore = context.read<AppStore>();
await appStore.init();
if (!mounted) return;
if (appStore.token.isEmpty) {
context.go(RoutePaths.login);
} else {
context.go(RoutePaths.layout);
}
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SizedBox(
width: double.infinity,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Image.asset(
"assets/image/logo.png",
width: 68.w,
),
Container(
margin: EdgeInsets.only(top: 16),
child: Text(
"Demacare",
style: Theme.of(context).textTheme.titleMedium,
),
),
],
),
),
);
}
}