1.列表,筛选完成和未完成

2.详情,增加checkout
This commit is contained in:
zhutao
2025-09-24 10:22:35 +08:00
parent 9b3c08dabc
commit ca376d9393
19 changed files with 838 additions and 542 deletions

View File

@@ -0,0 +1,228 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:go_router/go_router.dart';
import 'package:plan/api/endpoints/user_api.dart';
import 'package:plan/api/network/safe.dart';
import 'package:provider/provider.dart';
import '../../../providers/app_store.dart';
import '../../../router/config/route_paths.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 List<FocusNode> _focusNodes = List.generate(4, (_) => FocusNode());
final List<TextEditingController> _controllers = List.generate(
4,
(_) => TextEditingController(),
);
//倒计时
int _count = 60;
Timer? _timer;
@override
void initState() {
super.initState();
_handSendCode();
_handClear();
}
@override
void dispose() {
_timer?.cancel();
_handClear();
super.dispose();
}
///小输入框改变时
void _onChanged(String value, int index) async {
//一键复制
if (value.length == 4) {
_handlePaste(value);
}
//提交
if (value.isNotEmpty && index == 3) {
_handSubmit();
return;
}
// 自动跳到下一格
if (value.length == 1 && index < 3) {
_focusNodes[index + 1].requestFocus();
}
}
void _handlePaste(String pastedText) {
// 只取前4位数字
final digits = pastedText.replaceAll(RegExp(r'[^0-9]'), '');
for (int i = 0; i < 4; i++) {
_controllers[i].text = i < digits.length ? digits[i] : '';
}
if (digits.length >= 4) {
_focusNodes[3].requestFocus();
_handSubmit();
} else if (digits.isNotEmpty) {
_focusNodes[digits.length].requestFocus();
}
}
///删除键
void _onDelete(KeyEvent event, int index) {
if (event is KeyDownEvent && event.logicalKey == LogicalKeyboardKey.backspace) {
final currentController = _controllers[index];
if (currentController.text.isEmpty && index > 0) {
_focusNodes[index - 1].requestFocus();
_controllers[index - 1].clear();
}
}
}
///发送验证码
void _handSendCode() {
if (_count != 60) {
return;
}
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
setState(() {
_count--;
});
if (_count == 0) {
setState(() {
_count = 60;
});
timer.cancel();
}
});
sendEmailCodeApi(widget.email);
EasyLoading.showToast("Send success");
}
///提交
void _handSubmit() async {
String code = _controllers.map((controller) => controller.text).join();
if (code.length == 4) {
EasyLoading.show();
var res = await safeRequest(
registerApi(
widget.email,
widget.password,
code,
),
onError: (error) {
_handClear();
EasyLoading.showToast("Login Error");
},
);
var appStore = context.read<AppStore>();
await appStore.setInfo(res);
context.go(RoutePaths.layout);
}
}
///清空
void _handClear() {
for (var controller in _controllers) {
controller.clear();
}
_focusNodes.first.requestFocus();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(),
body: ListView(
physics: NeverScrollableScrollPhysics(),
padding: EdgeInsets.all(20),
children: [
Container(
margin: EdgeInsets.only(bottom: 20),
child: Text(
"Check your inbox",
style: Theme.of(context).textTheme.titleLarge,
),
),
Container(
margin: EdgeInsets.only(bottom: 60),
child: Text(
"Verification code has been sent to ${widget.email}",
style: Theme.of(context).textTheme.labelLarge,
),
),
Row(
spacing: 20,
children: List.generate(4, (index) {
return Expanded(
child: AspectRatio(
aspectRatio: 1,
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: Theme.of(context).colorScheme.surfaceContainer,
borderRadius: BorderRadius.circular(10),
),
child: KeyboardListener(
focusNode: FocusNode(),
onKeyEvent: (event) {
_onDelete(event, index);
},
child: TextField(
controller: _controllers[index],
focusNode: _focusNodes[index],
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
maxLength: 4,
style: TextStyle(fontSize: 32),
decoration: InputDecoration(
counterText: "",
border: InputBorder.none,
isCollapsed: true,
),
onChanged: (value) {
_onChanged(value, index);
},
),
),
),
),
);
}),
),
Container(
margin: EdgeInsets.only(top: 30),
child: Row(
children: [
GestureDetector(
onTap: _handSendCode,
child: Visibility(
visible: _count != 60,
replacement: Text(
"Resend Code",
style: Theme.of(context).textTheme.bodySmall,
),
child: Text(
"Resend Code${_count}s",
style: Theme.of(context).textTheme.labelMedium,
),
),
),
],
),
),
],
),
);
}
}

View File

@@ -1,115 +0,0 @@
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 '../../../api/endpoints/user_api.dart';
import '../../../api/network/safe.dart';
import '../../../providers/app_store.dart';
import '../../../router/config/route_paths.dart';
import '../../../widgets/ui_kit/button/custom_button.dart';
import 'widget/widget.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

