generated from dellevin/template
适配平板
This commit is contained in:
36
lib/widgets/master_detail_scaffold.dart
Normal file
36
lib/widgets/master_detail_scaffold.dart
Normal file
@@ -0,0 +1,36 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../utils/responsive.dart';
|
||||
|
||||
/// Master-Detail 布局包装器
|
||||
/// 手机或 detail 为 null 时只显示 master;平板显示左右分栏
|
||||
class MasterDetailScaffold extends StatelessWidget {
|
||||
final Widget master;
|
||||
final Widget? detail;
|
||||
final double masterFraction;
|
||||
final double minMasterWidth;
|
||||
|
||||
const MasterDetailScaffold({
|
||||
super.key,
|
||||
required this.master,
|
||||
this.detail,
|
||||
this.masterFraction = 0.38,
|
||||
this.minMasterWidth = 320,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!Breakpoint.isWideContent(context) || detail == null) {
|
||||
return master;
|
||||
}
|
||||
final screenWidth = MediaQuery.sizeOf(context).width;
|
||||
final effectiveMasterWidth =
|
||||
(screenWidth * masterFraction).clamp(minMasterWidth, screenWidth * 0.5);
|
||||
return Row(
|
||||
children: [
|
||||
SizedBox(width: effectiveMasterWidth, child: master),
|
||||
const VerticalDivider(width: 0.5, thickness: 0.5),
|
||||
Expanded(child: detail!),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user