Skip to content

Commit

Permalink
Uh oh
Browse files Browse the repository at this point in the history
  • Loading branch information
Pante committed Dec 5, 2024
1 parent 8aa9561 commit a4a87f0
Show file tree
Hide file tree
Showing 15 changed files with 572 additions and 34 deletions.
8 changes: 8 additions & 0 deletions docs/pages/docs/overlay/_meta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
dialog: 'Dialog',
popover: 'Popover',
'popover-menu': 'Popover Menu',
'sheet': 'Sheet',
'modal-sheet': 'Modal Sheet',
tooltip: 'Tooltip',
};
212 changes: 212 additions & 0 deletions docs/pages/docs/overlay/sheet.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
import { Callout, Tabs } from 'nextra/components';
import { Widget } from "../../../components/widget.tsx";
import LinkBadge from "../../../components/link-badge/link-badge.tsx";
import LinkBadgeGroup from "../../../components/link-badge/link-badge-group.tsx";

# Sheet

A sheet that are displayed above another widget. It is part of [FScaffold](/docs/layout/scaffold), which should be
preferred in most cases.

<LinkBadgeGroup>
<LinkBadge label="API Reference" href="https://pub.dev/documentation/forui/latest/forui.widgets.sheet/forui.widgets.sheet-library.html"/>
</LinkBadgeGroup>

<Callout type="info">
All calls to `showFSheet(...)` should be made inside widgets that have either `FScaffold` or `Sheets` as their
</Callout>

<Tabs items={['Preview', 'Code']}>
<Tabs.Tab>
<Widget name='sheets' query={{}} height={500}/>
</Tabs.Tab>
<Tabs.Tab>
```dart
class Sheets extends StatefulWidget {
@override
State<Sheets> createState() => _State();
}
class _State extends State<Sheets> {
final Map<Layout, FSheetController> _controllers = {};
@override
Widget build(BuildContext context) {
VoidCallback onPress(Layout side) => () {
var controller = _controllers[side];
if (controller == null) {
controller = _controllers[side] ??= showFSheet(
context: context,
side: Layout.ltr,
builder: (context) => Form(side: side),
);
} else {
controller.toggle();
}
};
return FScaffold( // This can be replaced with FSheets
content: Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
FButton(
label: const Text('Left'),
onPress: onPress(Layout.ltr),
),
const SizedBox(height: 5),
FButton(
label: const Text('Top'),
onPress: onPress(Layout.ttb),
),
const SizedBox(height: 5),
FButton(
label: const Text('Right'),
onPress: onPress(Layout.rtl),
),
const SizedBox(height: 5),
FButton(
label: const Text('Bottom'),
onPress: onPress(Layout.btt),
),
],
),
);
}
}
class Form extends StatelessWidget {
final Layout side;
const Form({required this.side, super.key});
@override
Widget build(BuildContext context) => Container(
height: double.infinity,
width: double.infinity,
decoration: BoxDecoration(
color: context.theme.colorScheme.background,
border: side.vertical
? Border.symmetric(horizontal: BorderSide(color: context.theme.colorScheme.border))
: Border.symmetric(vertical: BorderSide(color: context.theme.colorScheme.border)),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8.0),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Account',
style: context.theme.typography.xl2.copyWith(
fontWeight: FontWeight.w600,
color: context.theme.colorScheme.foreground,
height: 1.5,
),
),
Text(
'Make changes to your account here. Click save when you are done.',
style: context.theme.typography.sm.copyWith(
color: context.theme.colorScheme.mutedForeground,
),
),
const SizedBox(height: 8),
SizedBox(
width: 450,
child: Column(
children: [
const FTextField(
label: Text('Name'),
hint: 'John Renalo',
),
const SizedBox(height: 10),
const FTextField(
label: Text('Email'),
hint: '[email protected]',
),
const SizedBox(height: 16),
FButton(
label: const Text('Save'),
onPress: () => Navigator.of(context).pop(),
),
],
),
),
],
),
),
),
);
@override
void dispose() {
for (final controller in _controllers.values) {
controller.dispose();
}
super.dispose();
}
}
```
</Tabs.Tab>
</Tabs>

## Usage

### `showFSheet(...)`

```dart
showFSheet(
context: context,
side: Layout.ltr,
useRootNavigator: true,
useSafeArea: false,
keepAliveOffstage: true,
mainAxisMaxRatio: null,
constraints: const BoxConstraints(maxWidth: 450, maxHeight: 450),
draggable: true,
builder: (context) => const Placeholder(),
);
```

## Examples

### With `DraggableScrollableSheet`

