fluffychat/lib/widgets/layouts/two_column_layout.dart

76 lines
2.1 KiB
Dart
Raw Normal View History

2021-05-23 13:11:55 +02:00
import 'package:flutter/material.dart';
2022-08-30 20:24:36 +02:00
import '../../config/themes.dart';
2021-05-23 13:11:55 +02:00
class TwoColumnLayout extends StatelessWidget {
final Widget mainView;
final Widget sideView;
2021-11-19 20:28:17 +01:00
const TwoColumnLayout({
Key? key,
required this.mainView,
required this.sideView,
}) : super(key: key);
2021-05-23 13:11:55 +02:00
@override
Widget build(BuildContext context) {
final listenable = FluffyThemes.getDisplayNavigationRail(context);
2021-05-24 11:10:38 +02:00
return ScaffoldMessenger(
child: Scaffold(
body: Row(
2021-05-23 13:11:55 +02:00
children: [
// otherwise, we'd have an ugly animation where we don't want any...
listenable == null
? _FirstColumnChild(child: mainView)
: ValueListenableBuilder<bool>(
valueListenable: listenable,
child: mainView,
builder: (context, open, child) =>
LayoutBuilder(builder: (context, constraints) {
final width = open &&
MediaQuery.of(context).size.width >
FluffyThemes.hugeScreenBreakpoint
? 256.0
: 64.0;
return _FirstColumnChild(
drawerWidth: width,
child: child,
);
}),
),
2021-05-23 13:11:55 +02:00
Container(
width: 1.0,
color: Theme.of(context).dividerColor,
),
Expanded(
child: ClipRRect(
child: sideView,
),
),
],
),
),
);
}
}
class _FirstColumnChild extends StatelessWidget {
final Widget? child;
final double drawerWidth;
const _FirstColumnChild({Key? key, required this.child, this.drawerWidth = 0})
: super(key: key);
@override
Widget build(BuildContext context) {
return AnimatedContainer(
clipBehavior: Clip.antiAlias,
decoration: const BoxDecoration(),
width: 360.0 + drawerWidth,
duration: const Duration(milliseconds: 250),
curve: Curves.easeOut,
child: child,
);
}
}