首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >原创自研Flutter3.41+Dio+WindowManager打造桌面版AI问答系统

原创自研Flutter3.41+Dio+WindowManager打造桌面版AI问答系统

原创
作者头像
andy2018
发布2026-04-15 22:58:02
发布2026-04-15 22:58:02
820
举报
文章被收录于专栏:h5h5

基于flutter3.41.5+get+dio+window_manager对接deepseek-chat实战客户端ai流式会话系统。

项目技术选型

  • 编辑器:VScode
  • 跨平台技术框架:flutter3.41.5+dart3.11.3
  • 大模型框架:deepseek-v3.2
  • 流式请求:dio^5.9.2
  • 路由/状态管理:get^4.7.3
  • 存储服务:get_storage^2.1.1
  • markdown解析:flutter_markdown_plus^1.0.7
  • 环境变量配置:flutter_dotenv^6.0.0
  • 窗口管理:window_manager^0.5.1
  • 托盘管理:system_tray^2.0.3

项目结构目录

基于最新跨平台技术flutter3.41.5初始化项目,集成deepseek大模型。

项目公共结构模板

代码语言:actionscript
复制
return Scaffold(
  backgroundColor: Colors.grey[50],
  body: DragToResizeArea(
    child: Row(
      children: [
        // 侧边栏
        AnimatedSize(
          duration: const Duration(milliseconds: 300),
          curve: Curves.easeInOut,
          child: Container(
            width: collapsed ? 0 : 260,
            decoration: BoxDecoration(
              border: Border(right: BorderSide(color: Colors.grey.withAlpha(50)))
            ),
            child: Material(
              color: Color(0xFFF3F3F3),
              child: Sidebar(),
            ),
          ),
        ),
        // 主体容器
        Expanded(
          child: Column(
            children: [
              // 自定义导航栏
              SizedBox(
                height: 30.0,
                child: Row(
                  children: [
                    IconButton(
                      onPressed: () {
                        setState(() {
                          collapsed = !collapsed;
                        });
                      },
                      icon: Icon(collapsed ? Icons.format_indent_increase : Icons.format_indent_decrease, size: 16.0,),
                      tooltip: collapsed ? '展开' : '收缩',
                    ),
                    Expanded(
                      child: DragToMoveArea(
                        child: SizedBox(
                          height: double.infinity,
                        ),
                      ),
                    ),
                    // 右上角操作按钮
                    WinBtns(
                      leading: Row(
                        children: [
                          ...
                        ],
                      ),
                    ),
                  ],
                ),
              ),
              // 右侧主面板
              Expanded(
                child: Container(
                  child: widget.child,
                ),
              ),
            ],
          ),
        ),
      ],
    ),
  ),
);

flutter3-ai对话编辑框

代码语言:actionscript
复制
return Container(
  width: double.infinity,
  padding: EdgeInsets.symmetric(vertical: 10.0),
  child: Column(
    spacing: 6.0,
    children: [
      // 技能栏
      if (widget.skillbar)
      ScrollConfiguration(
        behavior: CustomScrollBehavior(),
        child: SingleChildScrollView(
          scrollDirection: Axis.horizontal,
          padding: EdgeInsets.symmetric(horizontal: 15.0),
          child: Row(
            spacing: 4.0,
            children: [
              ...
            ]
          ),
        ),
      ),
      // 编辑框
      Container(
        margin: EdgeInsets.symmetric(horizontal: 15.0),
        padding: EdgeInsets.all(10.0),
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border.all(color: Colors.grey.withAlpha(100), width: .5),
          borderRadius: BorderRadius.circular(15.0),
          boxShadow: [
            BoxShadow(
              color: Colors.black.withAlpha(20),
              offset: Offset(0.0, 3.0),
              blurRadius: 6.0,
              spreadRadius: 0.0,
            ),
          ]
        ),
        child: Column(
          spacing: 10.0,
          children: [
            // 输入框
            ConstrainedBox(
              constraints: BoxConstraints(minHeight: 48.0, maxHeight: 150.0),
              child: TextField(
                ...
              ),
            ),
            // 操作栏
            Row(
              spacing: 10.0,
              children: [
                SizedBox(
                  height: 30.0,
                  child: TextButton(
                    onPressed: () {
                      // ...
                    },
                    style: ButtonStyle(
                      backgroundColor: WidgetStateProperty.all(isDeep ? Color(0xFF4F6BFE).withAlpha(30) : Colors.grey[200]),
                      padding: WidgetStateProperty.all(EdgeInsets.symmetric(horizontal: 10.0)),
                    ),
                    child: Row(
                      spacing: 4.0,
                      children: [
                        Icon(Icons.stream, color: isDeep ? Color(0xFF4F6BFE) : Colors.black, size: 18.0,),
                        Text('深度思考(R1)', style: TextStyle(color: isDeep ? Color(0xFF4F6BFE) : Colors.black, fontSize: 13.0),),
                      ],
                    ),
                  ),
                ),
                SizedBox(
                  height: 30.0,
                  child: TextButton(
                    onPressed: () {
                      // ...
                    },
                    style: ButtonStyle(
                      backgroundColor: WidgetStateProperty.all(isNetwork ? Color(0xFF4F6BFE).withAlpha(30) : Colors.grey[200]),
                      padding: WidgetStateProperty.all(EdgeInsets.symmetric(horizontal: 10.0)),
                    ),
                    child: Row(
                      spacing: 4.0,
                      children: [
                        Icon(Icons.travel_explore, color: isNetwork ? Color(0xFF4F6BFE) : Colors.black, size: 18.0,),
                        Text('联网', style: TextStyle(color: isNetwork ? Color(0xFF4F6BFE) : Colors.black, fontSize: 13.0),),
                      ],
                    ),
                  ),
                ),
                Spacer(),
                SizedBox(
                  height: 30.0,
                  width: 30.0,
                  child: IconButton(
                    ...
                  ),
                ),
                SizedBox(
                  height: 30.0,
                  width: 30.0,
                  child: IconButton(
                    ...
                  ),
                )
              ],
            ),
          ],
        ),
      ),
    ],
  )
);

