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.
90 lines
2.6 KiB
90 lines
2.6 KiB
2 months ago
|
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/editor_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';
|
||
|
|
||
|
class AppScaffold extends StatelessWidget {
|
||
|
const AppScaffold({super.key});
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return MultiProvider(
|
||
|
providers: [
|
||
|
ChangeNotifierProvider(create: (_) => FileProvider()),
|
||
|
ChangeNotifierProvider(create: (_) => EditorProvider()),
|
||
|
],
|
||
|
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 Row(
|
||
|
children: [
|
||
|
// 左侧文件资源管理器
|
||
|
SizedBox(
|
||
|
width: leftPanelWidth,
|
||
|
child: const 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],
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
// 右侧编辑器区域
|
||
|
Expanded(
|
||
|
child: const EditorPane(),
|
||
|
),
|
||
|
],
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
}
|
||
|
}
|