### Making HTTP GET Requests with Request Client Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/00-START-HERE.txt Shows how to use the singleton Request client to perform HTTP GET requests. It includes an example of passing query parameters to an API endpoint. Ensure the Request client is properly initialized before use. ```dart final res = await Request().get(Api.videoIntro, queryParameters: {...}); ``` -------------------------------- ### Error Class Constructor Examples Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Shows how to instantiate the Error class with only an error message, or with both an error message and a code. ```dart // 仅错误信息 const Error("网络超时"); // 错误信息 + 错误代码 const Error("请求失败", code: -1); ``` -------------------------------- ### Loading State Usage Example Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Demonstrates checking the state during loading, attempting to access data (which throws an exception), and safely accessing dataOrNull. ```dart import 'package:PiliPlus/http/loading_state.dart'; // 初始化加载状态 LoadingState state = LoadingState.loading(); print(state.isSuccess); // false // 访问数据会抛异常 try { final data = state.data; } catch (e) { print('加载中,无数据'); } // 安全获取数据 final data = state.dataOrNull; // null print(state.toString()); // "ApiException: loading" ``` -------------------------------- ### Success Usage Example Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Demonstrates how to create and access data from a Success state. Shows accessing data directly and safely using dataOrNull. ```dart import 'package:PiliPlus/http/loading_state.dart'; // 创建成功状态 final state = Success({"id": 123, "name": "视频"}); // 访问数据 print(state.data); // {"id": 123, "name": "视频"} print(state.isSuccess); // true // 安全获取数据 final data = state.dataOrNull; // {"id": 123, "name": "视频"} ``` -------------------------------- ### Error Class Usage Example Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Demonstrates creating an Error state and accessing its properties like errMsg and code. It also shows how accessing 'data' throws an exception and how 'dataOrNull' returns null. ```dart // 创建错误状态 final state = Error("用户未登录", code: -101); // 检查是否成功 print(state.isSuccess); // false // 访问错误信息(会抛异常) try { final data = state.data; } catch (e) { print('捕获异常:$e'); } // 安全获取数据 final data = state.dataOrNull; // null // 获取错误信息 print(state.errMsg); // "用户未登录" print(state.code); // -101 print(state.toString()); // "用户未登录" ``` -------------------------------- ### Publish Flutter library and ICU data Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Makes Flutter library and ICU data available to parent scopes for installation. ```cmake set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) ``` -------------------------------- ### Find PkgConfig and Check Modules Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/linux/flutter/CMakeLists.txt Uses PkgConfig to find and check for required system-level libraries like GTK, GLIB, and GIO, making their imported targets available for linking. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) ``` -------------------------------- ### Configuring Multi-Account Management Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/00-START-HERE.txt Shows how to specify which account to use for a request using the Options class, particularly when dealing with multiple user accounts. This is useful for features like switching between main and secondary accounts. ```dart Options(extra: {'account': Accounts.main}) ``` -------------------------------- ### Loading State Creation Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Shows the recommended way to create a Loading state using the LoadingState.loading() factory method, and also the direct instantiation of the Loading class. ```dart // 通过工厂方法创建 final state = LoadingState.loading(); // 或直接创建 Loading 实例(不推荐) const loading = Loading._internal(); ``` -------------------------------- ### Apply Standard Build Settings Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/runner/CMakeLists.txt Applies a standard set of build settings to the executable target. This can be customized for applications requiring different build configurations. ```cmake apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Accessing Global Services with GetxService Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/00-START-HERE.txt Illustrates how to retrieve an instance of a global service, such as AccountService, using Get.find from the GetX dependency injection system. This is used for accessing shared functionalities across the application. ```dart final accountService = Get.find(); ``` -------------------------------- ### Define C++ wrapper application sources Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Lists and prepends the wrapper root directory to C++ wrapper application source files. ```cmake list(APPEND CPP_WRAPPER_SOURCES_APP "flutter_engine.cc" "flutter_view_controller.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Link Dependencies and Include Directories Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/runner/CMakeLists.txt Links necessary libraries (flutter, flutter_wrapper_app, dwmapi.lib) and sets include directories for the project. Custom application-specific dependencies can be added here. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) target_link_libraries(${BINARY_NAME} PRIVATE "dwmapi.lib") target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") ``` -------------------------------- ### Define C++ wrapper plugin sources Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Lists and prepends the wrapper root directory to C++ wrapper plugin source files. ```cmake list(APPEND CPP_WRAPPER_SOURCES_PLUGIN "plugin_registrar.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Create static library for Flutter wrapper plugin Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Builds a static library for the Flutter plugin wrapper, applying standard settings and visibility. ```cmake add_library(flutter_wrapper_plugin STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} ) apply_standard_settings(flutter_wrapper_plugin) set_target_properties(flutter_wrapper_plugin PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(flutter_wrapper_plugin PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) target_include_directories(flutter_wrapper_plugin PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_plugin flutter_assemble) ``` -------------------------------- ### VideoDetailData - 视频详情模型 Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/data-models.md 定义了视频详情的结构,包含 BV ID、标题、发布时间、UP主信息、统计信息等。可通过 `fromJson()` 从 JSON 解析或直接构造实例。 ```dart class VideoDetailData { String? bvid; // BV ID int? aid; // AV ID int? videos; // 分P 数量 int? copyright; // 版权标志(1=自制,2=转载) String? pic; // 封面 URL String? title; // 标题 int? pubdate; // 发布时间(时间戳) int? ctime; // 创建时间(时间戳) String? desc; // 描述 List? descV2; // 描述 v2(富文本) int? duration; // 总时长(秒) Rights? rights; // 权限信息 Owner? owner; // UP 主信息 VideoStat? stat; // 统计信息 ArgueInfo? argueInfo; // 争议信息 int? cid; // 当前分P 的 CID Dimension? dimension; // 画面尺寸 int? seasonId; // 合集 ID bool? isUpowerExclusive; // 是否为 UP 主专享 List? pages; // 分P 列表 UgcSeason? ugcSeason; // UGC 合集 List? staff; // 工作人员 String? redirectUrl; // 重定向 URL bool isPageReversed; // 是否倒序分P } ``` ```dart // 从 JSON 解析 VideoDetailData.fromJson(json) // 构造实例 VideoDetailData( bvid: 'BV...', title: '标题', // ... ) ``` -------------------------------- ### Create static library for Flutter wrapper application Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Builds a static library for the Flutter application runner wrapper, applying standard settings. ```cmake add_library(flutter_wrapper_app STATIC ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_APP} ) apply_standard_settings(flutter_wrapper_app) target_link_libraries(flutter_wrapper_app PUBLIC flutter) target_include_directories(flutter_wrapper_app PUBLIC "${WRAPPER_ROOT}/include" ) add_dependencies(flutter_wrapper_app flutter_assemble) ``` -------------------------------- ### Set wrapper root directory Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Specifies the root directory for the C++ client wrapper. ```cmake set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") ``` -------------------------------- ### Define C++ wrapper core sources Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Lists and prepends the wrapper root directory to core C++ wrapper source files. ```cmake list(APPEND CPP_WRAPPER_SOURCES_CORE "core_implementations.cc" "standard_codec.cc" ) list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") ``` -------------------------------- ### Custom Command for Flutter Tool Backend Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/linux/flutter/CMakeLists.txt Configures a custom command to run the Flutter tool backend script, generating the Flutter library and headers. A phony target is used to ensure execution. ```cmake add_custom_command( OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/_phony_ COMMAND ${CMAKE_COMMAND} -E env ${FLUTTER_TOOL_ENVIRONMENT} "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" ${FLUTTER_TARGET_PLATFORM} ${CMAKE_BUILD_TYPE} VERBATIM ) ``` -------------------------------- ### Define Flutter Library and Headers Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/linux/flutter/CMakeLists.txt Sets the path to the Flutter shared library and lists its header files, preparing them for inclusion in the build. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") # Published to parent scope for install step. set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) list(APPEND FLUTTER_LIBRARY_HEADERS "fl_basic_message_channel.h" "fl_binary_codec.h" "fl_binary_messenger.h" "fl_dart_project.h" "fl_engine.h" "fl_json_message_codec.h" "fl_json_method_codec.h" "fl_message_codec.h" "fl_method_call.h" "fl_method_channel.h" "fl_method_codec.h" "fl_method_response.h" "fl_plugin_registrar.h" "fl_plugin_registry.h" "fl_standard_message_codec.h" "fl_standard_method_codec.h" "fl_string_codec.h" "fl_value.h" "fl_view.h" "flutter_linux.h" ) list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") ``` -------------------------------- ### Define Flutter library path Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Sets the path to the Flutter Windows DLL. ```cmake set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") ``` -------------------------------- ### Define Flutter library headers Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Lists and prepends the ephemeral directory to Flutter library header files. ```cmake list(APPEND FLUTTER_LIBRARY_HEADERS "flutter_export.h" "flutter_windows.h" "flutter_messenger.h" "flutter_plugin_registrar.h" "flutter_texture_registrar.h" ) list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") ``` -------------------------------- ### Success Equality Comparison Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Illustrates how Success objects are compared for equality based on their response data. ```dart final state1 = Success(42); final state2 = Success(42); final state3 = Success(43); print(state1 == state2); // true(基于 response 比较) print(state1 == state3); // false print(state1.hashCode == state2.hashCode); // true ``` -------------------------------- ### Unified Asynchronous Result Handling with LoadingState Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/00-START-HERE.txt Demonstrates how to handle asynchronous operation results using the LoadingState sealed class, covering success, error, and loading states. This pattern is useful for managing UI states during network requests or other async operations. ```dart switch (result) { case Success(:final response) => handleSuccess(response), case Error(:final errMsg) => handleError(errMsg), case Loading() => showLoading(), } ``` -------------------------------- ### Include generated configuration Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Includes CMake configuration generated by the Flutter tool. ```cmake include(${EPHEMERAL_DIR}/generated_config.cmake) ``` -------------------------------- ### VideoShotData - 视频快照模型 Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/data-models.md 用于获取视频的进度条预览缩略图,包含快照 URL 列表。 ```dart class VideoShotData { List? image; // 快照 URL 列表 int? pvdata; String? pvtext; } ``` -------------------------------- ### VideoAIConclusionData - AI 视频总结模型 Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/data-models.md 包含 AI 对视频内容的总结文本和使用的模型版本。 ```dart class VideoAIConclusionData { String? conclusion; // AI 总结文本 int? modelNumber; // 模型版本 } ``` -------------------------------- ### VideoDetailResponse - 视频详情响应模型 Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/data-models.md 表示视频详情请求的响应结构,包含状态码、消息和视频详情数据。 ```dart class VideoDetailResponse { int? code; String? message; VideoDetailData? data; } ``` -------------------------------- ### Create Flutter Interface Library Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/linux/flutter/CMakeLists.txt Defines an interface library target for Flutter, specifying include directories and linking against the Flutter library and system dependencies. ```cmake add_library(flutter INTERFACE) target_include_directories(flutter INTERFACE "${EPHEMERAL_DIR}" ) target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") target_link_libraries(flutter INTERFACE PkgConfig::GTK PkgConfig::GLIB PkgConfig::GIO ) add_dependencies(flutter flutter_assemble) ``` -------------------------------- ### Set project build directory Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Defines the project's build directory, published to the parent scope. ```cmake set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) ``` -------------------------------- ### Safe Access with dataOrNull Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Demonstrates using dataOrNull for safe access to data, checking for null before attempting to use properties like 'name'. ```dart Future fetchUserInfo() async { final state = await UserHttp.userInfo(); final userName = state.dataOrNull?.name; if (userName != null) { print('用户名:$userName'); } else { print('无法获取用户信息'); } } ``` -------------------------------- ### Add Preprocessor Definitions for Build Version Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/runner/CMakeLists.txt Adds preprocessor definitions to the build configuration to include version information. This allows the application to access Flutter version details at compile time. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION=\"${FLUTTER_VERSION}\"") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MAJOR=${FLUTTER_VERSION_MAJOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_MINOR=${FLUTTER_VERSION_MINOR}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_PATCH=${FLUTTER_VERSION_PATCH}") target_compile_definitions(${BINARY_NAME} PRIVATE "FLUTTER_VERSION_BUILD=${FLUTTER_VERSION_BUILD}") ``` -------------------------------- ### Custom CMake List Prepend Function Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/linux/flutter/CMakeLists.txt Defines a custom function to prepend a prefix to each element in a CMake list, as list(TRANSFORM ... PREPEND ...) is not available in CMake 3.10. ```cmake function(list_prepend LIST_NAME PREFIX) set(NEW_LIST "") foreach(element ${${LIST_NAME}}) list(APPEND NEW_LIST "${PREFIX}${element}") endforeach(element) set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) endfunction() ``` -------------------------------- ### Updating UI with Rx Variables Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/00-START-HERE.txt Demonstrates how to use Rx observable variables to automatically refresh the UI when the state changes. The Obx widget rebuilds its child whenever the observed Rx variable's value is updated. ```dart Obx(() => Text(state.value.data)) ``` -------------------------------- ### PiliPlus Project Directory Structure Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/architecture-overview.md The PiliPlus project follows a structured directory layout for better organization and maintainability. Key directories include lib/, http/, models_new/, services/, pages/, router/, common/, utils/, grpc/, and plugin/. ```tree lib/ ├── main.dart # 应用入口 ├── build_config.dart # 构建配置 ├── http/ # HTTP 层 │ ├── init.dart # HTTP 客户端初始化 │ ├── api.dart # API 端点定义(200+ 个) │ ├── constants.dart # HTTP 常量 │ ├── loading_state.dart # 加载状态枚举 │ ├── user.dart # 用户 API │ ├── video.dart # 视频 API │ ├── reply.dart # 评论 API │ ├── dynamics.dart # 动态 API │ ├── live.dart # 直播 API │ ├── fav.dart # 收藏 API │ ├── download.dart # 下载 API │ ├── search.dart # 搜索 API │ ├── login.dart # 登录 API │ ├── msg.dart # 消息 API │ ├── member.dart # 用户空间 API │ ├── pgc.dart # 番剧 API │ ├── danmaku.dart # 弹幕 API │ └── ...(其他 API) ├── models/ # 旧模型(逐步迁移) │ └── user/ │ └── info.dart ├── models_new/ # 新模型(优先使用) │ ├── video/ # 视频模型 │ ├── user/ # 用户模型 │ ├── live/ # 直播模型 │ ├── pgc/ # 番剧模型 │ ├── reply/ # 评论模型 │ ├── dynamic/ # 动态模型 │ ├── fav/ # 收藏模型 │ ├── download/ # 下载模型 │ ├── history/ # 历史记录模型 │ ├── search/ # 搜索模型 │ ├── msg/ # 消息模型 │ └── ...(其他模型) ├── services/ # 服务层 │ ├── account_service.dart # 账户服务 │ ├── download/ │ │ ├── download_service.dart │ │ └── download_manager.dart │ ├── audio_handler.dart # 音频处理 │ ├── audio_session.dart # 音频会话 │ ├── service_locator.dart # 服务定位器 │ ├── logger.dart # 日志服务 │ └── shutdown_timer_service.dart ├── pages/ # 页面/屏幕 │ ├── home/ # 首页 │ ├── video/ # 视频详情页 │ ├── reply/ # 评论页 │ ├── user/ # 用户空间 │ ├── live/ # 直播页 │ ├── search/ # 搜索页 │ ├── download/ # 下载页 │ ├── message/ # 消息页 │ ├── dynamic/ # 动态页 │ ├── setting/ # 设置页 │ └── ...(其他页面) ├── router/ # 路由管理 │ └── app_pages.dart ├── common/ # 公共组件和工具 │ ├── widgets/ # 可复用 UI 组件 │ ├── skeleton/ # 骨架屏 │ ├── constants.dart # 应用常量 │ ├── style.dart # 样式定义 │ └── assets.dart # 资源常量 ├── utils/ # 工具函数 │ ├── storage.dart # 存储管理 │ ├── storage_pref.dart # 偏好设置 │ ├── storage_key.dart # 存储键常量 │ ├── cache_manager.dart # 缓存管理 │ ├── path_utils.dart # 路径工具 │ ├── platform_utils.dart # 平台检测 │ ├── id_utils.dart # ID 转换(BV↔AV) │ ├── wbi_sign.dart # WBI 签名 │ ├── app_sign.dart # APP 签名 │ ├── accounts.dart # 多账户管理 │ ├── request_utils.dart # 请求工具 │ ├── utils.dart # 通用工具 │ ├── extension/ # Dart 扩展方法 │ └── global_data.dart # 全局数据 ├── grpc/ # gRPC 定义(进行中) └── plugin/ # 插件 └── pl_player/ # 播放器插件 ``` -------------------------------- ### VideoPlayInfoData - 视频播放信息模型 Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/data-models.md 包含视频的播放 URL、清晰度、音质等信息。可用于获取不同清晰度的播放列表。 ```dart class VideoPlayInfoData { int? code; String? message; List? playUrl; // 可选的播放清晰度列表 String? videoUrl; // 播放 URL String? audioUrl; // 音频 URL(仅音频模式) } ``` -------------------------------- ### MemberInfo - 用户空间信息模型 Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/data-models.md 表示用户空间页面的用户信息,包含用户 ID、昵称、签名、性别等。 ```dart class MemberInfo { int? mid; String? name; String? face; String? sign; int? sex; // 性别(0=保密,1=男,2=女) int? birthday; // 生日(YYYYMMDD) // ... } ``` -------------------------------- ### Loading Class Definition Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Represents the loading state for an asynchronous operation. It uses a private constructor and a factory method for instantiation, adhering to the singleton pattern. ```dart class Loading extends LoadingState { const Loading._internal(); } ``` -------------------------------- ### LoadingState Class Definition Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Defines the base sealed class for asynchronous operation states. It includes factory methods for creating states and getters for checking the state and accessing data. ```dart sealed class LoadingState { const LoadingState(); factory LoadingState.loading() => const Loading._internal(); bool get isSuccess => this is Success; T get data { ... } T? get dataOrNull { ... } Future toast() { ... } } ``` -------------------------------- ### UserInfoData - 用户信息模型 Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/data-models.md 定义了用户基本信息,包括用户 ID、用户名、头像、VIP 状态等。 ```dart class UserInfoData { int? mid; // 用户 ID String? uname; // 用户名 String? face; // 头像 URL int? level; // 等级 int? money; // 硬币数 int? vipType; // VIP 类型(0=无,1=月度,2=年度) int? vipExpireTime; // VIP 过期时间 String? signature; // 签名 // ... } ``` -------------------------------- ### VideoTagData - 视频标签模型 Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/data-models.md 包含视频标签列表,每个标签有 ID 和名称。 ```dart class VideoTagData { List? tags; // 标签列表 } class TagItem { String? tagId; String? tagName; // ... } ``` -------------------------------- ### Define Executable Target Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/runner/CMakeLists.txt Defines the main executable target for the Windows runner application. Source files and resources are listed here. The binary name should be managed in the top-level CMakeLists.txt to ensure `flutter run` compatibility. ```cmake add_executable(${BINARY_NAME} WIN32 "flutter_window.cpp" "main.cpp" "utils.cpp" "win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) ``` -------------------------------- ### VideoRelationData - 相关视频模型 Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/data-models.md 表示相关视频的数据结构,其内部结构与 `VideoDetailData` 类似。 ```dart class VideoRelationData { // 相关视频列表,结构同 VideoDetailData } ``` -------------------------------- ### Add Flutter Tool Build Dependency Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/runner/CMakeLists.txt Ensures that the Flutter tool's assembly process is completed before the main executable is built. This is a required step for Flutter applications. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Set ephemeral directory Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Defines the directory for ephemeral build artifacts. ```cmake set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") ``` -------------------------------- ### Set AOT library path Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Specifies the path to the Ahead-Of-Time compiled library. ```cmake set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) ``` -------------------------------- ### ReplyData - 评论列表模型 Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/data-models.md 包含评论列表的元数据(页码、总数、游标)以及评论对象列表。 ```dart class ReplyData { int? page; int? count; int? cursor; List? replies; // 评论列表 } class Reply { int? rpid; // 评论 ID int? oid; // 内容 ID int? type; // 类型 String? message; // 评论内容 int? mid; // 评论者 ID String? uname; // 评论者名字 String? face; // 评论者头像 int? ctime; // 创建时间 int? like; // 点赞数 int? rcount; // 回复数 } ``` -------------------------------- ### Error Class Equality Comparison Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Illustrates how Error objects are compared for equality based on both their error message and error code. ```dart final error1 = Error("失败", code: 1); final error2 = Error("失败", code: 1); final error3 = Error("失败", code: 2); print(error1 == error2); // true(errMsg 和 code 都相同) print(error1 == error3); // false ``` -------------------------------- ### Custom Target for Flutter Assembly Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/linux/flutter/CMakeLists.txt Creates a custom target 'flutter_assemble' that depends on the generated Flutter library and its headers, ensuring they are built. ```cmake add_custom_target(flutter_assemble DEPENDS "${FLUTTER_LIBRARY}" ${FLUTTER_LIBRARY_HEADERS} ) ``` -------------------------------- ### LiveRoomInfoData - 直播间信息模型 Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/data-models.md 包含直播间的基本信息,如房间 ID、UP主 ID、标题、预览图以及清晰度列表。 ```dart class LiveRoomInfoData { int? roomId; int? uid; // UP 主 ID String? title; // 直播标题 String? keyframe; // 关键帧/预览图 String? parentAreaName; // 分区 List? qualityDescription; // 清晰度列表 } class QualityDesc { int? qn; // 清晰度等级 String? desc; // 清晰度描述 int? resolution; // 分辨率 } ``` -------------------------------- ### Set fallback target platform Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/flutter/CMakeLists.txt Provides a fallback for FLUTTER_TARGET_PLATFORM if not defined. ```cmake if (NOT DEFINED FLUTTER_TARGET_PLATFORM) set(FLUTTER_TARGET_PLATFORM "windows-x64") endif() ``` -------------------------------- ### Switch Expression for State Handling Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Recommended for Dart 3.0+, this pattern uses a switch expression to elegantly handle different LoadingState outcomes (Success, Error, Loading). ```dart Future fetchUserInfo() async { final state = await UserHttp.userInfo(); final result = switch (state) { Success(:final response) => 'User: ${response.name}', Error(:final errMsg) => 'Error: $errMsg', Loading() => 'Loading...', }; print(result); } ``` -------------------------------- ### ReplyInteractionData - 评论互动模型 Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/data-models.md 表示用户对某条评论的互动状态,如是否已点赞或点踩。 ```dart class ReplyInteractionData { bool? liked; // 是否已点赞 bool? hated; // 是否已点踩 } ``` -------------------------------- ### If-Else If Statement for State Handling Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md A traditional approach using if-else if statements to check the state and handle Success or Error conditions. ```dart Future fetchUserInfo() async { final state = await UserHttp.userInfo(); if (state.isSuccess) { final data = state.data; print('用户名:${data.name}'); } else if (state is Error) { print('错误:${state.errMsg}'); } } ``` -------------------------------- ### Toast Notification for Errors Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Shows how to trigger a toast notification for error states by calling the inherited toast() method when the state is not successful. ```dart Future fetchUserInfo() async { final state = await UserHttp.userInfo(); if (!state.isSuccess) { // 显示错误提示 await state.toast(); // 调用继承的 toast() 方法 } } ``` -------------------------------- ### Case Statement for State Handling Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Utilizes a switch statement with case expressions to pattern match and handle Success, Error, and Loading states, extracting relevant data like response or error messages. ```dart Future fetchUserInfo() async { final state = await UserHttp.userInfo(); switch (state) { case Success(:final response): print('成功:${response.name}'); case Error(:final errMsg, :final code): print('失败($code):$errMsg'); case Loading(): print('加载中'); } } ``` -------------------------------- ### Success Class Definition Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Represents a successful asynchronous operation. It is an immutable class holding the response data. ```dart @immutable class Success extends LoadingState { final T response; const Success(this.response); } ``` -------------------------------- ### Error Class toString Method Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Defines the string representation of the Error class, prioritizing the error message or falling back to the error code. ```dart @override String toString() => errMsg ?? code?.toString() ?? ''; ``` -------------------------------- ### Disable Conflicting Windows Macros Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/windows/runner/CMakeLists.txt Disables Windows-specific macros (NOMINMAX) that can conflict with standard C++ library functions, preventing potential compilation errors. ```cmake target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") ``` -------------------------------- ### Error Class Definition Source: https://github.com/bggrgjqaubcoe/piliplus/blob/main/_autodocs/loading-state-types.md Represents an error state in an asynchronous operation. It can store an error message and an optional error code. ```dart @immutable class Error extends LoadingState { final int? code; final String? errMsg; const Error(this.errMsg, {this.code}); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.