鸿蒙flutter第三方库适配 - 车辆管理
运行效果图车辆管理应用是一款专注于车辆全生命周期管理的实用工具应用,旨在帮助车主便捷地记录和管理车辆相关信息。应用支持保养记录管理、加油记录统计、违章信息查询、费用分析报告等功能,让车主轻松掌握爱车状况。应用以活力橙红为主色调,象征热情与动力。涵盖车辆信息、保养管理、加油记录、违章查询四大核心模块。用户可以记录车辆保养历史、追踪油耗变化、管理违章信息、分析用车成本,实现车辆管理的智能化和便捷化。序
车辆管理应用
欢迎加入开源鸿蒙跨平台社区:
https://openharmonycrossplatform.csdn.net
适配的第三方库地址:
- sqflite: https://pub.dev/packages/sqflite
- flutter_local_notifications: https://pub.dev/packages/flutter_local_notifications
- location: https://pub.dev/packages/location
- image_picker: https://pub.dev/packages/image_picker
一、项目概述
运行效果图



1.1 应用简介
车辆管理应用是一款专注于车辆全生命周期管理的实用工具应用,旨在帮助车主便捷地记录和管理车辆相关信息。应用支持保养记录管理、加油记录统计、违章信息查询、费用分析报告等功能,让车主轻松掌握爱车状况。
应用以活力橙红为主色调,象征热情与动力。涵盖车辆信息、保养管理、加油记录、违章查询四大核心模块。用户可以记录车辆保养历史、追踪油耗变化、管理违章信息、分析用车成本,实现车辆管理的智能化和便捷化。
1.2 核心功能
| 功能模块 | 功能描述 | 实现方式 |
|---|---|---|
| 车辆管理 | 添加、编辑、查看车辆信息 | 本地存储 |
| 保养记录 | 记录保养历史,到期提醒 | 数据库存储 |
| 加油记录 | 记录加油信息,油耗统计 | 数据计算 |
| 违章查询 | 查询违章信息,在线处理 | 网络接口 |
| 费用统计 | 分析用车成本,生成报告 | 数据分析 |
| 保养提醒 | 保养到期自动提醒 | 本地通知 |
| 证件管理 | 上传存储车辆证件照片 | 图片存储 |
| 位置记录 | 记录加油站、维修店位置 | 定位服务 |
1.3 保养类型定义
| 序号 | 保养类型 | Emoji | 间隔里程 | 描述 |
|---|---|---|---|---|
| 1 | 更换机油 | 🛢️ | 5000km | 发动机机油更换 |
| 2 | 更换滤芯 | 🔧 | 10000km | 空气/机油滤芯 |
| 3 | 轮胎换位 | 🛞 | 10000km | 轮胎位置调换 |
| 4 | 刹车检查 | 🛑 | 20000km | 制动系统检查 |
| 5 | 空调保养 | ❄️ | 15000km | 空调系统维护 |
| 6 | 火花塞更换 | ⚡ | 30000km | 点火系统维护 |
| 7 | 变速箱保养 | ⚙️ | 40000km | 变速箱油更换 |
| 8 | 年检 | 📋 | 365天 | 车辆年检 |
1.4 违章类型定义
| 序号 | 违章类型 | Emoji | 罚款 | 扣分 |
|---|---|---|---|---|
| 1 | 超速行驶 | 🚀 | ¥200 | 3分 |
| 2 | 闯红灯 | 🚦 | ¥200 | 6分 |
| 3 | 违章停车 | 🅿️ | ¥100 | 0分 |
| 4 | 无证驾驶 | 🚫 | ¥1000 | 12分 |
| 5 | 酒后驾驶 | 🍺 | ¥2000 | 12分 |
| 6 | 超载 | 📦 | ¥500 | 3分 |
| 7 | 违规变道 | ↔️ | ¥100 | 3分 |
1.5 油品类型定义
| 序号 | 油品名称 | 标号 | 适用车型 |
|---|---|---|---|
| 1 | 汽油 | 92# | 普通家用车 |
| 2 | 汽油 | 95# | 中高端车型 |
| 3 | 汽油 | 98# | 高性能车型 |
| 4 | 柴油 | 0# | 柴油车型 |
1.6 费用类型定义
| 序号 | 费用类型 | Emoji | 描述 |
|---|---|---|---|
| 1 | 加油费用 | ⛽ | 燃油消耗支出 |
| 2 | 保养费用 | 🔧 | 车辆维护支出 |
| 3 | 违章罚款 | ⚠️ | 交通违章罚款 |
| 4 | 保险费用 | 📋 | 车辆保险支出 |
| 5 | 停车费用 | 🅿️ | 停车场收费 |
| 6 | 过路费用 | 🛣️ | 高速公路收费 |
1.7 技术栈
| 技术领域 | 技术选型 | 版本要求 |
|---|---|---|
| 开发框架 | Flutter | >= 3.0.0 |
| 编程语言 | Dart | >= 2.17.0 |
| 设计规范 | Material Design 3 | - |
| 状态管理 | StatefulWidget | - |
| 数据存储 | Sqflite | >= 2.0.0 |
| 本地通知 | FlutterLocalNotifications | >= 15.0.0 |
| 定位服务 | Location | >= 4.0.0 |
| 图片选择 | ImagePicker | >= 1.0.0 |
| 目标平台 | 鸿蒙OS / Web | API 21+ |
1.8 项目结构
lib/
└── main_vehicle_management.dart
├── VehicleManagementApp # 应用入口
├── MaintenanceType # 保养类型枚举
├── ViolationType # 违章类型枚举
├── Vehicle # 车辆模型
├── MaintenanceRecord # 保养记录模型
├── RefuelRecord # 加油记录模型
├── ViolationRecord # 违章记录模型
├── VehicleStats # 车辆统计模型
├── VehicleManagementHomePage # 主页面(底部导航)
├── _buildHomePage # 车辆主页
├── _buildMaintenancePage # 保养页
├── _buildRefuelPage # 加油页
└── _buildViolationPage # 违章页
二、系统架构
2.1 整体架构图
2.2 类图设计
2.3 页面导航流程
2.4 保养提醒流程
三、核心模块设计
3.1 数据模型设计
3.1.1 保养类型枚举 (MaintenanceType)
enum MaintenanceType {
oilChange('更换机油', '🛢️', 5000),
filterChange('更换滤芯', '🔧', 10000),
tireRotation('轮胎换位', '🛞', 10000),
brakeCheck('刹车检查', '🛑', 20000),
airConditioning('空调保养', '❄️', 15000),
sparkPlug('火花塞更换', '⚡', 30000),
transmission('变速箱保养', '⚙️', 40000),
inspection('年检', '📋', 365);
final String label;
final String emoji;
final int intervalKm;
const MaintenanceType(this.label, this.emoji, this.intervalKm);
}
3.1.2 违章类型枚举 (ViolationType)
enum ViolationType {
speeding('超速行驶', '🚀', 200, 3),
redLight('闯红灯', '🚦', 200, 6),
illegalParking('违章停车', '🅿️', 100, 0),
noLicense('无证驾驶', '🚫', 1000, 12),
drunkDriving('酒后驾驶', '🍺', 2000, 12),
overloading('超载', '📦', 500, 3),
laneViolation('违规变道', '↔️', 100, 3);
final String label;
final String emoji;
final int fine;
final int points;
const ViolationType(this.label, this.emoji, this.fine, this.points);
}
3.1.3 车辆模型 (Vehicle)
class Vehicle {
final String id;
final String name;
final String plateNumber;
final String brand;
final String model;
final int year;
final String color;
final int currentMileage;
final String? imageUrl;
final DateTime purchaseDate;
final DateTime createdAt;
const Vehicle({
required this.id,
required this.name,
required this.plateNumber,
required this.brand,
required this.model,
required this.year,
required this.color,
required this.currentMileage,
this.imageUrl,
required this.purchaseDate,
required this.createdAt,
});
Vehicle copyWith({int? currentMileage}) {
return Vehicle(
id: id,
name: name,
plateNumber: plateNumber,
brand: brand,
model: model,
year: year,
color: color,
currentMileage: currentMileage ?? this.currentMileage,
imageUrl: imageUrl,
purchaseDate: purchaseDate,
createdAt: createdAt,
);
}
}
3.1.4 费用分布统计
3.2 页面结构设计
3.2.1 主页面布局
3.2.2 车辆主页结构
3.2.3 保养页结构
3.2.4 加油页结构
3.3 保养提醒逻辑
3.4 油耗计算逻辑
四、UI设计规范
4.1 配色方案
应用以活力橙红为主色调,象征热情与动力:
| 颜色类型 | 色值 | 用途 |
|---|---|---|
| 主色 | #FF5722 (DeepOrange) | 导航、主题元素 |
| 辅助色 | #FF8A65 | 卡片背景 |
| 第三色 | #FFAB91 | 进度条背景 |
| 强调色 | #FFCCBC | 分组页面 |
| 背景色 | #FAFAFA | 页面背景 |
| 卡片背景 | #FFFFFF | 信息卡片 |
| 加油色 | #4CAF50 | 加油相关 |
| 保养色 | #2196F3 | 保养相关 |
| 违章色 | #F44336 | 违章相关 |
4.2 功能配色
| 功能 | 色值 | 视觉效果 |
|---|---|---|
| 加油 | #4CAF50 | 绿色 |
| 保养 | #2196F3 | 蓝色 |
| 违章 | #F44336 | 红色 |
| 提醒 | #FF9800 | 橙色 |
| 完成 | #8BC34A | 浅绿 |
4.3 字体规范
| 元素 | 字号 | 字重 | 颜色 |
|---|---|---|---|
| 页面标题 | 24px | Bold | 主色 |
| 车辆名称 | 18px | Bold | #000000 |
| 费用金额 | 18px | Bold | 主色 |
| 记录标题 | 16px | Medium | #000000 |
| 提示文字 | 14px | Regular | #666666 |
| 标签文字 | 11px | Medium | 分组色 |
4.4 组件规范
4.4.1 车辆信息卡片
┌─────────────────────────────────────┐
│ 🚗 大众 帕萨特 2022款 │
│ 京A12345 │
│ ───────────────────────────────── │
│ 🚀 35,680 km 🎨 黑色 📅 365天 │
└─────────────────────────────────────┘
4.4.2 费用统计卡片
┌─────────────────────────────────────┐
│ 费用统计 │
│ │
│ ⛽ 加油费用 🔧 保养费用 │
│ ¥3,500 ¥1,200 │
│ │
│ ⚠️ 违章罚款 📊 平均油耗 │
│ ¥200 7.5 L/100km │
└─────────────────────────────────────┘
4.4.3 保养记录卡片
┌─────────────────────────────────────┐
│ 🛢️ 更换机油 ¥450 │
│ 里程: 30,000 km │
│ ───────────────────────────────── │
│ 📅 2024-01-15 🏪 4S店 │
│ ┌─────────────────────────────┐ │
│ │ 全合成机油 │ │
│ └─────────────────────────────┘ │
└─────────────────────────────────────┘
4.4.4 加油记录卡片
┌─────────────────────────────────────┐
│ ⛽ 45.5L [95#] ¥350 │
│ 里程: 35,000 km · ¥7.8/L │
│ 1/15│
└─────────────────────────────────────┘
4.4.5 违章记录卡片
┌─────────────────────────────────────┐
│ 🚀 超速行驶 [已处理] │
│ 京沪高速120公里处 │
│ ───────────────────────────────── │
│ 📅 2024-01-01 │
│ [罚款 ¥200] [扣3分] │
└─────────────────────────────────────┘
五、核心功能实现
5.1 车辆管理器实现
class VehicleManager {
final DatabaseHelper _dbHelper = DatabaseHelper();
List<Vehicle> _vehicles = [];
Future<void> loadVehicles() async {
_vehicles = await _dbHelper.getVehicles();
}
Future<void> addVehicle(Vehicle vehicle) async {
await _dbHelper.insertVehicle(vehicle);
_vehicles.add(vehicle);
}
Future<void> updateVehicle(Vehicle vehicle) async {
await _dbHelper.updateVehicle(vehicle);
final index = _vehicles.indexWhere((v) => v.id == vehicle.id);
if (index != -1) {
_vehicles[index] = vehicle;
}
}
Future<void> updateMileage(String vehicleId, int newMileage) async {
final index = _vehicles.indexWhere((v) => v.id == vehicleId);
if (index != -1) {
_vehicles[index] = _vehicles[index].copyWith(currentMileage: newMileage);
await _dbHelper.updateVehicle(_vehicles[index]);
}
}
List<Vehicle> get vehicles => List.unmodifiable(_vehicles);
}
5.2 保养管理器实现
class MaintenanceManager {
final DatabaseHelper _dbHelper = DatabaseHelper();
List<MaintenanceRecord> _records = [];
Future<void> loadRecords(String vehicleId) async {
_records = await _dbHelper.getMaintenanceRecords(vehicleId);
}
Future<void> addRecord(MaintenanceRecord record) async {
await _dbHelper.insertMaintenanceRecord(record);
_records.insert(0, record);
}
List<MaintenanceRecord> getUpcomingMaintenance(Vehicle vehicle) {
return _records.where((r) {
final daysLeft = r.nextDueDate.difference(DateTime.now()).inDays;
final kmLeft = r.nextDueMileage - vehicle.currentMileage;
return daysLeft < 30 || kmLeft < 1000;
}).toList();
}
double getTotalCost() {
return _records.fold<double>(0, (sum, r) => sum + r.cost);
}
}
5.3 加油管理器实现
class RefuelManager {
final DatabaseHelper _dbHelper = DatabaseHelper();
List<RefuelRecord> _records = [];
Future<void> loadRecords(String vehicleId) async {
_records = await _dbHelper.getRefuelRecords(vehicleId);
}
Future<void> addRecord(RefuelRecord record) async {
await _dbHelper.insertRefuelRecord(record);
_records.insert(0, record);
}
double calculateAvgFuelConsumption() {
if (_records.length < 2) return 0;
final totalLiters = _records.fold<double>(0, (sum, r) => sum + r.liters);
final totalKm = _records.first.mileage - _records.last.mileage;
return totalKm > 0 ? (totalLiters / totalKm) * 100 : 0;
}
double getTotalCost() {
return _records.fold<double>(0, (sum, r) => sum + r.totalCost);
}
double getTotalLiters() {
return _records.fold<double>(0, (sum, r) => sum + r.liters);
}
}
5.4 违章管理器实现
class ViolationManager {
final DatabaseHelper _dbHelper = DatabaseHelper();
List<ViolationRecord> _records = [];
Future<void> loadRecords(String vehicleId) async {
_records = await _dbHelper.getViolationRecords(vehicleId);
}
Future<void> addRecord(ViolationRecord record) async {
await _dbHelper.insertViolationRecord(record);
_records.insert(0, record);
}
Future<void> markAsPaid(String recordId) async {
final index = _records.indexWhere((r) => r.id == recordId);
if (index != -1) {
_records[index] = _records[index].copyWith(
isPaid: true,
isHandled: true,
paidAt: DateTime.now(),
);
await _dbHelper.updateViolationRecord(_records[index]);
}
}
List<ViolationRecord> getUnpaidRecords() {
return _records.where((r) => !r.isPaid).toList();
}
int getTotalUnpaidFine() {
return _records.where((r) => !r.isPaid).fold<int>(0, (sum, r) => sum + r.fine);
}
}
5.5 通知管理器实现
class NotificationManager {
final FlutterLocalNotificationsPlugin _notifications =
FlutterLocalNotificationsPlugin();
Future<void> initialize() async {
const initializationSettings = InitializationSettings(
android: AndroidInitializationSettings('@mipmap/ic_launcher'),
iOS: DarwinInitializationSettings(),
);
await _notifications.initialize(initializationSettings);
}
Future<void> showMaintenanceReminder(
MaintenanceRecord record,
int daysLeft,
) async {
await _notifications.show(
record.id.hashCode,
'保养提醒',
'${record.type.label}将在$daysLeft天后到期',
NotificationDetails(
android: AndroidNotificationDetails(
'maintenance_channel',
'保养提醒',
importance: Importance.high,
),
),
);
}
Future<void> showViolationReminder(ViolationRecord record) async {
await _notifications.show(
record.id.hashCode,
'违章提醒',
'您有未处理的违章:${record.type.label}',
const NotificationDetails(
android: AndroidNotificationDetails(
'violation_channel',
'违章提醒',
importance: Importance.high,
),
),
);
}
}
5.6 数据库存储实现
class DatabaseHelper {
static Database? _database;
Future<Database> get database async {
if (_database != null) return _database!;
_database = await _initDatabase();
return _database!;
}
Future<Database> _initDatabase() async {
final path = join(await getDatabasesPath(), 'vehicle_management.db');
return await openDatabase(
path,
version: 1,
onCreate: (db, version) async {
await db.execute('''
CREATE TABLE vehicles (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
plate_number TEXT NOT NULL,
brand TEXT NOT NULL,
model TEXT NOT NULL,
year INTEGER NOT NULL,
color TEXT NOT NULL,
current_mileage INTEGER NOT NULL,
image_url TEXT,
purchase_date TEXT NOT NULL,
created_at TEXT NOT NULL
)
''');
await db.execute('''
CREATE TABLE maintenance_records (
id TEXT PRIMARY KEY,
vehicle_id TEXT NOT NULL,
type TEXT NOT NULL,
mileage INTEGER NOT NULL,
cost REAL NOT NULL,
shop TEXT,
notes TEXT,
date TEXT NOT NULL,
next_due_date TEXT NOT NULL,
next_due_mileage INTEGER NOT NULL
)
''');
await db.execute('''
CREATE TABLE refuel_records (
id TEXT PRIMARY KEY,
vehicle_id TEXT NOT NULL,
date TEXT NOT NULL,
mileage INTEGER NOT NULL,
liters REAL NOT NULL,
price REAL NOT NULL,
total_cost REAL NOT NULL,
fuel_type TEXT NOT NULL,
station TEXT,
latitude REAL,
longitude REAL
)
''');
await db.execute('''
CREATE TABLE violation_records (
id TEXT PRIMARY KEY,
vehicle_id TEXT NOT NULL,
type TEXT NOT NULL,
date TEXT NOT NULL,
location TEXT NOT NULL,
fine INTEGER NOT NULL,
points INTEGER NOT NULL,
is_paid INTEGER NOT NULL,
is_handled INTEGER NOT NULL,
paid_at TEXT
)
''');
},
);
}
}
六、交互设计
6.1 添加保养记录流程
6.2 油耗统计流程
6.3 违章处理流程
七、扩展功能规划
7.1 后续版本规划
7.2 功能扩展建议
7.2.1 智能分析
分析功能:
- 油耗异常预警
- 保养周期优化建议
- 费用趋势分析
- 驾驶习惯评估
7.2.2 社交功能
社交功能:
- 车友圈分享
- 加油站点评
- 维修店推荐
- 用车经验交流
7.2.3 服务对接
对接功能:
- 在线预约保养
- 违章在线处理
- 保险到期提醒
- 年检预约服务
八、注意事项
8.1 开发注意事项
-
数据安全:车辆信息属于隐私数据,需妥善存储
-
权限管理:正确申请定位、存储、相机等权限
-
数据同步:确保本地数据与云端保持同步
-
性能优化:大量记录时需优化查询和显示性能
-
兼容性:适配不同Android/iOS版本
8.2 常见问题
| 问题 | 原因 | 解决方案 |
|---|---|---|
| 油耗计算不准 | 记录数据不足 | 增加加油记录 |
| 保养提醒不显示 | 通知权限未开启 | 引导用户开启权限 |
| 数据丢失 | 应用被清理 | 实现数据自动备份 |
| 图片上传失败 | 存储空间不足 | 检查存储空间 |
| 定位失败 | 定位权限未授予 | 申请定位权限 |
8.3 使用技巧
🚗 车辆管理应用使用技巧 🚗
保养管理
- 定期检查保养到期提醒
- 保存保养发票和凭证
- 记录保养店铺信息
- 关注保养周期建议
加油记录
- 每次加油及时记录
- 记录加油站位置
- 关注油价变化趋势
- 分析油耗异常
违章处理
- 定期查询违章信息
- 及时处理违章罚款
- 保留处理凭证
- 注意扣分累计
九、运行说明
9.1 环境要求
| 环境 | 版本要求 |
|---|---|
| Flutter SDK | >= 3.0.0 |
| Dart SDK | >= 2.17.0 |
| 鸿蒙OS | API 21+ |
| Android | API 21+ |
| iOS | 12.0+ |
| Web浏览器 | Chrome 90+ |
9.2 依赖配置
在 pubspec.yaml 中添加以下依赖:
dependencies:
flutter:
sdk: flutter
sqflite: ^2.0.0
flutter_local_notifications: ^15.0.0
location: ^4.0.0
image_picker: ^1.0.0
path_provider: ^2.0.0
path: ^1.8.0
intl: ^0.19.0
9.3 权限配置
Android (android/app/src/main/AndroidManifest.xml):
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
iOS (ios/Runner/Info.plist):
<key>NSLocationWhenInUseUsageDescription</key>
<string>需要获取您的位置以记录加油站位置</string>
<key>NSCameraUsageDescription</key>
<string>需要访问相机以拍摄车辆证件照片</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>需要访问相册以选择车辆证件照片</string>
9.4 运行命令
# 查看可用设备
flutter devices
# 运行到Web服务器
flutter run -d web-server -t lib/main_vehicle_management.dart --web-port 8148
# 运行到鸿蒙设备
flutter run -d 127.0.0.1:5555 -t lib/main_vehicle_management.dart
# 运行到Android设备
flutter run -d android -t lib/main_vehicle_management.dart
# 代码分析
flutter analyze lib/main_vehicle_management.dart
十、总结
车辆管理应用通过保养记录管理、加油记录统计、违章信息查询、费用分析报告等功能,帮助车主便捷地管理车辆相关信息。应用支持8种保养类型记录、7种违章类型查询、油耗趋势分析、保养到期提醒等核心功能。
应用采用 Material Design 3 设计规范,以活力橙红为主色调,象征热情与动力。通过本应用,希望能够帮助车主轻松掌握爱车状况,实现车辆管理的智能化和便捷化。
车辆管理应用——您的智能用车管家
更多推荐


所有评论(0)