You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

104 lines
3.4 KiB

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:win_text_editor/app/menus/app_menu.dart';
import 'package:win_text_editor/app/providers/tab_provider.dart';
import 'package:win_text_editor/app/providers/file_provider.dart';
import 'package:win_text_editor/app/widgets/editor_pane.dart';
import 'package:win_text_editor/app/widgets/file_explorer.dart';
import 'package:win_text_editor/app/widgets/console_panel.dart'; // 新增导入
class AppScaffold extends StatelessWidget {
const AppScaffold({super.key});
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (_) => FileProvider()),
ChangeNotifierProvider(create: (_) => TabProvider()),
],
child: const Scaffold(
body: Column(
children: [
// 菜单栏
AppMenu(),
// 主内容区域
Expanded(child: _ResizablePanel()),
],
),
),
);
}
}
class _ResizablePanel extends StatefulWidget {
const _ResizablePanel();
@override
State<_ResizablePanel> createState() => _ResizablePanelState();
}
class _ResizablePanelState extends State<_ResizablePanel> {
double _leftWidth = 0.2; // 初始宽度20%
final double _minWidth = 100; // 最小宽度
final double _maxWidth = 400; // 最大宽度
@override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
return LayoutBuilder(
builder: (context, constraints) {
// 计算实际宽度
final leftPanelWidth = (_leftWidth * screenWidth).clamp(_minWidth, _maxWidth);
return Column(
children: [
Expanded(
child: Row(
children: [
// 左侧文件资源管理器 - 添加Material小部件包裹
Material(
elevation: 1, // 轻微阴影分隔
child: SizedBox(
width: leftPanelWidth,
child: const ClipRect(
// 确保内容被裁剪
child: FileExplorer(),
),
),
),
// 拖拽手柄
GestureDetector(
behavior: HitTestBehavior.translucent,
onPanUpdate: (details) {
setState(() {
_leftWidth = ((leftPanelWidth + details.delta.dx) / screenWidth).clamp(
_minWidth / screenWidth,
_maxWidth / screenWidth,
);
});
},
child: MouseRegion(
cursor: SystemMouseCursors.resizeLeftRight,
child: Container(width: 4, color: Colors.grey[300]),
),
),
// 右侧编辑器区域 - 添加Material背景
const Expanded(
child: Material(
color: Colors.white,
child: Column(children: [Expanded(child: EditorPane())]),
),
),
],
),
),
// 控制台面板
const ConsolePanel(),
],
);
},
);
}
}