Skip to content

Commit

Permalink
Complete refactoring VWSheet to use extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
carllosnc committed Nov 3, 2024
1 parent 2d7474f commit ed97e0e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
19 changes: 6 additions & 13 deletions example/lib/examples/vw_sheet_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,49 +22,44 @@ class _VWSheetExampleState extends State<VWSheetExample> {
FilledButton(
child: const Text('Open first page'),
onPressed: () {
VWSheet.open(
context.openSheet(
level: 1,
context: context,
appBar: AppBar(
title: const Text('First page'),
),
body: Center(
child: FilledButton(
child: const Text('open second page'),
onPressed: () {
VWSheet.open(
context.openSheet(
level: 2,
context: context,
appBar: AppBar(
title: const Text('Second page'),
),
body: Center(
child: FilledButton(
child: const Text('open third page'),
onPressed: () {
VWSheet.open(
context.openSheet(
level: 3,
context: context,
appBar: AppBar(
title: const Text('Third page'),
),
body: Center(
child: FilledButton(
child: const Text('open fourth page'),
onPressed: () {
VWSheet.open(
context.openSheet(
level: 4,
context: context,
appBar: AppBar(
title: const Text('Fourth page'),
),
body: Center(
child: FilledButton(
child: const Text('open fifth page'),
onPressed: () {
VWSheet.open(
context.openSheet(
level: 5,
context: context,
appBar: AppBar(
title: const Text('Fifth page'),
),
Expand Down Expand Up @@ -92,9 +87,7 @@ class _VWSheetExampleState extends State<VWSheetExample> {
),
FilledButton(
onPressed: () {
VWSheet.open(
borderRadius: 28,
context: context,
context.openSheet(
appBar: AppBar(
leading: IconButton(
icon: const Icon(Icons.close),
Expand Down
14 changes: 5 additions & 9 deletions lib/vw_sheet.dart → lib/extensions/vw_sheet_extension.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import 'package:flutter/material.dart';

sealed class VWSheet {
static Future<dynamic> open({
extension BottomSheetExtension on BuildContext {
openSheet({
///[appBar] is the header of the page.
required AppBar appBar,

///[context] is the BuildContext of the page.
required BuildContext context,

///[bottomBar] is the bottom bar of the page.
Widget? bottomBar,

Expand All @@ -26,11 +23,11 @@ sealed class VWSheet {
///[borderColor] is the border color of the page.
bool isScrollControlled = true,
}) {
return showModalBottomSheet(
showModalBottomSheet(
useSafeArea: true,
backgroundColor: Colors.transparent,
isScrollControlled: isScrollControlled,
context: context,
context: this,
builder: (context) {
return Container(
height: MediaQuery.of(context).size.height * 0.96 - (15 * level),
Expand All @@ -42,8 +39,7 @@ sealed class VWSheet {
),
),
child: Scaffold(
backgroundColor:
backgroundColor ?? Theme.of(context).colorScheme.surface,
backgroundColor: backgroundColor ?? Theme.of(context).colorScheme.surface,
appBar: appBar,
body: body,
bottomNavigationBar: bottomBar,
Expand Down
4 changes: 3 additions & 1 deletion lib/vw.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
export './vw_column.dart';
export './vw_row.dart';
export './vw_button.dart';
export './vw_sheet.dart';
export './vw_timepicker.dart';
export './vw_select.dart';
export './vw_modal.dart';
export './vw_box.dart';
export './vw_reveal.dart';
export './vw_text.dart';
export './vw_if.dart';

// Extensions
export './extensions/vw_screen_size_extension.dart';
export './extensions/vw_text_extension.dart';
export './extensions/vw_sheet_extension.dart';
9 changes: 3 additions & 6 deletions test/vw_sheet_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ void main() {
return Center(
child: FilledButton(
onPressed: () {
VWSheet.open(
context.openSheet(
appBar: AppBar(
title: const Text('VW Sheet header'),
),
context: context,
body: const Center(
child: Text('VW Sheet body'),
),
Expand Down Expand Up @@ -59,9 +58,8 @@ void main() {
return FilledButton(
child: const Text('Open first page'),
onPressed: () {
VWSheet.open(
context.openSheet(
level: 1,
context: context,
appBar: AppBar(
title: const Text('First page'),
actions: [
Expand All @@ -77,9 +75,8 @@ void main() {
child: FilledButton(
child: const Text('open second page'),
onPressed: () {
VWSheet.open(
context.openSheet(
level: 2,
context: context,
appBar: AppBar(
title: const Text('Second page'),
actions: [
Expand Down

0 comments on commit ed97e0e

Please sign in to comment.