//s1 Imports //s2 Core Package Imports import 'package:flutter/material.dart'; //s2 1st-party Package Imports //s2 3rd-party Package Imports import 'package:provider/provider.dart'; //s2 Dependancies Imports //s3 Routes //s3 Services import '../../dependencies/vsync-provider/vsync_provider.dart'; //s3 Models import '../form/form_helper.astromic.dart'; import '../sheet/src/models/models.exports.dart'; import '../sheet/src/enums/enums.exports.dart'; import '../sheet/src/widgets/widgets.exports.dart'; //s1 Exports export '../sheet/src/models/models.exports.dart'; export '../form/form_helper.astromic.dart' show AstromicFormController; class AstromicSheetHelper { static VsyncProviderState? _vsyncState; /// A wrapper to initialize the vSync plugin for the sheets' animations. static Widget vSyncBuilder(Widget child) { return VsyncProvider(child: child); } /// An initializer method to initialize the vSync state. static _initializevSync(BuildContext context) { _vsyncState = VsyncProvider.of(context); } /// Show FLEX sheet, a flexible sheet that hugs the height of it's content. static Future flex( BuildContext context, { // Widget Function(SheetStore store)? headSection, required Widget Function(SheetStore store) contentSection, Widget Function(SheetStore store)? footerSection, // AstromicSheetConfiguration? configuration, AstromicSheetStyle? style, // }) async { if (_vsyncState == null) { _initializevSync(context); } AstromicSheetConfiguration sheetConfigs = configuration ?? const AstromicSheetConfiguration(); AstromicSheetStyle sheetStyle = style ?? const AstromicSheetStyle(); SheetStore store = SheetStore(); return await BasicSheet.show( context: context, vsyncState: _vsyncState!, // useRootNavigator: sheetConfigs.useRootNavigator, enableOutsideInteraction: sheetConfigs.enableOutsideInteraction, enableSheetInteraction: sheetConfigs.enableSheetInteraction, // forwardAnimationDuration: sheetConfigs.forwardAnimationDuration ?? const Duration(milliseconds: 250), reverseAnimationDuration: sheetConfigs.reverseAnimationDuration ?? const Duration(milliseconds: 250), animationCurve: sheetConfigs.animationCurve ?? Curves.easeOut, // barrierColor: sheetStyle.maskColor, radius: sheetStyle.radius, // child: ChangeNotifierProvider( create: (BuildContext c) => store, child: BaseSheetWidget( sheetConfiguration: sheetConfigs, sheetStyle: sheetStyle, // headSection: headSection?.call(store), contentSection: contentSection(store), footerSection: footerSection?.call(store), )), ); } /// Show FLEX sheet using a pre-set FlexSheetTemplate. static Future flexTemplate(BuildContext context, AstromicFlexSheetTemplate template) async => await flex( context, headSection: template.headSection, contentSection: template.contentSection, footerSection: template.footerSection, // configuration: template.configuration, style: template.style, ); /// Show Form sheet, a FLEX sheet but with an integrated form controller. static Future form( BuildContext context, { // Widget Function(AstromicFormController, SheetStore store)? headSectionBuilder, required Widget Function(AstromicFormController, SheetStore store) contentSectionBuilder, Widget Function(AstromicFormController, SheetStore store)? footerSectionBuilder, // AstromicSheetConfiguration? configuration, AstromicSheetStyle? style, }) async { if (_vsyncState == null) { _initializevSync(context); } AstromicSheetConfiguration sheetConfigs = configuration ?? const AstromicSheetConfiguration(); AstromicSheetStyle sheetStyle = style ?? const AstromicSheetStyle(); SheetStore store = SheetStore(); return await BasicSheet.show( context: context, vsyncState: _vsyncState!, // useRootNavigator: sheetConfigs.useRootNavigator, enableOutsideInteraction: sheetConfigs.enableOutsideInteraction, enableSheetInteraction: sheetConfigs.enableSheetInteraction, // forwardAnimationDuration: sheetConfigs.forwardAnimationDuration ?? const Duration(milliseconds: 250), reverseAnimationDuration: sheetConfigs.reverseAnimationDuration ?? const Duration(milliseconds: 250), animationCurve: sheetConfigs.animationCurve ?? Curves.easeOut, // barrierColor: sheetStyle.maskColor, radius: sheetStyle.radius, // child: ChangeNotifierProvider( create: (BuildContext c) => store, child: BaseSheetWidget( sheetType: SheetType.form, // sheetConfiguration: sheetConfigs, sheetStyle: sheetStyle, // headSectionFormBuilder: headSectionBuilder == null ? null : (AstromicFormController controller) => headSectionBuilder.call(controller, store), contentSectionFormBuilder: (AstromicFormController controller) => contentSectionBuilder(controller, store), footerSectionFormBuilder: footerSectionBuilder == null ? null : (AstromicFormController controller) => footerSectionBuilder.call(controller, store), ), ), ); } /// Show Form sheet using a pre-set FormSheetTemplate. static Future formTemplate(BuildContext c, AstromicFormSheetTemplate template) async => await form( c, headSectionBuilder: template.headSectionBuilder, contentSectionBuilder: template.contentSectionBuilder, footerSectionBuilder: template.footerSectionBuilder, // configuration: template.configuration, style: template.style, // ); /// Show Scroller sheet, a sheet that contains a vertically scrollable elements with some tweeks for animation. static Future scroller( BuildContext context, { // Widget Function(ScrollController, SheetStore store)? headSectionBuilder, required Widget Function(ScrollController, ScrollPhysics, SheetStore store) contentSectionBuilder, Widget Function(ScrollController, SheetStore store)? footerSectionBuilder, // AstromicSheetConfiguration? configuration, AstromicSheetStyle? style, }) async { if (_vsyncState == null) { _initializevSync(context); } AstromicSheetConfiguration sheetConfigs = configuration ?? const AstromicSheetConfiguration(); AstromicSheetStyle sheetStyle = style ?? const AstromicSheetStyle(); SheetStore store = SheetStore(); return await ScrollerSheet.show( context: context, vsyncState: _vsyncState!, // useRootNavigator: sheetConfigs.useRootNavigator, enableOutsideInteraction: sheetConfigs.enableOutsideInteraction, enableSheetInteraction: sheetConfigs.enableSheetInteraction, respectKeyboardInset: sheetConfigs.respectKeyboardInset, // forwardAnimationDuration: sheetConfigs.forwardAnimationDuration ?? const Duration(milliseconds: 250), reverseAnimationDuration: sheetConfigs.reverseAnimationDuration ?? const Duration(milliseconds: 250), animationCurve: sheetConfigs.animationCurve ?? Curves.easeOut, dragThreshold: sheetConfigs.dragThreshold ?? 25, // physics: sheetConfigs.physics, stops: sheetConfigs.expandedHeightFactor != null && (sheetConfigs.expandedHeightFactor! > sheetConfigs.initialHeightFactor) ? [sheetConfigs.initialHeightFactor, sheetConfigs.expandedHeightFactor].map((double? s) { double r = sheetConfigs.safeAreaAware ? ((s! * MediaQuery.of(context).size.height) - MediaQuery.of(context).viewPadding.top) : (s! * MediaQuery.of(context).size.height); return r; }).toList() : [ sheetConfigs.initialHeightFactor, ].map((double s) { double r = sheetConfigs.safeAreaAware ? ((s * MediaQuery.of(context).size.height) - MediaQuery.of(context).viewPadding.top) : (s * MediaQuery.of(context).size.height); return r; }).toList(), // s2 -- Styling barrierColor: sheetStyle.maskColor, topInset: sheetStyle.topInset, // s2 -- Child builder: (BuildContext context, ScrollController scrollController, ScrollPhysics scrollPhysics, int stop) { return ChangeNotifierProvider( create: (BuildContext c) => store, child: BaseSheetWidget( sheetType: SheetType.scroller, sheetConfiguration: sheetConfigs, sheetStyle: sheetStyle, headSectionScrollerBuilder: headSectionBuilder == null ? null : (ScrollController controller) => headSectionBuilder.call(controller, store), contentSectionScrollBuilder: (ScrollController controller, ScrollPhysics physics) => contentSectionBuilder(controller,physics, store), footerSectionScrollerBuilder: footerSectionBuilder == null ? null : (ScrollController controller) => footerSectionBuilder.call(controller, store), scrollController: scrollController, scrollPhysics: scrollPhysics, ), ); }, ); } /// Show Scroller sheet using a pre-set ScrollerSheetTemplate. static Future scrollerTemplate(BuildContext context, AstromicScrollerSheetTemplate template) async => await scroller( context, headSectionBuilder: template.headSectionBuilder, contentSectionBuilder: template.contentSectionBuilder, footerSectionBuilder: template.footerSectionBuilder, // configuration: template.configuration, style: template.style, ); }