# flutter_custom_base **Repository Path**: kikt/flutter_custom_base ## Basic Information - **Project Name**: flutter_custom_base - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-01-20 - **Last Updated**: 2025-08-01 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Flutter Custom Base A collection of Flutter packages for common use cases, including QR code scanning, UI components, and more. ## 引入方式 (Integration) 本项目推荐使用 Git Submodule 方式引入到您的项目中: ```bash # 添加子模块 git submodule add https://gitee.com/kikt/flutter_custom_base.git # 更新子模块 git submodule update --init --recursive ``` ## 可用包 (Available Packages) ### QR Code Scanning (qrcode_scan_view) 一个简单易用的二维码/条形码扫描组件,支持 ZXing 和 MLKit 两种扫描引擎。 #### 添加依赖 (Add Dependency) 在您的 `pubspec.yaml` 文件中添加以下依赖: ```yaml dependencies: qrcode_scan_view: path: flutter_custom_base/packages/qrcode_scan_view ``` #### 在 melos 管理的项目中添加依赖 ```bash melos bootstrap ``` ```yaml dependencies: qrcode_scan_view: ``` #### 基本用法 (Basic Usage) 简单的扫码视图: ```dart import 'package:flutter/material.dart'; import 'package:qrcode_scan_view/qrcode_scan_view.dart'; class ScanExamplePage extends StatelessWidget { const ScanExamplePage({super.key}); @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar(title: const Text('扫码示例')), body: ScanView( controller: ScanViewController(), onResult: (ScanResult result) { debugPrint('扫码结果: ${result.text}'); }, ), ); } } ``` #### 完整扫码页面 (Full Scan Page) 使用内置的扫码页面,包含返回按钮、闪光灯控制和引擎切换功能: ```dart import 'package:flutter/material.dart'; import 'package:qrcode_scan_view/qrcode_scan_view.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( appBar: AppBar(title: const Text('扫码示例')), body: Center( child: ElevatedButton( onPressed: () { Navigator.push( context, MaterialPageRoute( builder: (context) => ScanQrcodePage( onResult: (ScanResult result) { debugPrint('扫码结果: $result'); Navigator.pop(context); // 扫描完成后返回 }, ), ), ); }, child: const Text('开始扫码'), ), ), ), ); } } ``` #### 控制器使用 (Controller Usage) 使用 `ScanViewController` 控制扫码组件: ```dart final controller = ScanViewController(); // 初始化控制器 controller.init(); // 切换闪光灯 await controller.toggleTorch(); // 打开闪光灯 await controller.openTorch(); // 关闭闪光灯 await controller.closeTorch(); // 切换扫码引擎(在 Android 上可在 ZXing 和 MLKit 之间切换) await controller.switchEngine(); // 释放资源 controller.dispose(); ``` #### 自定义配置 (Custom Configuration) 使用 `ScanQrcodeConfig` 自定义扫码页面: ```dart ScanQrcodePage( config: const ScanQrcodeConfig( showTorchButton: true, // 是否显示闪光灯按钮 showSwitchEngineButton: true, // 是否显示切换引擎按钮 ), onResult: (ScanResult result) { debugPrint('扫码结果: $result'); }, ) ``` ## 注意事项 (Notes) 1. 请确保在使用扫码功能前已获取相机权限 2. ZXing 引擎仅在 Android 平台可用,iOS 平台将自动使用 MLKit 引擎 3. 在不需要扫码功能时,请调用 `controller.dispose()` 释放资源 ## 许可证 (License) 本项目遵循 MIT 许可证