flutter3+dio实现流式stream输出

代码语言:actionscript
复制
// 调用deepseek接口
final response = await dio.post(
  '$baseURL/v1/chat/completions',
  options: Options(
    // 响应超时
    receiveTimeout: const Duration(seconds: 60),
    headers: {
      "Content-Type": "application/json",
      "Authorization": "Bearer $apiKEY",
    },
    // 设置响应类型为流式响应
    responseType: ResponseType.stream,
  ),
  data: {
    // 多轮会话
    'messages': widget.multiConversation ? chatStore.historySession : [{'role': 'user', 'content': editorValue}],
    // deepseek-chat对话模型 deepseek-reasoner推理模型
    'model': chatStore.getSetting('thinkingEnabled') ? 'deepseek-reasoner' : 'deepseek-chat',
    'stream': true, // 流式输出
    'max_tokens': 8192, // 限制一次请求中模型生成 completion 的最大 token 数(默认使用 4096)
    'temperature': 0.4, // 严谨采样 越低越严谨(默认1)
  }
);

flutter3自定义系统托盘

代码语言:actionscript
复制
// 初始化系统托盘
Future<void> initSystemTray() async {
  String trayIco = 'assets/images/tray.ico';
  SystemTray systemTray = SystemTray();

  // 初始化系统托盘
  await systemTray.initSystemTray(
    title: 'system-tray',
    iconPath: trayIco,
  );

  // 右键菜单
  final Menu menu = Menu();
  await menu.buildFrom([
    MenuItemLabel(label: '打开主界面', image: 'assets/images/tray.ico', onClicked: (menuItem) async => await windowManager.show()),
    MenuItemLabel(label: '隐藏窗口', image: 'assets/images/tray.ico', onClicked: (menuItem) async => await windowManager.hide()),
    MenuItemLabel(label: '设置中心', image: 'assets/images/tray.ico', onClicked: (menuItem) => Get.toNamed('/setting')),
    MenuItemLabel(label: '锁屏', image: 'assets/images/tray.ico', onClicked: (menuItem) => {}),
    MenuItemLabel(label: '关闭程序并退出', image: 'assets/images/tray.ico', onClicked: (menuItem) async => await windowManager.destroy()),
  ]);
  await systemTray.setContextMenu(menu);

  // 右键事件
  systemTray.registerSystemTrayEventHandler((eventName) async {
    debugPrint('eventName: $eventName');
    if (eventName == kSystemTrayEventClick) {
      Platform.isWindows ? await windowManager.show() : systemTray.popUpContextMenu();
    } else if (eventName == kSystemTrayEventRightClick) {
      Platform.isWindows ? systemTray.popUpContextMenu() : await windowManager.show();
    }
  });
}

推荐热文

Flutter3.41实战AI:从零到一构建app版流式ai系统

Electron41 + Vite8打造流式输出客户端AI助手

Vite8.0+Vue3.5+Arco深度对接DeepSeek网页版AI智能助手

2026版開工新作uni-app+mphtml结合deepseek跨端ai应用

vite7.2-deepseek流式ai对话|vue3.5+vant4+katex+mermaid智能ai打字会话

最新实战Vite7.3+Tauri2.10深度集成DeepSeek桌面端AI智能助手

electron38-vite7-vue3os电脑端os管理系统

最新版electron38-vite7-admin电脑端中后台管理系统

Electron38+Vite7+Pinia3+ElementPlus客户端聊天程序

基于tauri2.8+vite7+vue3+element-plus仿QQ/微信聊天应用

tauri2.9-vite7-vue3admin客户端后台系统管理Exe模板

最新原创uniapp-vue3-osadmin手机版后台管理系统

最新研发uniapp+vue3仿微信app聊天模板

最新原创flutter3.27+bitsdojo_window客户端聊天Exe

自研新版Flutter3.32仿微信app聊天|朋友圈模板

基于uni-app+vue3实战短视频+聊天+直播app商城

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 项目技术选型
  • 项目结构目录
  • 项目公共结构模板
  • flutter3-ai对话编辑框
  • flutter3+dio实现流式stream输出
  • flutter3自定义系统托盘
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档