@@ -14,7 +14,9 @@ import '../../../router/config/route_paths.dart';
import '../../../utils/common.dart';
import '../../../widgets/ui_kit/button/custom_button.dart';
import 'widget/agreement_box.dart';
import 'widget/widget.dart';
import 'widget/login_input.dart';
import 'widget/login_header.dart';
import 'widget/login_other.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@@ -48,7 +50,11 @@ class _LoginPageState extends State<LoginPage> {
try {
await Dio().get(
'https://captive.apple.com/hotspot-detect.html',
options: Options(sendTimeout: const Duration(seconds: 3), receiveTimeout: const Duration(seconds: 3), headers: {'Cache-Control': 'no-cache'}),
options: Options(
sendTimeout: const Duration(seconds: 3),
receiveTimeout: const Duration(seconds: 3),
headers: {'Cache-Control': 'no-cache'},
),
);
return true;
} catch (_) {
@@ -58,11 +64,16 @@ class _LoginPageState extends State<LoginPage> {
void _initGoogleSign() {
if (isAndroid()) {
_googleSignIn.initialize(clientId: null, serverClientId: "512878764950-0bsl98c4q4p695mlmfn35qhmr2ld5n0o.apps.googleusercontent.com");
_googleSignIn.initialize(
clientId: null,
serverClientId:
"512878764950-0bsl98c4q4p695mlmfn35qhmr2ld5n0o.apps.googleusercontent.com",
);
} else {
_googleSignIn.initialize(
clientId: "512878764950-4hpppthg6c8p98mkfcro99echkftbbmo.apps.googleusercontent.com",
serverClientId: "512878764950-0bsl98c4q4p695mlmfn35qhmr2ld5n0o.apps.googleusercontent.com",
serverClientId:
"512878764950-0bsl98c4q4p695mlmfn35qhmr2ld5n0o.apps.googleusercontent.com",
);
}
@@ -76,7 +87,7 @@ class _LoginPageState extends State<LoginPage> {
}
///谷歌登录
void _handleGoogleSignIn() async {
void _handGoogleSignIn() async {
try {
// 如果用户未登录,则启动标准的 Google 登录
if (_googleSignIn.supportsAuthenticate()) {
@@ -112,7 +123,9 @@ class _LoginPageState extends State<LoginPage> {
///apple登录
void _handAppleSignIn() async {
try {
final credential = await SignInWithApple.getAppleIDCredential(scopes: [AppleIDAuthorizationScopes.email, AppleIDAuthorizationScopes.fullName]);
final credential = await SignInWithApple.getAppleIDCredential(
scopes: [AppleIDAuthorizationScopes.email, AppleIDAuthorizationScopes.fullName],
);
EasyLoading.show(status: "Logging in...");
var res = await thirdLoginApi(credential.identityToken!, OtherLoginType.apple);
EasyLoading.dismiss();
@@ -138,7 +151,10 @@ class _LoginPageState extends State<LoginPage> {
});
var isRegister = await checkRegisterApi(_emailController.text);
if (!isRegister) {
context.push(RoutePaths.loginCode, extra: {"email": _emailController.text, "password": _passwordController.text});
context.push(
RoutePaths.loginCode,
extra: {"email": _emailController.text, "password": _passwordController.text},
);
} else {
var res = await loginApi(_emailController.text, _passwordController.text);
_onLogin(res);
@@ -174,9 +190,9 @@ class _LoginPageState extends State<LoginPage> {
children: [
LogoBox(),
PageHeader(),
InputBox(hintText: "Email", controller: _emailController),
LoginInput(hintText: "Email", controller: _emailController),
SizedBox(height: 15),
InputBox(
LoginInput(
obscureText: _hidePassword,
hintText: "Password",
controller: _passwordController,
@@ -196,23 +212,12 @@ class _LoginPageState extends State<LoginPage> {
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: () {
_handleGoogleSignIn();
},
),
SizedBox(height: 15),
OtherButton(
title: "Continue with Apple",
icon: "assets/image/apple.png",
onTap: () {
_handAppleSignIn();
},
child: CustomButton(
loading: _subLoading,
round: false,
onPressed: _handSubmit,
child: Text("Continue"),
),
),
Container(
width: double.infinity,
@@ -220,6 +225,26 @@ class _LoginPageState extends State<LoginPage> {
alignment: Alignment.center,
child: AgreementBox(),
),
LoginDivider(),
Row(
spacing: 20,
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
OtherButton(
onTap: () {
_handGoogleSignIn();
},
icon: "assets/image/google.png",
),
OtherButton(
onTap: () {
_handAppleSignIn();
},
icon: "assets/image/apple.png",
),
],
),
],
),
),

View File

@@ -0,0 +1,53 @@
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: 40),
child: Column(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Image.asset(
"assets/image/logo.png",
width: 43,
),
),
Text(
"PlanCura",
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(
"Use your email to get started",
style: Theme.of(context).textTheme.bodySmall,
),
],
),
);
}
}

View File

@@ -0,0 +1,46 @@
import 'package:flutter/material.dart';
///输入框
class LoginInput extends StatelessWidget {
final bool obscureText;
final String hintText;
final TextEditingController controller;
final Widget? suffix;
const LoginInput({
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: 100,
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,
),
),
);
}
}

View File

@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
///分割线
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 icon;
const OtherButton({
super.key,
required this.onTap,
required this.icon,
});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: onTap,
child: Container(
width: 45,
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: Theme.of(context).colorScheme.surfaceContainer,
),
),
child: AspectRatio(
aspectRatio: 1,
child: Image.asset(icon),
),
),
);
}
}

View File

@@ -1,169 +0,0 @@
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: 40),
child: Column(
children: [
ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Image.asset(
"assets/image/logo.png",
width: 43,
),
),
Text(
"PlanCura",
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(
"Use your email to get started",
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: 100,
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,
),
],
),
),
);
}
}