<Tabs items={['Preview', 'Code']}>
<Tabs.Tab>
<Widget name='sheets' query={{}} height={400} variant='draggable'/>
</Tabs.Tab>
<Tabs.Tab>
```dart
FScaffold( // This can be replaced with FSheets
content: FButton(
label: const Text('Click me'),
onPress: () => showFSheet(
context: context,
side: Layout.btt,
mainAxisMaxRatio: null,
builder: (context) => DraggableScrollableSheet(
expand: false,
builder: (context, controller) => ScrollConfiguration(
// This is required to enable dragging on desktop.
// See https://github.com/flutter/flutter/issues/101903 for more information.
behavior: ScrollConfiguration.of(context).copyWith(dragDevices: {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
PointerDeviceKind.trackpad,
}),
child: FTileGroup.builder(
count: 25,
controller: controller,
tileBuilder: (context, index) => FTile(title: Text('Tile $index')),
),
),
),
),
),
);
```
</Tabs.Tab>
</Tabs>

10 changes: 10 additions & 0 deletions forui/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

### Additions

* Add `showFSheet(...)`.

* Add `showFModalSheet(...)`.

* Add `FModalSheetRoute`.

* Add `FSheets`.

* Add `FSheets` internally to `FScaffold`.

* Add `truncateAndStripTimezone` to `FCalendarController.date(...)`.

* Add `truncateAndStripTimezone` to `FCalendarController.dates(...)`.
Expand Down
73 changes: 68 additions & 5 deletions forui/example/lib/sandbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ class Sandbox extends StatefulWidget {

class _SandboxState extends State<Sandbox> with SingleTickerProviderStateMixin {
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
final FRadioSelectGroupController<Notification> controller = FRadioSelectGroupController();
late FPopoverController popoverController;
late FCalendarController<DateTime?> a = FCalendarController.date();
late AnimationController controller;

@override
void initState() {
super.initState();
popoverController = FPopoverController(vsync: this);
controller = AnimationController(vsync: this, duration: const Duration(milliseconds: 300));
}

@override
Expand All @@ -41,11 +39,76 @@ class _SandboxState extends State<Sandbox> with SingleTickerProviderStateMixin {
),
],
),
);
);

@override
void dispose() {
controller.dispose();
super.dispose();
}
}

class AForm extends StatelessWidget {
final Layout side;

const AForm({required this.side, super.key});

@override
Widget build(BuildContext context) => Container(
height: double.infinity,
width: double.infinity,
decoration: BoxDecoration(
color: context.theme.colorScheme.background,
border: side.vertical
? Border.symmetric(horizontal: BorderSide(color: context.theme.colorScheme.border))
: Border.symmetric(vertical: BorderSide(color: context.theme.colorScheme.border)),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 8.0),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Account',
style: context.theme.typography.xl2.copyWith(
fontWeight: FontWeight.w600,
color: context.theme.colorScheme.foreground,
height: 1.5,
),
),
Text(
'Make changes to your account here. Click save when you are done.',
style: context.theme.typography.sm.copyWith(
color: context.theme.colorScheme.mutedForeground,
),
),
const SizedBox(height: 8),
SizedBox(
width: 450,
child: Column(
children: [
const FTextField(
label: Text('Name'),
hint: 'John Renalo',
),
const SizedBox(height: 10),
const FTextField(
label: Text('Email'),
hint: '[email protected]',
),
const SizedBox(height: 16),
FButton(
label: const Text('Save'),
onPress: () => Navigator.of(context).pop(),
),
],
),
),
],
),
),
),
);
}
20 changes: 10 additions & 10 deletions forui/lib/src/widgets/scaffold.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class FScaffold extends StatefulWidget {
}

class _State extends State<FScaffold> {
FSheetController? _sheet;

@override
Widget build(BuildContext context) {
final style = widget.style ?? context.theme.scaffoldStyle;
Expand All @@ -63,14 +61,16 @@ class _State extends State<FScaffold> {
content = Padding(padding: style.contentPadding, child: content);
}

return ColoredBox(
color: style.backgroundColor,
child: Column(
children: [
if (widget.header != null) DecoratedBox(decoration: style.headerDecoration, child: widget.header!),
Expanded(child: content),
if (widget.footer != null) DecoratedBox(decoration: style.footerDecoration, child: widget.footer!),
],
return FSheets(
child: ColoredBox(
color: style.backgroundColor,
child: Column(
children: [
if (widget.header != null) DecoratedBox(decoration: style.headerDecoration, child: widget.header!),
Expanded(child: content),
if (widget.footer != null) DecoratedBox(decoration: style.footerDecoration, child: widget.footer!),
],
),
),
);
}
Expand Down
2 changes: 1 addition & 1 deletion forui/lib/src/widgets/sheet/sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ class _SheetState extends State<Sheet> with SingleTickerProviderStateMixin {

@override
void dispose() {
super.dispose();
if (widget.controller == null) {
_controller.dispose();
}
super.dispose();
}
}

Expand Down
Loading

0 comments on commit a4a87f0

Please sign in to comment.