| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715 |
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:get/get.dart';
- import 'package:nomo/app/base/base_view.dart';
- import 'package:nomo/app/widgets/click_opacity.dart';
- import 'package:nomo/app/widgets/ix_app_bar.dart';
- import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
- import 'package:pinput/pinput.dart';
- import '../controllers/deviceauth_controller.dart';
- class DeviceauthView extends BaseView<DeviceauthController> {
- const DeviceauthView({super.key});
- @override
- PreferredSizeWidget? get appBar => IXAppBar(title: 'Device Authorization');
- @override
- Widget buildContent(BuildContext context) {
- return Obx(() {
- final isPremium = controller.isPremium.value;
- return SingleChildScrollView(
- padding: EdgeInsets.symmetric(horizontal: 14.w, vertical: 20.h),
- child: Column(
- children: [
- if (isPremium) ...[
- // VIP用户界面
- _buildVIPUserInterface(),
- ] else ...[
- // 免费用户界面
- _buildFreeUserInterface(),
- ],
- ],
- ),
- );
- });
- }
- /// 免费用户界面 - 显示授权码和等待授权
- Widget _buildFreeUserInterface() {
- return Column(
- children: [
- // 授权码显示区域
- _buildAuthCodeDisplay(),
- 30.verticalSpaceFromWidth,
- // 说明卡片
- _buildInstructionCards(),
- ],
- );
- }
- /// VIP用户界面 - 输入授权码和管理设备
- Widget _buildVIPUserInterface() {
- return Column(
- children: [
- // 6个输入框在顶部
- _buildTopCodeInput(),
- 20.verticalSpaceFromWidth,
- // 设备管理区域
- _buildDeviceManagementSection(),
- 20.verticalSpaceFromWidth,
- // 授权步骤说明
- _buildAuthorizationSteps(),
- ],
- );
- }
- /// 授权码显示区域
- Widget _buildAuthCodeDisplay() {
- return Container(
- padding: EdgeInsets.all(24.w),
- decoration: BoxDecoration(
- color: Get.reactiveTheme.highlightColor,
- borderRadius: BorderRadius.circular(16.r),
- ),
- child: Column(
- children: [
- // 6位授权码
- Obx(
- () => Text(
- controller.authCode.value,
- style: TextStyle(
- fontSize: 48.sp,
- fontWeight: FontWeight.bold,
- color: Colors.white,
- letterSpacing: 4.w,
- ),
- ),
- ),
- 20.verticalSpaceFromWidth,
- // 倒计时和复制按钮
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Icon(
- Icons.access_time,
- size: 16.w,
- color: Get.reactiveTheme.hintColor,
- ),
- SizedBox(width: 8.w),
- Obx(
- () => Text(
- controller.countdownText,
- style: TextStyle(
- fontSize: 16.sp,
- color: Get.reactiveTheme.hintColor,
- ),
- ),
- ),
- SizedBox(width: 16.w),
- Container(
- width: 1,
- height: 20.h,
- color: Get.reactiveTheme.hintColor.withOpacity(0.3),
- ),
- SizedBox(width: 16.w),
- ClickOpacity(
- onTap: () {
- Clipboard.setData(
- ClipboardData(text: controller.authCode.value),
- );
- controller.copyAuthCode();
- },
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- 'Copy',
- style: TextStyle(
- fontSize: 16.sp,
- color: Get.reactiveTheme.hintColor,
- ),
- ),
- SizedBox(width: 4.w),
- Icon(
- Icons.copy,
- size: 16.w,
- color: Get.reactiveTheme.hintColor,
- ),
- ],
- ),
- ),
- ],
- ),
- 20.verticalSpaceFromWidth,
- // 提示文字
- Text(
- 'Please keep this page open.',
- style: TextStyle(
- fontSize: 16.sp,
- color: const Color(0xFFFFB800),
- fontWeight: FontWeight.w500,
- ),
- ),
- ],
- ),
- );
- }
- /// 说明卡片
- Widget _buildInstructionCards() {
- return Container(
- padding: EdgeInsets.all(20.w),
- decoration: BoxDecoration(
- color: Get.reactiveTheme.hintColor.withOpacity(0.1),
- borderRadius: BorderRadius.circular(16.r),
- border: Border.all(
- color: const Color(0xFF00A8E8).withOpacity(0.3),
- width: 1,
- ),
- ),
- child: Column(
- children: [
- _buildInstructionItem(
- icon: Icons.vpn_key,
- title: 'Authorization Code',
- description:
- 'This 6-digit code allows a VIP user to link your device. It refreshes every 15 minutes.',
- ),
- 20.verticalSpaceFromWidth,
- _buildInstructionItem(
- icon: Icons.workspace_premium,
- title: 'Share with Pre User',
- description:
- 'Tell the VIP user this code so they can enter it on their device to authorize you.',
- ),
- 20.verticalSpaceFromWidth,
- _buildInstructionItem(
- icon: Icons.access_time,
- title: 'Waiting for Authorization',
- description:
- 'Please keep this page open.\nOnce approved, your account will automatically upgrade and reconnect.',
- highlightText: 'Please keep this page open.',
- ),
- ],
- ),
- );
- }
- /// 说明条目
- Widget _buildInstructionItem({
- required IconData icon,
- required String title,
- required String description,
- String? highlightText,
- }) {
- return Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- width: 40.w,
- height: 40.w,
- decoration: BoxDecoration(
- color: const Color(0xFF00A8E8).withOpacity(0.2),
- borderRadius: BorderRadius.circular(8.r),
- ),
- child: Icon(icon, size: 20.w, color: const Color(0xFF00A8E8)),
- ),
- SizedBox(width: 16.w),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- title,
- style: TextStyle(
- fontSize: 16.sp,
- fontWeight: FontWeight.bold,
- color: Colors.white,
- ),
- ),
- SizedBox(height: 8.h),
- highlightText != null
- ? RichText(
- text: TextSpan(
- children: [
- TextSpan(
- text: highlightText,
- style: TextStyle(
- fontSize: 14.sp,
- color: const Color(0xFF00A8E8),
- ),
- ),
- TextSpan(
- text:
- '\n${description.substring(highlightText.length + 1)}',
- style: TextStyle(
- fontSize: 14.sp,
- color: Get.reactiveTheme.hintColor,
- ),
- ),
- ],
- ),
- )
- : Text(
- description,
- style: TextStyle(
- fontSize: 14.sp,
- color: Get.reactiveTheme.hintColor,
- height: 1.4,
- ),
- ),
- ],
- ),
- ),
- ],
- );
- }
- /// 顶部6个输入框
- Widget _buildTopCodeInput() {
- return Container(
- padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 16.h),
- decoration: BoxDecoration(
- color: Get.reactiveTheme.highlightColor,
- borderRadius: BorderRadius.circular(16.r),
- ),
- child: Obx(
- () => Pinput(
- length: 6,
- defaultPinTheme: PinTheme(
- width: 40.w,
- height: 50.h,
- textStyle: TextStyle(
- fontSize: 24.sp,
- fontWeight: FontWeight.bold,
- color: Colors.white,
- ),
- decoration: BoxDecoration(
- color: Get.reactiveTheme.hintColor.withOpacity(0.1),
- borderRadius: BorderRadius.circular(8.r),
- border: Border.all(color: Colors.transparent, width: 2),
- ),
- ),
- focusedPinTheme: PinTheme(
- width: 40.w,
- height: 50.h,
- textStyle: TextStyle(
- fontSize: 24.sp,
- fontWeight: FontWeight.bold,
- color: Colors.white,
- ),
- decoration: BoxDecoration(
- color: const Color(0xFF00A8E8).withOpacity(0.2),
- borderRadius: BorderRadius.circular(8.r),
- border: Border.all(color: const Color(0xFF00A8E8), width: 2),
- ),
- ),
- submittedPinTheme: PinTheme(
- width: 40.w,
- height: 50.h,
- textStyle: TextStyle(
- fontSize: 24.sp,
- fontWeight: FontWeight.bold,
- color: Colors.white,
- ),
- decoration: BoxDecoration(
- color: const Color(0xFF00A8E8).withOpacity(0.2),
- borderRadius: BorderRadius.circular(8.r),
- border: Border.all(color: Colors.transparent, width: 2),
- ),
- ),
- onChanged: (value) {
- controller.setInputCode(value);
- },
- onCompleted: (pin) {
- controller.submitAuthCode();
- },
- inputFormatters: [FilteringTextInputFormatter.digitsOnly],
- keyboardType: TextInputType.number,
- showCursor: true,
- cursor: Container(
- width: 2,
- height: 20.h,
- color: const Color(0xFF00A8E8),
- ),
- ),
- ),
- );
- }
- /// 设备管理区域
- Widget _buildDeviceManagementSection() {
- return Container(
- padding: EdgeInsets.all(20.w),
- decoration: BoxDecoration(
- color: Get.reactiveTheme.highlightColor,
- borderRadius: BorderRadius.circular(16.r),
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- // 标题
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(
- 'Manage Devices',
- style: TextStyle(
- fontSize: 18.sp,
- fontWeight: FontWeight.bold,
- color: Colors.white,
- ),
- ),
- Obx(
- () => Text(
- controller.deviceCountText,
- style: TextStyle(
- fontSize: 16.sp,
- color: Get.reactiveTheme.hintColor,
- ),
- ),
- ),
- ],
- ),
- 20.verticalSpaceFromWidth,
- // 设备列表
- Obx(
- () => Column(
- children: [
- ...controller.currentDevices.map((device) {
- return _buildDeviceCard(device);
- }).toList(),
- // 等待激活的设备
- if (controller.inputCode.value.isEmpty)
- _buildAwaitingDeviceCard(),
- ],
- ),
- ),
- 20.verticalSpaceFromWidth,
- // 授权限制说明
- Text(
- 'Authorize up to 4 devices as Premium (${controller.deviceCountText})',
- style: TextStyle(
- fontSize: 14.sp,
- color: Get.reactiveTheme.hintColor,
- ),
- ),
- ],
- ),
- );
- }
- /// 等待激活的设备卡片
- Widget _buildAwaitingDeviceCard() {
- return Container(
- margin: EdgeInsets.only(bottom: 12.h),
- padding: EdgeInsets.all(16.w),
- decoration: BoxDecoration(
- color: Get.reactiveTheme.hintColor.withOpacity(0.1),
- borderRadius: BorderRadius.circular(12.r),
- ),
- child: Row(
- children: [
- // 设备图标
- Container(
- width: 40.w,
- height: 40.w,
- decoration: BoxDecoration(
- color: Get.reactiveTheme.hintColor.withOpacity(0.2),
- borderRadius: BorderRadius.circular(8.r),
- ),
- child: Icon(
- Icons.phone_iphone,
- size: 20.w,
- color: Get.reactiveTheme.hintColor,
- ),
- ),
- SizedBox(width: 12.w),
- // 设备信息
- Expanded(
- child: Text(
- 'Awaiting Activation',
- style: TextStyle(
- fontSize: 16.sp,
- fontWeight: FontWeight.w500,
- color: Colors.white,
- ),
- ),
- ),
- ],
- ),
- );
- }
- /// 设备卡片
- Widget _buildDeviceCard(DeviceInfo device) {
- return Container(
- margin: EdgeInsets.only(bottom: 12.h),
- padding: EdgeInsets.all(16.w),
- decoration: BoxDecoration(
- color: Get.reactiveTheme.hintColor.withOpacity(0.1),
- borderRadius: BorderRadius.circular(12.r),
- ),
- child: Row(
- children: [
- // 设备图标
- Container(
- width: 40.w,
- height: 40.w,
- decoration: BoxDecoration(
- color: Get.reactiveTheme.hintColor.withOpacity(0.2),
- borderRadius: BorderRadius.circular(8.r),
- ),
- child: Icon(
- _getDeviceIcon(device.type),
- size: 20.w,
- color: Get.reactiveTheme.hintColor,
- ),
- ),
- SizedBox(width: 12.w),
- // 设备信息
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- device.name,
- style: TextStyle(
- fontSize: 16.sp,
- fontWeight: FontWeight.w500,
- color: Colors.white,
- ),
- ),
- if (device.uid != null) ...[
- SizedBox(height: 4.h),
- Text(
- device.uid!,
- style: TextStyle(
- fontSize: 14.sp,
- color: Get.reactiveTheme.hintColor,
- ),
- ),
- ],
- if (device.date != null) ...[
- SizedBox(height: 4.h),
- Text(
- device.date!,
- style: TextStyle(
- fontSize: 12.sp,
- color: Get.reactiveTheme.hintColor,
- ),
- ),
- ],
- ],
- ),
- ),
- // 操作按钮
- if (device.isCurrent)
- ClickOpacity(
- onTap: () => controller.removeDevice(device.id),
- child: Container(
- padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
- decoration: BoxDecoration(
- color: Get.reactiveTheme.hintColor.withOpacity(0.2),
- borderRadius: BorderRadius.circular(6.r),
- ),
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Icon(
- Icons.delete,
- size: 16.w,
- color: Get.reactiveTheme.hintColor,
- ),
- SizedBox(width: 4.w),
- Text(
- 'Relieve',
- style: TextStyle(
- fontSize: 12.sp,
- color: Get.reactiveTheme.hintColor,
- ),
- ),
- ],
- ),
- ),
- )
- else
- ClickOpacity(
- onTap: () => controller.removeDevice(device.id),
- child: Container(
- padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 6.h),
- decoration: BoxDecoration(
- color: const Color(0xFF00A8E8),
- borderRadius: BorderRadius.circular(6.r),
- ),
- child: Text(
- 'Relieve',
- style: TextStyle(
- fontSize: 12.sp,
- color: Colors.white,
- fontWeight: FontWeight.w500,
- ),
- ),
- ),
- ),
- ],
- ),
- );
- }
- /// 获取设备图标
- IconData _getDeviceIcon(DeviceTypeEnum type) {
- switch (type) {
- case DeviceTypeEnum.ios:
- return Icons.phone_iphone;
- case DeviceTypeEnum.android:
- return Icons.android;
- case DeviceTypeEnum.windows:
- return Icons.laptop_windows;
- case DeviceTypeEnum.mac:
- return Icons.laptop_mac;
- }
- }
- /// 授权步骤说明
- Widget _buildAuthorizationSteps() {
- return Container(
- padding: EdgeInsets.all(20.w),
- decoration: BoxDecoration(
- color: Get.reactiveTheme.highlightColor,
- borderRadius: BorderRadius.circular(16.r),
- ),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- 'Authorization Steps',
- style: TextStyle(
- fontSize: 18.sp,
- fontWeight: FontWeight.bold,
- color: Colors.white,
- ),
- ),
- 20.verticalSpaceFromWidth,
- _buildStepItem(
- stepNumber: 1,
- title: 'Enter Code',
- description:
- 'Input the 6-digit code shown on the other device (free user). This code refreshes every 15 minutes.',
- icon: Icons.input,
- isCompleted: controller.inputCode.value.isNotEmpty,
- ),
- 16.verticalSpaceFromWidth,
- _buildStepItem(
- stepNumber: 2,
- title: 'Verify Device',
- description:
- 'We\'ll check if the entered code matches an active device waiting for authorization.',
- icon: Icons.verified_user,
- isCompleted: controller.isCodeComplete.value,
- ),
- 16.verticalSpaceFromWidth,
- _buildStepItem(
- stepNumber: 3,
- title: 'Authorization Successful',
- description:
- 'Once confirmed, the device will automatically upgrade and link to your account.',
- icon: Icons.check_circle,
- isCompleted:
- controller.authorizationStatus.value ==
- AuthorizationStatus.success,
- ),
- ],
- ),
- );
- }
- /// 步骤条目
- Widget _buildStepItem({
- required int stepNumber,
- required String title,
- required String description,
- required IconData icon,
- required bool isCompleted,
- }) {
- return Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Container(
- width: 32.w,
- height: 32.w,
- decoration: BoxDecoration(
- color: isCompleted
- ? const Color(0xFF00D9A3)
- : Get.reactiveTheme.hintColor.withOpacity(0.2),
- borderRadius: BorderRadius.circular(8.r),
- ),
- child: Center(
- child: isCompleted
- ? Icon(Icons.check, size: 16.w, color: Colors.white)
- : Icon(icon, size: 16.w, color: Get.reactiveTheme.hintColor),
- ),
- ),
- SizedBox(width: 12.w),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- title,
- style: TextStyle(
- fontSize: 16.sp,
- fontWeight: FontWeight.w500,
- color: Colors.white,
- ),
- ),
- SizedBox(height: 4.h),
- Text(
- description,
- style: TextStyle(
- fontSize: 14.sp,
- color: Get.reactiveTheme.hintColor,
- height: 1.4,
- ),
- ),
- ],
- ),
- ),
- ],
- );
- }
- }
|