feat: update layouts to allow more control on components

This commit is contained in:
2023-02-28 15:42:02 +00:00
committed by Gitea
parent 3a59230bce
commit 4029d4de03
44 changed files with 1391 additions and 60 deletions
@@ -18,30 +18,51 @@ import 'package:flutter/material.dart';
import 'package:wyatt_ui_components/wyatt_wyatt_ui_components.dart';
import 'package:wyatt_ui_layout/src/presentation/layouts/layout.dart';
class AppBarLayout extends Layout {
const AppBarLayout({
abstract class TopBarLayout<T extends TopBarComponent> extends Layout {
const TopBarLayout({
required this.body,
this.title,
this.leading,
this.actions,
this.custom,
this.height = 60,
super.key,
});
final String? title;
final Widget? leading;
final List<Widget>? actions;
final Widget body;
final T? Function(T?)? custom;
final double height;
T? child(BuildContext context);
@override
Widget build(BuildContext context) => Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(60),
child: context.components.appBar?.copyWith(
title: title.wrap(),
leading: leading,
actions: actions,
) ??
const SizedBox.shrink(),
preferredSize: Size.fromHeight(height),
child: custom?.call(child(context)) ?? const SizedBox.shrink(),
),
body: body,
);
}
class TopAppBarLayout extends TopBarLayout<TopAppBarComponent> {
const TopAppBarLayout({
required super.body,
super.custom,
super.height,
super.key,
});
@override
TopAppBarComponent? child(BuildContext context) => context.components.appBar;
}
class TopNavigationBarLayout extends TopBarLayout<TopNavigationBarComponent> {
const TopNavigationBarLayout({
required super.body,
super.custom,
super.height,
super.key,
});
@override
TopNavigationBarComponent? child(BuildContext context) =>
context.components.topNavigationBarComponent;
}
@@ -4,17 +4,18 @@ import 'package:wyatt_ui_layout/src/presentation/layouts/layout.dart';
class BottomNavigationBarLayout extends Layout {
const BottomNavigationBarLayout({
this.currentIndex,
this.body,
required this.body,
this.custom,
super.key,
});
final Widget? body;
final int? currentIndex;
final BottomNavigationBarComponent? Function(BottomNavigationBarComponent?)?
custom;
@override
Widget build(BuildContext context) => Scaffold(
body: body,
bottomNavigationBar: context.components.bottomNavigationBar?.copyWith(
currentIndex: currentIndex ?? 0,
bottomNavigationBar: custom?.call(
context.components.bottomNavigationBar,
),
);
}
@@ -21,32 +21,27 @@ import 'package:wyatt_ui_layout/src/presentation/layouts/layout.dart';
class FrameLayout extends Layout {
const FrameLayout({
required this.body,
this.title,
this.leading,
this.actions,
this.currentIndex,
this.customAppBar,
this.customBottomNavBar,
this.height = 60,
super.key,
});
final String? title;
final Widget? leading;
final List<Widget>? actions;
final TopAppBarComponent? Function(TopAppBarComponent?)? customAppBar;
final BottomNavigationBarComponent? Function(BottomNavigationBarComponent?)?
customBottomNavBar;
final Widget body;
final int? currentIndex;
final double height;
@override
Widget build(BuildContext context) => Scaffold(
appBar: PreferredSize(
preferredSize: const Size.fromHeight(60),
child: context.components.appBar?.copyWith(
title: title.wrap(),
leading: leading,
actions: actions,
) ??
preferredSize: Size.fromHeight(height),
child: customAppBar?.call(context.components.appBar) ??
const SizedBox.shrink(),
),
body: body,
bottomNavigationBar: context.components.bottomNavigationBar?.copyWith(
currentIndex: currentIndex ?? 0,
),
bottomNavigationBar:
customBottomNavBar?.call(context.components.bottomNavigationBar),
);
}