69 lines
1.5 KiB
Dart
69 lines
1.5 KiB
Dart
|
|
import 'package:shadcn_flutter/shadcn_flutter.dart';
|
|
|
|
class SidebarSwiper extends StatefulWidget {
|
|
const SidebarSwiper({
|
|
required this.sidebar,
|
|
required this.child,
|
|
super.key,
|
|
});
|
|
|
|
final Widget sidebar;
|
|
final Widget child;
|
|
|
|
@override
|
|
State<SidebarSwiper> createState() => _SidebarSwiperState();
|
|
}
|
|
|
|
class _SidebarSwiperState extends State<SidebarSwiper> {
|
|
final _controller = PageController(initialPage: 1);
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
child: PageView(
|
|
controller: _controller,
|
|
physics: const ClampingScrollPhysics(),
|
|
children: [
|
|
// page 0 - sidebar
|
|
Row(
|
|
children: [
|
|
Expanded(child: _KeepAlive(child: Scaffold(child: widget.sidebar))),
|
|
const VerticalDivider(width: 1),
|
|
],
|
|
),
|
|
|
|
// page 1 - main content
|
|
_KeepAlive(child: widget.child),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _KeepAlive extends StatefulWidget {
|
|
const _KeepAlive({required this.child});
|
|
final Widget child;
|
|
|
|
@override
|
|
State<_KeepAlive> createState() => _KeepAliveState();
|
|
}
|
|
|
|
class _KeepAliveState extends State<_KeepAlive>
|
|
with AutomaticKeepAliveClientMixin {
|
|
|
|
@override
|
|
bool get wantKeepAlive => true;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
super.build(context);
|
|
return SizedBox.expand(child: widget.child);
|
|
}
|
|
}
|