1
This commit is contained in:
33
lib/api/dto/article_detail_dto.dart
Normal file
33
lib/api/dto/article_detail_dto.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
class ArticleDetailDto {
|
||||
int? id;
|
||||
String? title;
|
||||
String? subtitle;
|
||||
String? content;
|
||||
int? status;
|
||||
String? createdAt;
|
||||
String? updatedAt;
|
||||
|
||||
ArticleDetailDto({this.id, this.title, this.subtitle, this.content, this.status, this.createdAt, this.updatedAt});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map["id"] = id;
|
||||
map["title"] = title;
|
||||
map["subtitle"] = subtitle;
|
||||
map["content"] = content;
|
||||
map["status"] = status;
|
||||
map["created_at"] = createdAt;
|
||||
map["updated_at"] = updatedAt;
|
||||
return map;
|
||||
}
|
||||
|
||||
ArticleDetailDto.fromJson(dynamic json){
|
||||
id = json["id"] ?? 0;
|
||||
title = json["title"] ?? "";
|
||||
subtitle = json["subtitle"] ?? "";
|
||||
content = json["content"] ?? "";
|
||||
status = json["status"] ?? 0;
|
||||
createdAt = json["created_at"] ?? "";
|
||||
updatedAt = json["updated_at"] ?? "";
|
||||
}
|
||||
}
|
||||
25
lib/api/dto/article_dto.dart
Normal file
25
lib/api/dto/article_dto.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
class ArticleDto {
|
||||
int? id;
|
||||
String? title;
|
||||
String? subtitle;
|
||||
|
||||
ArticleDto({
|
||||
this.id,
|
||||
this.title,
|
||||
this.subtitle,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map["id"] = id;
|
||||
map["title"] = title;
|
||||
map["subtitle"] = subtitle;
|
||||
return map;
|
||||
}
|
||||
|
||||
ArticleDto.fromJson(dynamic json) {
|
||||
id = json["id"] ?? 0;
|
||||
title = json["title"] ?? "";
|
||||
subtitle = json["subtitle"] ?? "";
|
||||
}
|
||||
}
|
||||
15
lib/api/dto/base_dto.dart
Normal file
15
lib/api/dto/base_dto.dart
Normal file
@@ -0,0 +1,15 @@
|
||||
class ApiDto<T> {
|
||||
final int code;
|
||||
final String message;
|
||||
final T data;
|
||||
|
||||
ApiDto({required this.code, required this.message, required this.data});
|
||||
|
||||
factory ApiDto.fromJson(Map<String, dynamic> json) {
|
||||
return ApiDto<T>(
|
||||
code: json['code'],
|
||||
message: json['message'],
|
||||
data: json['data'],
|
||||
);
|
||||
}
|
||||
}
|
||||
86
lib/api/dto/login_dto.dart
Normal file
86
lib/api/dto/login_dto.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
class UserInfo {
|
||||
int? id;
|
||||
String? name;
|
||||
dynamic avatar;
|
||||
String? email;
|
||||
dynamic emailVerifiedAt;
|
||||
dynamic googleId;
|
||||
dynamic appleId;
|
||||
String? lastLoginIp;
|
||||
String? lastLoginTime;
|
||||
dynamic lastUsedTime;
|
||||
int? status;
|
||||
String? createdAt;
|
||||
String? updatedAt;
|
||||
|
||||
UserInfo({
|
||||
this.id,
|
||||
this.name,
|
||||
this.avatar,
|
||||
this.email,
|
||||
this.emailVerifiedAt,
|
||||
this.googleId,
|
||||
this.appleId,
|
||||
this.lastLoginIp,
|
||||
this.lastLoginTime,
|
||||
this.lastUsedTime,
|
||||
this.status,
|
||||
this.createdAt,
|
||||
this.updatedAt,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map["id"] = id;
|
||||
map["name"] = name;
|
||||
map["avatar"] = avatar;
|
||||
map["email"] = email;
|
||||
map["email_verified_at"] = emailVerifiedAt;
|
||||
map["google_id"] = googleId;
|
||||
map["apple_id"] = appleId;
|
||||
map["last_login_ip"] = lastLoginIp;
|
||||
map["last_login_time"] = lastLoginTime;
|
||||
map["last_used_time"] = lastUsedTime;
|
||||
map["status"] = status;
|
||||
map["created_at"] = createdAt;
|
||||
map["updated_at"] = updatedAt;
|
||||
return map;
|
||||
}
|
||||
|
||||
UserInfo.fromJson(dynamic json) {
|
||||
id = json["id"] ?? 0;
|
||||
name = json["name"] ?? "";
|
||||
avatar = json["avatar"];
|
||||
email = json["email"] ?? "";
|
||||
emailVerifiedAt = json["email_verified_at"];
|
||||
googleId = json["google_id"];
|
||||
appleId = json["apple_id"];
|
||||
lastLoginIp = json["last_login_ip"] ?? "";
|
||||
lastLoginTime = json["last_login_time"] ?? "";
|
||||
lastUsedTime = json["last_used_time"];
|
||||
status = json["status"] ?? 0;
|
||||
createdAt = json["created_at"] ?? "";
|
||||
updatedAt = json["updated_at"] ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
class LoginDto {
|
||||
String? accessToken;
|
||||
UserInfo? userInfo;
|
||||
|
||||
LoginDto({this.accessToken, this.userInfo});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map["accessToken"] = accessToken;
|
||||
if (userInfo != null) {
|
||||
map["userInfo"] = userInfo?.toJson();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
LoginDto.fromJson(dynamic json) {
|
||||
accessToken = json["accessToken"] ?? "";
|
||||
userInfo = json["userInfo"] != null ? UserInfo.fromJson(json["userInfo"]) : null;
|
||||
}
|
||||
}
|
||||
66
lib/api/dto/record_list_dto.dart
Normal file
66
lib/api/dto/record_list_dto.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
import 'package:derma_flutter/api/dto/skin_check_dto.dart';
|
||||
|
||||
class RecordItemDto {
|
||||
num? id;
|
||||
num? userId;
|
||||
String? imageUrl;
|
||||
num? imageType;
|
||||
num? skinStatus;
|
||||
String? createdAt;
|
||||
SkinCheckDto? result;
|
||||
|
||||
RecordItemDto({
|
||||
this.id,
|
||||
this.userId,
|
||||
this.imageUrl,
|
||||
this.imageType,
|
||||
this.skinStatus,
|
||||
this.createdAt,
|
||||
this.result,
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map["id"] = id;
|
||||
map["user_id"] = userId;
|
||||
map["image_url"] = imageUrl;
|
||||
map["image_type"] = imageType;
|
||||
map["skin_status"] = skinStatus;
|
||||
map["created_at"] = createdAt;
|
||||
map["result"] = result?.toJson();
|
||||
return map;
|
||||
}
|
||||
|
||||
RecordItemDto.fromJson(dynamic json) {
|
||||
id = json["id"] ?? 0;
|
||||
userId = json["user_id"] ?? 0;
|
||||
imageUrl = json["image_url"] ?? "";
|
||||
imageType = json["image_type"] ?? 0;
|
||||
skinStatus = json["skin_status"] ?? 0;
|
||||
createdAt = json["created_at"] ?? "";
|
||||
result = json["result"] != null ? SkinCheckDto.fromJson(json["result"]) : null;
|
||||
}
|
||||
}
|
||||
|
||||
class RecordListDto {
|
||||
num? total;
|
||||
List<RecordItemDto>? list;
|
||||
|
||||
RecordListDto({this.total, this.list});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map["total"] = total;
|
||||
if (list != null) {
|
||||
map["list"] = list?.map((v) => v.toJson()).toList();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
factory RecordListDto.fromJson(dynamic json) {
|
||||
return RecordListDto(
|
||||
total: json["total"] ?? 0,
|
||||
list: (json["list"] as List<dynamic>? ?? []).map((v) => RecordItemDto.fromJson(v)).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
39
lib/api/dto/skin_check_dto.dart
Normal file
39
lib/api/dto/skin_check_dto.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import '../../data/models/skin_check_status.dart';
|
||||
|
||||
class SkinCheckDto {
|
||||
int? id;
|
||||
int? score;
|
||||
String? rating;
|
||||
String? concise;
|
||||
late List<String> tags;
|
||||
late SkinCheckStatus skinStatus;
|
||||
|
||||
SkinCheckDto({
|
||||
this.id,
|
||||
this.skinStatus = SkinCheckStatus.unknown,
|
||||
this.score,
|
||||
this.rating,
|
||||
this.concise,
|
||||
this.tags = const [],
|
||||
});
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final map = <String, dynamic>{};
|
||||
map["id"] = id;
|
||||
map["score"] = score;
|
||||
map["rating"] = rating;
|
||||
map["concise"] = concise;
|
||||
map["tags"] = tags;
|
||||
map["skin_status"] = skinStatus.value;
|
||||
return map;
|
||||
}
|
||||
|
||||
SkinCheckDto.fromJson(dynamic json) {
|
||||
id = json["id"];
|
||||
skinStatus = SkinCheckStatus.fromValue(json["skin_status"] ?? 0);
|
||||
score = json["score"];
|
||||
rating = json["rating"];
|
||||
concise = json["concise"];
|
||||
tags = (json["tags"] as List?)?.map((e) => e.toString()).toList() ?? [];
|
||||
}
|
||||
}
|
||||
54
lib/api/endpoints/skin_api.dart
Normal file
54
lib/api/endpoints/skin_api.dart
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:derma_flutter/api/dto/article_detail_dto.dart';
|
||||
import 'package:derma_flutter/api/dto/record_list_dto.dart';
|
||||
import 'package:derma_flutter/api/dto/skin_check_dto.dart';
|
||||
import 'package:derma_flutter/api/network/request.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../dto/article_dto.dart';
|
||||
|
||||
///皮肤检测
|
||||
Future<SkinCheckDto> skinDetectApi(String path) async {
|
||||
FormData formData = FormData.fromMap({
|
||||
"skin_image": await MultipartFile.fromFile(path),
|
||||
});
|
||||
var res = await Request().post("/skin/check", formData);
|
||||
return SkinCheckDto.fromJson(res);
|
||||
}
|
||||
|
||||
///提交联系邮箱
|
||||
Future<void> skinContactApi(int id, String email) async {
|
||||
await Request().post("/customer-health/submit-demand", {
|
||||
"email": email,
|
||||
"skin_check_record_id": id,
|
||||
});
|
||||
}
|
||||
|
||||
///皮肤检测记录
|
||||
Future<RecordListDto> skinRecordApi({
|
||||
int page = 1,
|
||||
int pageSize = 20,
|
||||
Map<String, dynamic>? query,
|
||||
}) async {
|
||||
var res = await Request().get("/skin/records", {
|
||||
"search_params": jsonEncode(query),
|
||||
"page": page,
|
||||
"page_size": pageSize,
|
||||
});
|
||||
return RecordListDto.fromJson(res);
|
||||
}
|
||||
|
||||
///获取文章列表
|
||||
Future<List<ArticleDto>> articleListApi() async{
|
||||
var res = await Request().get("/customer-health/get_articles");
|
||||
return (res['list'] as List).map((e) => ArticleDto.fromJson(e)).toList();
|
||||
}
|
||||
|
||||
///文章详情
|
||||
Future<ArticleDetailDto> articleDetailApi(String id) async{
|
||||
var res = await Request().get("/customer-health/get_article_detail", {
|
||||
"id": id,
|
||||
});
|
||||
return ArticleDetailDto.fromJson(res);
|
||||
}
|
||||
50
lib/api/endpoints/user_api.dart
Normal file
50
lib/api/endpoints/user_api.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
import 'package:derma_flutter/api/dto/login_dto.dart';
|
||||
import 'package:derma_flutter/api/network/request.dart';
|
||||
import 'package:derma_flutter/data/models/other_login_type.dart';
|
||||
|
||||
///检查是否注册
|
||||
Future<bool> checkRegisterApi(String email) async {
|
||||
var res = await Request().post("/auth/email_check", {
|
||||
"email": email,
|
||||
});
|
||||
if (res["next"] == "login") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
// return res;
|
||||
}
|
||||
|
||||
///邮箱密码登陆
|
||||
Future<LoginDto> loginApi(String email, String password) async {
|
||||
var res = await Request().post("/auth/login/account", {
|
||||
"email": email,
|
||||
"password": password,
|
||||
});
|
||||
return LoginDto.fromJson(res);
|
||||
}
|
||||
|
||||
///注册处
|
||||
Future<LoginDto> registerApi(String email, String password, String code) async {
|
||||
var res = await Request().post("/auth/register", {
|
||||
"email": email,
|
||||
"password": password,
|
||||
"email_code": code,
|
||||
});
|
||||
return LoginDto.fromJson(res);
|
||||
}
|
||||
|
||||
///发送邮箱验证码
|
||||
Future<void> sendEmailCodeApi(String email) async {
|
||||
return Request().post("/send_email_code", {
|
||||
"email": email,
|
||||
});
|
||||
}
|
||||
|
||||
///三方登录
|
||||
Future<LoginDto> thirdLoginApi(String token, OtherLoginType type) async {
|
||||
var res =await Request().post("/auth/login/oauth", {
|
||||
"login_token": token,
|
||||
"login_type": type.value,
|
||||
});
|
||||
return LoginDto.fromJson(res);
|
||||
}
|
||||
65
lib/api/network/interceptor.dart
Normal file
65
lib/api/network/interceptor.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
|
||||
import '../../providers/app_store.dart';
|
||||
import '../dto/base_dto.dart';
|
||||
|
||||
|
||||
///请求拦截器
|
||||
void onRequest(
|
||||
RequestOptions options,
|
||||
RequestInterceptorHandler handler,
|
||||
) async {
|
||||
String token = await AppStore.getToken();
|
||||
options.headers['Authorization'] = 'Bearer $token';
|
||||
return handler.next(options);
|
||||
}
|
||||
|
||||
///响应拦截器
|
||||
void onResponse(
|
||||
Response<dynamic> response,
|
||||
ResponseInterceptorHandler handler,
|
||||
) {
|
||||
var apiResponse = ApiDto.fromJson(response.data);
|
||||
if (apiResponse.code == 1) {
|
||||
response.data = apiResponse.data;
|
||||
return handler.next(response);
|
||||
} else {
|
||||
showError(apiResponse.message);
|
||||
handler.reject(
|
||||
DioException(
|
||||
requestOptions: response.requestOptions,
|
||||
response: response,
|
||||
error: {'code': 0, 'message': apiResponse.message},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
///错误响应
|
||||
void onError(
|
||||
DioException e,
|
||||
ErrorInterceptorHandler handler,
|
||||
) {
|
||||
var title = "";
|
||||
if (e.type == DioExceptionType.connectionTimeout) {
|
||||
title = "请求超时";
|
||||
} else if (e.type == DioExceptionType.badResponse) {
|
||||
if (e.response?.statusCode == 404) {
|
||||
title = "接口404不存在";
|
||||
} else {
|
||||
title = "500";
|
||||
}
|
||||
} else if (e.type == DioExceptionType.connectionError) {
|
||||
title = "网络连接失败";
|
||||
} else {
|
||||
title = "异常其他错误";
|
||||
}
|
||||
showError(title);
|
||||
handler.next(e);
|
||||
}
|
||||
|
||||
///显示错误信息
|
||||
void showError(String message) {
|
||||
EasyLoading.showError(message);
|
||||
}
|
||||
44
lib/api/network/request.dart
Normal file
44
lib/api/network/request.dart
Normal file
@@ -0,0 +1,44 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../../config/env.dart';
|
||||
import 'interceptor.dart';
|
||||
|
||||
class Request {
|
||||
static final Request _instance = Request._internal();
|
||||
static Dio _dio = Dio();
|
||||
|
||||
//返回单例
|
||||
factory Request() {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
//初始化
|
||||
Request._internal() {
|
||||
//创建基本配置
|
||||
final BaseOptions options = BaseOptions(
|
||||
baseUrl: Config.baseUrl(),
|
||||
connectTimeout: const Duration(seconds: 30),
|
||||
receiveTimeout: const Duration(seconds: 30),
|
||||
);
|
||||
|
||||
_dio = Dio(options);
|
||||
|
||||
_dio.interceptors.add(InterceptorsWrapper(
|
||||
onRequest: onRequest,
|
||||
onResponse: onResponse,
|
||||
onError: onError,
|
||||
));
|
||||
}
|
||||
|
||||
///get请求
|
||||
Future<T> get<T>(String path, [Map<String, dynamic>? params]) async {
|
||||
var res = await _dio.get(path, queryParameters: params);
|
||||
return res.data;
|
||||
}
|
||||
|
||||
///post请求
|
||||
Future<dynamic> post(String path, Object? data) async {
|
||||
var res = await _dio.post(path, data: data);
|
||||
return res.data;
|
||||
}
|
||||
}
|
||||
13
lib/api/network/safe.dart
Normal file
13
lib/api/network/safe.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
/// 网络请求的错误处理封装
|
||||
Future<T> safeRequest<T>(Future<T> request, {
|
||||
void Function(DioException error)? onError,
|
||||
}) async {
|
||||
try {
|
||||
return await request;
|
||||
} on DioException catch (e) {
|
||||
onError?.call(e); // 额外 hook
|
||||
rethrow; // 继续往上传
|
||||
}
|
||||
}
|
||||
22
lib/config/app_context.dart
Normal file
22
lib/config/app_context.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AppContext {
|
||||
static late BuildContext _context;
|
||||
|
||||
AppContext._();
|
||||
|
||||
///私有构造函数,防止外部实例化
|
||||
static void setContent(BuildContext context) {
|
||||
_context = context;
|
||||
}
|
||||
|
||||
///获取全局上下文
|
||||
static BuildContext get context => _context;
|
||||
|
||||
///获取主题
|
||||
static TextTheme get textTheme => Theme.of(_context).textTheme;
|
||||
static ColorScheme get colorScheme => Theme.of(_context).colorScheme;
|
||||
|
||||
///页面内间距
|
||||
static double get pagePadding => 15;
|
||||
}
|
||||
19
lib/config/env.dart
Normal file
19
lib/config/env.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
///环境配置
|
||||
class Config {
|
||||
Config._();
|
||||
|
||||
///获取环境
|
||||
static String getEnv() {
|
||||
const env = String.fromEnvironment('ENV', defaultValue: 'dev');
|
||||
return env;
|
||||
}
|
||||
|
||||
///获取接口地址
|
||||
static String baseUrl() {
|
||||
if (getEnv() == 'dev') {
|
||||
return 'https://skin-api.curain.ai/api';
|
||||
} else {
|
||||
return 'https://skin-api.curain.ai/api';
|
||||
}
|
||||
}
|
||||
}
|
||||
13
lib/config/theme/custom_colors.dart
Normal file
13
lib/config/theme/custom_colors.dart
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
///扩展颜色
|
||||
extension CustomColors on ColorScheme {
|
||||
Color get success => const Color(0xff57be80);
|
||||
|
||||
Color get warning => const Color(0xffff9800);
|
||||
|
||||
Color get info => const Color(0xff909399);
|
||||
|
||||
Color get danger => const Color(0xfff44545);
|
||||
}
|
||||
28
lib/config/theme/theme.dart
Normal file
28
lib/config/theme/theme.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
///颜色
|
||||
final scheme = ColorScheme.fromSeed(
|
||||
primary: Color(0xff107870),
|
||||
seedColor: Color(0xff107870),
|
||||
brightness: Brightness.light,
|
||||
//卡片色
|
||||
surface: Colors.white,
|
||||
surfaceContainerLow: Color(0xFFF4F8FB),
|
||||
surfaceContainer: Color(0xFFE9ECF3),
|
||||
surfaceContainerHigh: Color(0xFFDDE2EA),
|
||||
//颜色
|
||||
onSurfaceVariant:Color(0xFF828282)
|
||||
);
|
||||
|
||||
///字体
|
||||
final textTheme = TextTheme(
|
||||
titleLarge: TextStyle(fontSize: 24, fontWeight: FontWeight.w700, color: scheme.onSurface),
|
||||
titleMedium: TextStyle(fontSize: 20, fontWeight: FontWeight.w700, color: scheme.onSurface),
|
||||
titleSmall: TextStyle(fontSize: 16, fontWeight: FontWeight.w700, color: scheme.onSurface),
|
||||
bodyLarge: TextStyle(fontSize: 18),
|
||||
bodyMedium: TextStyle(fontSize: 16),
|
||||
bodySmall: TextStyle(fontSize: 14),
|
||||
labelLarge: TextStyle(fontSize: 16, color: scheme.onSurfaceVariant),
|
||||
labelMedium: TextStyle(fontSize: 14, color: scheme.onSurfaceVariant),
|
||||
labelSmall: TextStyle(fontSize: 12, color: scheme.onSurfaceVariant),
|
||||
);
|
||||
50
lib/data/local/storage.dart
Normal file
50
lib/data/local/storage.dart
Normal file
@@ -0,0 +1,50 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
|
||||
class Storage {
|
||||
|
||||
//存储数据
|
||||
static Future<void> set(String key, dynamic value) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
if (value is String) {
|
||||
sp.setString(key, value);
|
||||
} else if (value is int) {
|
||||
sp.setInt(key, value);
|
||||
} else if (value is bool) {
|
||||
sp.setBool(key, value);
|
||||
} else if (value is double) {
|
||||
sp.setDouble(key, value);
|
||||
} else if (value is Map) {
|
||||
String jsonStr = jsonEncode(value);
|
||||
sp.setString(key, jsonStr);
|
||||
}
|
||||
}
|
||||
|
||||
//获取数据
|
||||
static Future<dynamic> get(String key) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
var value = sp.get(key);
|
||||
if (value is String) {
|
||||
try {
|
||||
return jsonDecode(value);
|
||||
} catch (e) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
//删除数据
|
||||
static Future<void> remove(key) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
sp.remove(key);
|
||||
}
|
||||
|
||||
//判断键是否存在
|
||||
static Future<bool> hasKey(String key) async {
|
||||
SharedPreferences sp = await SharedPreferences.getInstance();
|
||||
return sp.containsKey(key);
|
||||
}
|
||||
}
|
||||
7
lib/data/models/other_login_type.dart
Normal file
7
lib/data/models/other_login_type.dart
Normal file
@@ -0,0 +1,7 @@
|
||||
enum OtherLoginType {
|
||||
google('google'),
|
||||
apple('apple');
|
||||
|
||||
const OtherLoginType(this.value);
|
||||
final String value;
|
||||
}
|
||||
22
lib/data/models/skin_check_status.dart
Normal file
22
lib/data/models/skin_check_status.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
enum SkinCheckStatus {
|
||||
/// 正常
|
||||
normal(1),
|
||||
|
||||
/// 警告
|
||||
warning(2),
|
||||
|
||||
/// 危险
|
||||
danger(3),
|
||||
|
||||
/// 未知
|
||||
unknown(0);
|
||||
|
||||
final int value;
|
||||
|
||||
const SkinCheckStatus(this.value);
|
||||
|
||||
/// 根据 int 值返回对应的枚举,默认返回 online
|
||||
static SkinCheckStatus fromValue(int value) {
|
||||
return SkinCheckStatus.values.firstWhere((e) => e.value == value, orElse: () => SkinCheckStatus.unknown);
|
||||
}
|
||||
}
|
||||
69
lib/layout/layout_page.dart
Normal file
69
lib/layout/layout_page.dart
Normal file
@@ -0,0 +1,69 @@
|
||||
import 'package:derma_flutter/page/record/list/record_list_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import '../page/education/list/education_list_page.dart';
|
||||
import '../page/home/home_page.dart';
|
||||
import 'tabbar.dart';
|
||||
|
||||
class LayoutPage extends StatefulWidget {
|
||||
const LayoutPage({super.key});
|
||||
|
||||
@override
|
||||
State<LayoutPage> createState() => _LayoutPageState();
|
||||
}
|
||||
|
||||
class _LayoutPageState extends State<LayoutPage> {
|
||||
///分页
|
||||
final PageController _pageController = PageController(initialPage: 1);
|
||||
|
||||
int get currentPage {
|
||||
if (!_pageController.hasClients) return 1; // 没 attach 直接 0
|
||||
return _pageController.page?.round() ?? 1;
|
||||
}
|
||||
|
||||
//tabbar列表
|
||||
final List<PageItem> _pages = [
|
||||
PageItem(
|
||||
name: "record",
|
||||
icon: RemixIcons.history_line,
|
||||
page: RecordListPage(),
|
||||
),
|
||||
PageItem(
|
||||
name: "Home",
|
||||
icon: RemixIcons.home_2_line,
|
||||
page: HomePage(),
|
||||
),
|
||||
PageItem(
|
||||
name: "Home",
|
||||
icon: RemixIcons.book_open_line,
|
||||
page: EducationListPage(),
|
||||
),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: PageView(
|
||||
controller: _pageController,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
children: _pages.map((item) => item.page).toList(),
|
||||
),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
currentIndex: currentPage,
|
||||
onTap: (index) {
|
||||
_pageController.jumpToPage(index);
|
||||
setState(() {});
|
||||
},
|
||||
items: _pages.map((item) {
|
||||
return BottomNavigationBarItem(
|
||||
icon: Icon(item.icon),
|
||||
label: item.name,
|
||||
);
|
||||
}).toList(),
|
||||
showSelectedLabels: false,
|
||||
showUnselectedLabels: false,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
10
lib/layout/tabbar.dart
Normal file
10
lib/layout/tabbar.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class PageItem {
|
||||
final String name;
|
||||
final IconData icon;
|
||||
final Widget page;
|
||||
|
||||
PageItem({required this.name, required this.icon, required this.page});
|
||||
}
|
||||
|
||||
55
lib/main.dart
Normal file
55
lib/main.dart
Normal file
@@ -0,0 +1,55 @@
|
||||
import 'package:derma_flutter/router/routes.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import 'config/theme/theme.dart';
|
||||
import 'providers/app_store.dart';
|
||||
|
||||
void main() {
|
||||
runApp(
|
||||
MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(create: (context) => AppStore()),
|
||||
],
|
||||
child: MyApp(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ScreenUtilInit(
|
||||
designSize: const Size(375, 694),
|
||||
useInheritedMediaQuery: true,
|
||||
child: MaterialApp.router(
|
||||
debugShowCheckedModeBanner: false,
|
||||
routerConfig: goRouter,
|
||||
localizationsDelegates: [],
|
||||
themeMode: ThemeMode.light,
|
||||
theme: ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: scheme,
|
||||
elevatedButtonTheme: ElevatedButtonThemeData(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: scheme.primary,
|
||||
foregroundColor: scheme.onPrimary,
|
||||
),
|
||||
),
|
||||
textTheme: textTheme,
|
||||
scaffoldBackgroundColor: Color(0xffFAFAFE),
|
||||
appBarTheme: AppBarTheme(
|
||||
backgroundColor: scheme.surface,
|
||||
scrolledUnderElevation: 0,
|
||||
titleTextStyle: textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
builder: EasyLoading.init(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
63
lib/page/education/detail/education_detail_page.dart
Normal file
63
lib/page/education/detail/education_detail_page.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:markdown_widget/markdown_widget.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
|
||||
import '../../../api/dto/article_detail_dto.dart';
|
||||
import '../../../api/endpoints/skin_api.dart';
|
||||
|
||||
class EducationDetailPage extends StatefulWidget {
|
||||
final String id;
|
||||
|
||||
const EducationDetailPage({super.key, required this.id});
|
||||
|
||||
@override
|
||||
State<EducationDetailPage> createState() => _EducationDetailPageState();
|
||||
}
|
||||
|
||||
class _EducationDetailPageState extends State<EducationDetailPage> {
|
||||
ArticleDetailDto? _detailDto;
|
||||
bool _loading = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_init();
|
||||
}
|
||||
|
||||
void _init() async {
|
||||
var res = await articleDetailApi(widget.id);
|
||||
setState(() {
|
||||
_detailDto = res;
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_detailDto?.title ?? ""),
|
||||
),
|
||||
body: Skeletonizer(
|
||||
enabled: _loading,
|
||||
child: _loading
|
||||
? ListView.builder(
|
||||
padding: EdgeInsets.all(15),
|
||||
itemBuilder: (context, index) {
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 6),
|
||||
height: 14,
|
||||
width: double.infinity,
|
||||
color: Colors.grey[300],
|
||||
);
|
||||
},
|
||||
itemCount: 10,
|
||||
)
|
||||
: MarkdownWidget(
|
||||
padding: EdgeInsets.all(15),
|
||||
data: _detailDto?.content ?? "",
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
103
lib/page/education/list/education_list_page.dart
Normal file
103
lib/page/education/list/education_list_page.dart
Normal file
@@ -0,0 +1,103 @@
|
||||
import 'package:derma_flutter/api/dto/article_dto.dart';
|
||||
import 'package:derma_flutter/api/endpoints/skin_api.dart';
|
||||
import 'package:derma_flutter/widgets/common/app_backend.dart';
|
||||
import 'package:derma_flutter/widgets/ui_kit/empty/index.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../../router/config/route_paths.dart';
|
||||
|
||||
class EducationListPage extends StatefulWidget {
|
||||
const EducationListPage({super.key});
|
||||
|
||||
@override
|
||||
State<EducationListPage> createState() => _EducationListPageState();
|
||||
}
|
||||
|
||||
class _EducationListPageState extends State<EducationListPage> {
|
||||
var _loading = false;
|
||||
final List<ArticleDto> _list = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_init();
|
||||
}
|
||||
|
||||
void _init() async {
|
||||
setState(() {
|
||||
_loading = true;
|
||||
});
|
||||
var list = await articleListApi();
|
||||
setState(() {
|
||||
_list.clear();
|
||||
_list.addAll(list);
|
||||
_loading = false;
|
||||
});
|
||||
}
|
||||
|
||||
void _handToDetail(ArticleDto item) {
|
||||
context.push(RoutePaths.articleDetail(item.id));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Skin Health Education"),
|
||||
),
|
||||
body: AppBackend(
|
||||
child: SafeArea(
|
||||
child: Visibility(
|
||||
visible: !_loading && _list.isNotEmpty,
|
||||
replacement: Empty(),
|
||||
child: ListView.separated(
|
||||
itemBuilder: (context, index) {
|
||||
var item = _list[index];
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
_handToDetail(item);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color(0xffE9E9E9),
|
||||
spreadRadius: 2,
|
||||
blurRadius: 9,
|
||||
offset: Offset(1, 2), // changes position of shadow
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(item.title ?? ''),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 5),
|
||||
child: Text(
|
||||
item.subtitle ?? "",
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
separatorBuilder: (context, index) {
|
||||
return Container(
|
||||
height: 15,
|
||||
);
|
||||
},
|
||||
itemCount: _list.length,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
76
lib/page/home/home_page.dart
Normal file
76
lib/page/home/home_page.dart
Normal file
@@ -0,0 +1,76 @@
|
||||
import 'package:derma_flutter/router/config/route_paths.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
import '../../api/endpoints/skin_api.dart';
|
||||
import '../../widgets/common/app_backend.dart';
|
||||
import '../../widgets/common/app_header.dart';
|
||||
import 'widget/tip_widget.dart';
|
||||
import 'widget/upload_widget.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
const HomePage({super.key});
|
||||
|
||||
@override
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> with AutomaticKeepAliveClientMixin {
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
|
||||
///打开相机拍照
|
||||
void _handTakePhoto() async {
|
||||
var photo = await _picker.pickImage(source: ImageSource.camera);
|
||||
if (photo != null) {
|
||||
_startDetect(photo.path);
|
||||
}
|
||||
}
|
||||
|
||||
///选择图片
|
||||
void _handPickImage() async {
|
||||
var result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.image,
|
||||
allowMultiple: false,
|
||||
);
|
||||
if (result != null) {
|
||||
_startDetect(result.files[0].path!);
|
||||
}
|
||||
}
|
||||
|
||||
///开始检测
|
||||
void _startDetect(String path) async {
|
||||
EasyLoading.show(
|
||||
status: 'Skin analysis in progress, please wait...',
|
||||
maskType: EasyLoadingMaskType.clear,
|
||||
);
|
||||
var res = await skinDetectApi(path);
|
||||
EasyLoading.dismiss();
|
||||
context.push(RoutePaths.detail, extra: res);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: AppBackend(
|
||||
child: Column(
|
||||
children: [
|
||||
AppHeader(),
|
||||
UploadBox(
|
||||
onPhoto: _handTakePhoto,
|
||||
onSelect: _handPickImage,
|
||||
),
|
||||
TipBox(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
57
lib/page/home/widget/tip_widget.dart
Normal file
57
lib/page/home/widget/tip_widget.dart
Normal file
@@ -0,0 +1,57 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TipBox extends StatelessWidget {
|
||||
TipBox({super.key});
|
||||
|
||||
final List<String> tips = [
|
||||
"Ensure good lighting",
|
||||
"Keep the camera steady",
|
||||
"Fill the frame with the skin area",
|
||||
"Avoid shadows and glare",
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
margin: EdgeInsets.only(top: 20),
|
||||
padding: EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Theme.of(context).cardColor,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color(0xffE9E9E9),
|
||||
spreadRadius: 2,
|
||||
blurRadius: 9,
|
||||
offset: Offset(1, 2), // changes position of shadow
|
||||
),
|
||||
],
|
||||
),
|
||||
child: DefaultTextStyle(
|
||||
style: TextStyle(color: Color(0xff1A8C8C)),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"Tips:",
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
color: Color(0xff1A8C8C),
|
||||
),
|
||||
),
|
||||
ListView.builder(
|
||||
itemExtent: 25,
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
padding: EdgeInsets.all(10),
|
||||
itemBuilder: (_, index) {
|
||||
return Text("-${tips[index]}.");
|
||||
},
|
||||
itemCount: tips.length,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
117
lib/page/home/widget/upload_widget.dart
Normal file
117
lib/page/home/widget/upload_widget.dart
Normal file
@@ -0,0 +1,117 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
class UploadBox extends StatelessWidget {
|
||||
final Function() onSelect;
|
||||
final Function() onPhoto;
|
||||
|
||||
const UploadBox({
|
||||
super.key,
|
||||
required this.onSelect,
|
||||
required this.onPhoto,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(top: 30),
|
||||
width: double.infinity,
|
||||
height: 350,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color(0xffE9E9E9),
|
||||
spreadRadius: 2,
|
||||
blurRadius: 9,
|
||||
offset: Offset(1, 2), // changes position of shadow
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
child: Image.asset(
|
||||
"assets/image/bg_hushi.png",
|
||||
width: 0.7.sw,
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
left: 0,
|
||||
top: 0,
|
||||
right: 0,
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
child: Text(
|
||||
"Take a clear photo of the skin area you’d like to analyze.Our AI will provide instant health insights.",
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: Column(
|
||||
spacing: 20,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
"Analyze Your Skin",
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
_btn(
|
||||
colors: [Color(0xff107870), Color(0xff1EDECF)],
|
||||
title: "Take photo",
|
||||
onTap: (){
|
||||
onPhoto();
|
||||
},
|
||||
),
|
||||
_btn(
|
||||
colors: [Color(0xffFFFFFF), Color(0xffC6C6C6)],
|
||||
title: "Upload Photo",
|
||||
textColor: Color(0xff000000),
|
||||
onTap: (){
|
||||
onSelect();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _btn({
|
||||
required List<Color> colors,
|
||||
Color textColor = Colors.white,
|
||||
required String title,
|
||||
required Function() onTap,
|
||||
}) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: 120,
|
||||
height: 38,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
gradient: LinearGradient(
|
||||
colors: colors,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: textColor,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
63
lib/page/record/detail/record_detail_page.dart
Normal file
63
lib/page/record/detail/record_detail_page.dart
Normal file
@@ -0,0 +1,63 @@
|
||||
import 'package:derma_flutter/api/dto/skin_check_dto.dart';
|
||||
import 'package:derma_flutter/data/models/skin_check_status.dart';
|
||||
import 'package:derma_flutter/page/record/detail/widget/error_box.dart';
|
||||
import 'package:derma_flutter/page/record/detail/widget/warning_box.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
|
||||
import 'widget/success_box.dart';
|
||||
|
||||
class RecordDetailPage extends StatefulWidget {
|
||||
final SkinCheckDto data;
|
||||
|
||||
// final String id;
|
||||
|
||||
const RecordDetailPage({super.key, required this.data});
|
||||
|
||||
@override
|
||||
State<RecordDetailPage> createState() => _RecordDetailPageState();
|
||||
}
|
||||
|
||||
class _RecordDetailPageState extends State<RecordDetailPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
systemOverlayStyle: const SystemUiOverlayStyle(
|
||||
statusBarIconBrightness: Brightness.dark,
|
||||
),
|
||||
),
|
||||
body: Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.only(left: 15, right: 15, top: 0.05.sh, bottom: 15),
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
switch (widget.data.skinStatus) {
|
||||
case SkinCheckStatus.normal:
|
||||
return SuccessBox(data: widget.data);
|
||||
case SkinCheckStatus.warning:
|
||||
return WarningBox(
|
||||
data: widget.data,
|
||||
);
|
||||
case SkinCheckStatus.danger:
|
||||
return ErrorBox(
|
||||
data: widget.data,
|
||||
);
|
||||
case SkinCheckStatus.unknown:
|
||||
return SizedBox();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
88
lib/page/record/detail/widget/common_box.dart
Normal file
88
lib/page/record/detail/widget/common_box.dart
Normal file
@@ -0,0 +1,88 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class StatusBox extends StatelessWidget {
|
||||
final Color color;
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String desc;
|
||||
|
||||
const StatusBox({
|
||||
super.key,
|
||||
required this.color,
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.desc,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: Colors.white,
|
||||
size: 50,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 10),
|
||||
child: Text(
|
||||
title,
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
color: color,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 5),
|
||||
child: Text(
|
||||
desc,
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CardBox extends StatelessWidget {
|
||||
final Widget child;
|
||||
|
||||
const CardBox({
|
||||
super.key,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(15),
|
||||
margin: const EdgeInsets.only(top: 15),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).cardColor,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
child: Text(
|
||||
"Detected Signs:",
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
child
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
45
lib/page/record/detail/widget/error_box.dart
Normal file
45
lib/page/record/detail/widget/error_box.dart
Normal file
@@ -0,0 +1,45 @@
|
||||
import 'package:derma_flutter/api/dto/skin_check_dto.dart';
|
||||
import 'package:derma_flutter/config/theme/custom_colors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import 'common_box.dart';
|
||||
|
||||
class ErrorBox extends StatefulWidget {
|
||||
final SkinCheckDto data;
|
||||
const ErrorBox({super.key, required this.data});
|
||||
|
||||
@override
|
||||
State<ErrorBox> createState() => _ErrorBoxState();
|
||||
}
|
||||
|
||||
class _ErrorBoxState extends State<ErrorBox> {
|
||||
void _handBack() {
|
||||
context.pop();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
StatusBox(
|
||||
color: Theme.of(context).colorScheme.error,
|
||||
icon: RemixIcons.alert_fill,
|
||||
title: "Need to see a doctor",
|
||||
desc: "Your skin shows signs of concern that require attention.Please visit the hospital for examination immediately.",
|
||||
),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 45,
|
||||
margin: const EdgeInsets.only(top: 50),
|
||||
child: ElevatedButton(
|
||||
onPressed: _handBack,
|
||||
child: Text("Know"),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
67
lib/page/record/detail/widget/success_box.dart
Normal file
67
lib/page/record/detail/widget/success_box.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
import 'package:derma_flutter/api/dto/skin_check_dto.dart';
|
||||
import 'package:derma_flutter/config/theme/custom_colors.dart';
|
||||
import 'package:derma_flutter/page/record/detail/widget/common_box.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
class SuccessBox extends StatefulWidget {
|
||||
final SkinCheckDto data;
|
||||
|
||||
const SuccessBox({super.key, required this.data});
|
||||
|
||||
@override
|
||||
State<SuccessBox> createState() => _SuccessBoxState();
|
||||
}
|
||||
|
||||
class _SuccessBoxState extends State<SuccessBox> {
|
||||
void _handBack() {
|
||||
context.pop();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
StatusBox(
|
||||
color: Theme.of(context).colorScheme.success,
|
||||
icon: RemixIcons.check_fill,
|
||||
title: "Healthy Skin",
|
||||
desc: "Your skin appears to be in good condition.",
|
||||
),
|
||||
CardBox(
|
||||
child: Wrap(
|
||||
spacing: 10,
|
||||
runSpacing: 10,
|
||||
children: widget.data.tags.map((item) {
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 3, horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.success.withValues(alpha: 0.3),
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
),
|
||||
child: Text(
|
||||
item,
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.success,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
|
||||
Container(
|
||||
width: double.infinity,
|
||||
height: 45,
|
||||
margin: const EdgeInsets.only(top: 50),
|
||||
child: ElevatedButton(
|
||||
onPressed: _handBack,
|
||||
child: Text("Return"),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
93
lib/page/record/detail/widget/warning_box.dart
Normal file
93
lib/page/record/detail/widget/warning_box.dart
Normal file
@@ -0,0 +1,93 @@
|
||||
import 'package:derma_flutter/api/dto/skin_check_dto.dart';
|
||||
import 'package:derma_flutter/api/endpoints/skin_api.dart';
|
||||
import 'package:derma_flutter/config/theme/custom_colors.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import 'common_box.dart';
|
||||
|
||||
class WarningBox extends StatefulWidget {
|
||||
final SkinCheckDto data;
|
||||
|
||||
const WarningBox({super.key, required this.data});
|
||||
|
||||
@override
|
||||
State<WarningBox> createState() => _WarningBoxState();
|
||||
}
|
||||
|
||||
class _WarningBoxState extends State<WarningBox> {
|
||||
final _emailController = TextEditingController();
|
||||
|
||||
///提交
|
||||
void _handSubmit() async {
|
||||
if (_emailController.text.isEmpty) {
|
||||
EasyLoading.showToast("Contact email is required");
|
||||
return;
|
||||
}
|
||||
EasyLoading.show(status: 'Sending request...');
|
||||
await skinContactApi(widget.data.id!, _emailController.text);
|
||||
EasyLoading.dismiss();
|
||||
context.pop();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () => FocusScope.of(context).unfocus(),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
StatusBox(
|
||||
color: Theme.of(context).colorScheme.warning,
|
||||
icon: RemixIcons.error_warning_fill,
|
||||
title: "Troubled Skin",
|
||||
desc: widget.data.concise ?? "",
|
||||
),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(top: 20),
|
||||
child: Text(
|
||||
"Find out more:",
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(top: 10),
|
||||
child: Text(
|
||||
"We will contact you shortly.Please check your e-mail promptly for further information.",
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(top: 10),
|
||||
child: Text(
|
||||
"Please confirm/enter your e-mail address:",
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(top: 15),
|
||||
child: TextField(
|
||||
controller: _emailController,
|
||||
decoration: InputDecoration(
|
||||
hintText: "Email",
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
margin: const EdgeInsets.only(top: 60),
|
||||
height: 45,
|
||||
child: ElevatedButton(
|
||||
onPressed: _handSubmit,
|
||||
child: Text("Continue"),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
151
lib/page/record/list/record_list_page.dart
Normal file
151
lib/page/record/list/record_list_page.dart
Normal file
@@ -0,0 +1,151 @@
|
||||
import 'package:derma_flutter/api/dto/record_list_dto.dart';
|
||||
import 'package:derma_flutter/api/endpoints/skin_api.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../widgets/ui_kit/empty/index.dart';
|
||||
import 'widget/item_widget.dart';
|
||||
|
||||
class RecordListPage extends StatefulWidget {
|
||||
const RecordListPage({super.key});
|
||||
|
||||
@override
|
||||
State<RecordListPage> createState() => _RecordListPageState();
|
||||
}
|
||||
|
||||
class _RecordListPageState extends State<RecordListPage> with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
|
||||
//tab
|
||||
late TabController _tabController;
|
||||
List<TabItem> tabList = [
|
||||
TabItem(name: "All", value: 0),
|
||||
TabItem(name: "Healthy", value: 1),
|
||||
TabItem(name: "Unhealthy", value: 2),
|
||||
];
|
||||
|
||||
//列表
|
||||
List<RecordItemDto> _recordList = [];
|
||||
var _isEnd = false;
|
||||
var _isLoading = false;
|
||||
|
||||
///滚动监听器
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: tabList.length, vsync: this);
|
||||
_tabController.addListener(_onTabChange);
|
||||
_scrollController.addListener(_onScroll);
|
||||
_onRefresh();
|
||||
}
|
||||
|
||||
///监听列表滚动
|
||||
void _onScroll() {
|
||||
final maxExtent = _scrollController.position.maxScrollExtent;
|
||||
final current = _scrollController.position.pixels;
|
||||
const threshold = 15;
|
||||
if (current >= maxExtent - threshold) {
|
||||
_fetchList();
|
||||
}
|
||||
}
|
||||
|
||||
///tab改变
|
||||
void _onTabChange() {
|
||||
if (!_tabController.indexIsChanging) {
|
||||
_onRefresh();
|
||||
}
|
||||
}
|
||||
|
||||
///刷新
|
||||
Future<void> _onRefresh() async {
|
||||
_isEnd = false;
|
||||
await _fetchList(refresh: true);
|
||||
}
|
||||
|
||||
///获取数据
|
||||
Future<void> _fetchList({bool refresh = false}) async {
|
||||
const pageSize = 20;
|
||||
int page = refresh ? 1 : (_recordList.length / pageSize).ceil() + 1;
|
||||
if (!_isLoading && !_isEnd) {
|
||||
setState(() => _isLoading = true);
|
||||
var type = tabList[_tabController.index].value;
|
||||
var res = await skinRecordApi(
|
||||
page: page,
|
||||
pageSize: pageSize,
|
||||
query: {"skin_status": type},
|
||||
);
|
||||
|
||||
setState(() {
|
||||
_isEnd = res.list!.length < pageSize;
|
||||
if (refresh) {
|
||||
_recordList.clear();
|
||||
}
|
||||
_recordList.addAll(res.list!);
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Analysis History"),
|
||||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
dividerColor: Colors.transparent,
|
||||
tabs: tabList.map((item) {
|
||||
return Tab(text: item.name);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () => _onRefresh(),
|
||||
child: Visibility(
|
||||
visible: !_isLoading && _recordList.isEmpty,
|
||||
replacement: ListView(
|
||||
controller: _scrollController,
|
||||
padding: EdgeInsets.all(15),
|
||||
children: [
|
||||
..._recordList.map((item) {
|
||||
return ItemWidget(data: item);
|
||||
}),
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 10),
|
||||
child: Visibility(
|
||||
visible: _isLoading,
|
||||
replacement: Center(child: Text("已加载完毕", style: Theme.of(context).textTheme.labelSmall)),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 12,
|
||||
height: 12,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 1,
|
||||
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
Text("加载中...", style: Theme.of(context).textTheme.labelSmall),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Empty(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
}
|
||||
|
||||
class TabItem {
|
||||
final String name;
|
||||
final int value;
|
||||
|
||||
const TabItem({required this.name, required this.value});
|
||||
}
|
||||
113
lib/page/record/list/widget/item_widget.dart
Normal file
113
lib/page/record/list/widget/item_widget.dart
Normal file
@@ -0,0 +1,113 @@
|
||||
import 'package:derma_flutter/api/dto/record_list_dto.dart';
|
||||
import 'package:derma_flutter/config/theme/custom_colors.dart';
|
||||
import 'package:derma_flutter/router/config/route_paths.dart';
|
||||
import 'package:derma_flutter/utils/format.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
class ItemWidget extends StatefulWidget {
|
||||
final RecordItemDto data;
|
||||
|
||||
const ItemWidget({super.key, required this.data});
|
||||
|
||||
@override
|
||||
State<ItemWidget> createState() => _ItemWidgetState();
|
||||
}
|
||||
|
||||
class _ItemWidgetState extends State<ItemWidget> {
|
||||
void _handToDetail() {
|
||||
context.push(RoutePaths.detail, extra: widget.data.result);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var color = Colors.black;
|
||||
|
||||
switch (widget.data.skinStatus) {
|
||||
case 1:
|
||||
color = Theme.of(context).colorScheme.success;
|
||||
break;
|
||||
case 2:
|
||||
color = Theme.of(context).colorScheme.warning;
|
||||
break;
|
||||
case 3:
|
||||
color = Theme.of(context).colorScheme.error;
|
||||
break;
|
||||
default:
|
||||
color = Colors.black;
|
||||
}
|
||||
|
||||
return InkWell(
|
||||
onTap: _handToDetail,
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(15),
|
||||
margin: EdgeInsets.only(bottom: 15),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Theme.of(context).colorScheme.surface,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Color(0xffE9E9E9),
|
||||
spreadRadius: 2,
|
||||
blurRadius: 9,
|
||||
offset: Offset(1, 2), // changes position of shadow
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.only(bottom: 10),
|
||||
child: Text("Recent Analyses"),
|
||||
),
|
||||
Row(
|
||||
spacing: 15,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
clipBehavior: Clip.hardEdge,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Image.network(
|
||||
widget.data.imageUrl!,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(color: Theme.of(context).colorScheme.surfaceContainer),
|
||||
child: Icon(RemixIcons.error_warning_fill),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 5),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"health",
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: color),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 5),
|
||||
child: Text(
|
||||
formatDateUS(widget.data.createdAt),
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
23
lib/page/system/agree/agree_page.dart
Normal file
23
lib/page/system/agree/agree_page.dart
Normal 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)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
115
lib/page/system/login/login_code_page.dart
Normal file
115
lib/page/system/login/login_code_page.dart
Normal 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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
236
lib/page/system/login/login_page.dart
Normal file
236
lib/page/system/login/login_page.dart
Normal 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;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
77
lib/page/system/login/widget/agreement_box.dart
Normal file
77
lib/page/system/login/widget/agreement_box.dart
Normal 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"},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
166
lib/page/system/login/widget/widget.dart
Normal file
166
lib/page/system/login/widget/widget.dart
Normal 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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
65
lib/page/system/splash/splash_page.dart
Normal file
65
lib/page/system/splash/splash_page.dart
Normal 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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
48
lib/providers/app_store.dart
Normal file
48
lib/providers/app_store.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
import 'package:derma_flutter/api/dto/login_dto.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../data/local/storage.dart';
|
||||
|
||||
class AppStore with ChangeNotifier {
|
||||
///用户信息
|
||||
UserInfo? userInfo;
|
||||
|
||||
///token
|
||||
String token = '';
|
||||
|
||||
//初始化
|
||||
Future<void> init() async {
|
||||
token = await getToken();
|
||||
var userInfoStorage = await Storage.get('userInfo');
|
||||
if(userInfoStorage != null){
|
||||
userInfo = UserInfo.fromJson(await Storage.get('userInfo'));
|
||||
}
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
///设置用户数据
|
||||
Future<void> setInfo(LoginDto data) async {
|
||||
token = data.accessToken!;
|
||||
userInfo = data.userInfo;
|
||||
|
||||
await Storage.set('userInfo', userInfo?.toJson());
|
||||
await Storage.set('token', token);
|
||||
|
||||
}
|
||||
|
||||
|
||||
///获取token
|
||||
static Future<String> getToken() async {
|
||||
return await Storage.get("token") ?? '';
|
||||
}
|
||||
|
||||
///退出登录
|
||||
Future<void> logout() async {
|
||||
await Storage.remove('token');
|
||||
await Storage.remove('userInfo');
|
||||
token = '';
|
||||
userInfo = null;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
22
lib/router/config/route_paths.dart
Normal file
22
lib/router/config/route_paths.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
class RoutePaths {
|
||||
RoutePaths._();
|
||||
|
||||
///闪烁页
|
||||
static const splash = "/";
|
||||
///协议页
|
||||
static const agreement = "/agreement";
|
||||
///登录
|
||||
static const login = "/login";
|
||||
|
||||
///登陆验证码
|
||||
static const loginCode = "/loginCode";
|
||||
|
||||
///首页
|
||||
static const layout = "/layout";
|
||||
|
||||
///预约详情
|
||||
static const detail = "/detail";
|
||||
|
||||
///文章详情
|
||||
static String articleDetail([int? id]) => id != null ? "/articleDetail/$id" : "/articleDetail/:id";
|
||||
}
|
||||
16
lib/router/config/route_type.dart
Normal file
16
lib/router/config/route_type.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class RouteType {
|
||||
String path;
|
||||
FutureOr<String?> Function(BuildContext, GoRouterState)? redirect;
|
||||
Widget Function(GoRouterState) child;
|
||||
|
||||
RouteType({
|
||||
required this.path,
|
||||
required this.child,
|
||||
this.redirect,
|
||||
});
|
||||
}
|
||||
49
lib/router/modules/base.dart
Normal file
49
lib/router/modules/base.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
import 'package:derma_flutter/layout/layout_page.dart';
|
||||
import 'package:derma_flutter/page/system/login/login_code_page.dart';
|
||||
import 'package:derma_flutter/page/system/splash/splash_page.dart';
|
||||
import 'package:derma_flutter/router/config/route_paths.dart';
|
||||
|
||||
import '../../page/system/agree/agree_page.dart';
|
||||
import '../../page/system/login/login_page.dart';
|
||||
import '../config/route_type.dart';
|
||||
|
||||
List<RouteType> baseRoutes = [
|
||||
RouteType(
|
||||
path: RoutePaths.splash,
|
||||
child: (state) {
|
||||
return SplashPage();
|
||||
},
|
||||
),
|
||||
RouteType(
|
||||
path: RoutePaths.agreement,
|
||||
child: (state) {
|
||||
final extra = state.extra as Map<String, String>;
|
||||
return AgreePage(
|
||||
title: extra['title'] ?? "",
|
||||
url: extra['url'] ?? "",
|
||||
);
|
||||
},
|
||||
),
|
||||
RouteType(
|
||||
path: RoutePaths.login,
|
||||
child: (state) {
|
||||
return LoginPage();
|
||||
},
|
||||
),
|
||||
RouteType(
|
||||
path: RoutePaths.loginCode,
|
||||
child: (state) {
|
||||
final args = state.extra as Map;
|
||||
return LoginCodePage(
|
||||
email: args['email'],
|
||||
password: args['password'],
|
||||
);
|
||||
},
|
||||
),
|
||||
RouteType(
|
||||
path: RoutePaths.layout,
|
||||
child: (state) {
|
||||
return LayoutPage();
|
||||
},
|
||||
),
|
||||
];
|
||||
28
lib/router/modules/serve.dart
Normal file
28
lib/router/modules/serve.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:derma_flutter/api/dto/skin_check_dto.dart';
|
||||
import 'package:derma_flutter/page/education/detail/education_detail_page.dart';
|
||||
import 'package:derma_flutter/page/record/detail/record_detail_page.dart';
|
||||
|
||||
import '../config/route_paths.dart';
|
||||
import '../config/route_type.dart';
|
||||
|
||||
List<RouteType> serverRoutes = [
|
||||
RouteType(
|
||||
path: RoutePaths.detail,
|
||||
child: (state) {
|
||||
// final params = state.pathParameters;
|
||||
final extra = state.extra! as SkinCheckDto;
|
||||
return RecordDetailPage(
|
||||
data: extra,
|
||||
);
|
||||
},
|
||||
),
|
||||
RouteType(
|
||||
path: RoutePaths.articleDetail(),
|
||||
child: (state) {
|
||||
final params = state.pathParameters;
|
||||
return EducationDetailPage(
|
||||
id: params['id']!,
|
||||
);
|
||||
},
|
||||
),
|
||||
];
|
||||
28
lib/router/routes.dart
Normal file
28
lib/router/routes.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import 'modules/base.dart';
|
||||
import 'config/route_paths.dart';
|
||||
import 'config/route_type.dart';
|
||||
import 'modules/serve.dart';
|
||||
|
||||
GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
List<RouteType> routeConfigs = [...baseRoutes, ...serverRoutes];
|
||||
|
||||
//for循环遍历
|
||||
List<RouteBase> routes = routeConfigs.map((item) {
|
||||
return GoRoute(
|
||||
path: item.path,
|
||||
builder: (context, state) {
|
||||
return item.child(state);
|
||||
},
|
||||
);
|
||||
}).toList();
|
||||
|
||||
//变量命名
|
||||
GoRouter goRouter = GoRouter(
|
||||
initialLocation: RoutePaths.splash,
|
||||
routes: routes,
|
||||
navigatorKey: navigatorKey,
|
||||
);
|
||||
35
lib/utils/format.dart
Normal file
35
lib/utils/format.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
/// 格式化日期时间
|
||||
String formatDateUS(dynamic date, [String format = 'MM/DD/YYYY hh:mm:ss a']) {
|
||||
DateTime dateTime;
|
||||
|
||||
if (date is String) {
|
||||
dateTime = DateTime.tryParse(date) ?? DateTime.now();
|
||||
} else if (date is DateTime) {
|
||||
dateTime = date;
|
||||
} else {
|
||||
dateTime = DateTime.now();
|
||||
}
|
||||
|
||||
final yyyy = dateTime.year.toString();
|
||||
final MM = dateTime.month.toString().padLeft(2, '0');
|
||||
final dd = dateTime.day.toString().padLeft(2, '0');
|
||||
|
||||
// 12小时制
|
||||
final hour12 = (dateTime.hour % 12 == 0 ? 12 : dateTime.hour % 12).toString().padLeft(2, '0');
|
||||
final HH = dateTime.hour.toString().padLeft(2, '0'); // 24小时制备用
|
||||
final mm = dateTime.minute.toString().padLeft(2, '0');
|
||||
final ss = dateTime.second.toString().padLeft(2, '0');
|
||||
final ampm = dateTime.hour >= 12 ? 'PM' : 'AM';
|
||||
|
||||
String result = format
|
||||
.replaceFirst(RegExp('YYYY'), yyyy)
|
||||
.replaceFirst(RegExp('MM'), MM)
|
||||
.replaceFirst(RegExp('DD'), dd)
|
||||
.replaceFirst(RegExp('hh'), hour12)
|
||||
.replaceFirst(RegExp('HH'), HH)
|
||||
.replaceFirst(RegExp('mm'), mm)
|
||||
.replaceFirst(RegExp('ss'), ss)
|
||||
.replaceFirst(RegExp('a'), ampm);
|
||||
|
||||
return result;
|
||||
}
|
||||
28
lib/widgets/common/app_backend.dart
Normal file
28
lib/widgets/common/app_backend.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AppBackend extends StatelessWidget {
|
||||
final Widget child;
|
||||
|
||||
const AppBackend({super.key, required this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(15),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Color(0xffFFFFFF),
|
||||
Color(0xffF7fefD),
|
||||
Color(0xffF0FDFA),
|
||||
],
|
||||
stops: [0, 0.6, 1],
|
||||
),
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
80
lib/widgets/common/app_header.dart
Normal file
80
lib/widgets/common/app_header.dart
Normal file
@@ -0,0 +1,80 @@
|
||||
import 'package:derma_flutter/router/config/route_paths.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import '../../providers/app_store.dart';
|
||||
|
||||
class AppHeader extends StatefulWidget {
|
||||
const AppHeader({super.key});
|
||||
|
||||
@override
|
||||
State<AppHeader> createState() => _AppHeaderState();
|
||||
}
|
||||
|
||||
class _AppHeaderState extends State<AppHeader> {
|
||||
void _handLogout() {
|
||||
var appStore = context.read<AppStore>();
|
||||
appStore.logout();
|
||||
context.go(RoutePaths.login);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
Image.asset(
|
||||
"assets/image/logo.png",
|
||||
width: 44,
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"Demacare",
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
Text(
|
||||
"AI Skin Health Analysis",
|
||||
style: Theme.of(context).textTheme.labelSmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
PopupMenuButton(
|
||||
offset: const Offset(0, 50),
|
||||
color: Theme.of(context).cardColor,
|
||||
itemBuilder: (context) {
|
||||
return [
|
||||
PopupMenuItem(
|
||||
onTap: _handLogout,
|
||||
child: Text("Log out"),
|
||||
),
|
||||
];
|
||||
},
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(RemixIcons.user_3_line, color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
84
lib/widgets/ui_kit/button/custom_button.dart
Normal file
84
lib/widgets/ui_kit/button/custom_button.dart
Normal file
@@ -0,0 +1,84 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
///自定义按钮
|
||||
///包括loading功能
|
||||
class CustomButton extends StatelessWidget {
|
||||
final Widget child;
|
||||
final VoidCallback? onPressed;
|
||||
final bool loading;
|
||||
final bool round;
|
||||
final bool disabled;
|
||||
|
||||
const CustomButton({
|
||||
super.key,
|
||||
required this.child,
|
||||
this.onPressed,
|
||||
this.loading = false,
|
||||
this.round = true,
|
||||
this.disabled = false,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
///自定义颜色
|
||||
// switch (size) {
|
||||
// case ButtonSize.small:
|
||||
// height = 28;
|
||||
// loadingSize = 16;
|
||||
// fontSize = 12;
|
||||
// padding = const EdgeInsets.symmetric(horizontal: 12);
|
||||
// break;
|
||||
// case ButtonSize.large:
|
||||
// height = 48;
|
||||
// loadingSize = 24;
|
||||
// fontSize = 18;
|
||||
// padding = const EdgeInsets.symmetric(horizontal: 20);
|
||||
// break;
|
||||
// case ButtonSize.medium:
|
||||
// height = 45;
|
||||
// loadingSize = 15;
|
||||
// fontSize = 16;
|
||||
// padding = const EdgeInsets.symmetric(horizontal: 16);
|
||||
// break;
|
||||
// }
|
||||
|
||||
void handClick() {
|
||||
if (!loading && !disabled) {
|
||||
onPressed?.call();
|
||||
}
|
||||
}
|
||||
|
||||
return Opacity(
|
||||
opacity: disabled ? 0.5 : 1,
|
||||
child: ElevatedButton(
|
||||
onPressed: handClick,
|
||||
style: ElevatedButton.styleFrom(
|
||||
shape: round
|
||||
? const StadiumBorder()
|
||||
: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Visibility(
|
||||
visible: loading,
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(right: 8),
|
||||
child: SizedBox.square(
|
||||
dimension: 15,
|
||||
child: CircularProgressIndicator(
|
||||
color: Colors.white,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child,
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
35
lib/widgets/ui_kit/empty/index.dart
Normal file
35
lib/widgets/ui_kit/empty/index.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../config/app_context.dart';
|
||||
|
||||
class Empty extends StatelessWidget {
|
||||
final String? title;
|
||||
final Widget? child;
|
||||
|
||||
const Empty({super.key, this.title, this.child});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox.expand(
|
||||
child: Align(
|
||||
alignment: const FractionalOffset(0.5, 0.2),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
FractionallySizedBox(
|
||||
widthFactor: 0.5,
|
||||
child: Image.asset("assets/image/empty_data.png"),
|
||||
),
|
||||
if (title != null)
|
||||
Text(
|
||||
title!,
|
||||
style: AppContext.textTheme.labelMedium,
|
||||
),
|
||||
if( child != null)
|
||||
child!
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user