This commit is contained in:
2025-02-27 18:08:08 +02:00
commit 499020323e
48 changed files with 3036 additions and 0 deletions

View File

@@ -0,0 +1,219 @@
//s1 Imports
//s2 Core Package Imports
import 'package:flutter/material.dart';
//s2 1st-party Package Imports
//s2 3rd-party Package Imports
//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<T?> flex<T extends Object?>(
BuildContext context, {
//
Widget? headSection,
required Widget contentSection,
Widget? footerSection,
//
AstromicSheetConfiguration? configuration,
AstromicSheetStyle? style,
//
}) async {
if (_vsyncState == null) {
_initializevSync(context);
}
AstromicSheetConfiguration sheetConfigs = configuration ?? const AstromicSheetConfiguration();
AstromicSheetStyle sheetStyle = style ?? const AstromicSheetStyle();
return await BasicSheet.show<T>(
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: BaseSheetWidget<T?>(
sheetConfiguration: sheetConfigs,
sheetStyle: sheetStyle,
//
headSection: headSection,
contentSection: contentSection,
footerSection: footerSection,
),
);
}
/// Show FLEX sheet using a pre-set FlexSheetTemplate.
static Future<T?> flexTemplate<T extends Object?>(BuildContext context, AstromicFlexSheetTemplate<T> template) async => await flex<T>(
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<T?> form<T extends Object?>(
BuildContext context, {
//
Widget Function(AstromicFormController)? headSectionBuilder,
required Widget Function(AstromicFormController) contentSectionBuilder,
Widget Function(AstromicFormController)? footerSectionBuilder,
//
AstromicSheetConfiguration? configuration,
AstromicSheetStyle? style,
}) async {
if (_vsyncState == null) {
_initializevSync(context);
}
AstromicSheetConfiguration sheetConfigs = configuration ?? const AstromicSheetConfiguration();
AstromicSheetStyle sheetStyle = style ?? const AstromicSheetStyle();
return await BasicSheet.show<T>(
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: BaseSheetWidget<T?>(
sheetType: SheetType.form,
//
sheetConfiguration: sheetConfigs,
sheetStyle: sheetStyle,
//
headSectionFormBuilder: headSectionBuilder,
contentSectionFormBuilder: contentSectionBuilder,
footerSectionFormBuilder: footerSectionBuilder,
),
);
}
/// Show Form sheet using a pre-set FormSheetTemplate.
static Future<T?> formTemplate<T extends Object?>(BuildContext c, AstromicFormSheetTemplate<T> template) async => await form<T>(
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<T?> scroller<T extends Object?>(
BuildContext context, {
//
Widget Function(ScrollController)? headSectionBuilder,
required Widget Function(ScrollController, ScrollPhysics) contentSectionBuilder,
Widget Function(ScrollController)? footerSectionBuilder,
//
AstromicSheetConfiguration? configuration,
AstromicSheetStyle? style,
}) async {
if (_vsyncState == null) {
_initializevSync(context);
}
AstromicSheetConfiguration sheetConfigs = configuration ?? const AstromicSheetConfiguration();
AstromicSheetStyle sheetStyle = style ?? const AstromicSheetStyle();
return await ScrollerSheet.show<T>(
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)
? <double?>[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()
: <double>[
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 BaseSheetWidget<T?>(
sheetType: SheetType.scroller,
sheetConfiguration: sheetConfigs,
sheetStyle: sheetStyle,
headSectionScrollerBuilder: headSectionBuilder,
contentSectionScrollBuilder: contentSectionBuilder,
footerSectionScrollerBuilder: footerSectionBuilder,
scrollController: scrollController,
scrollPhysics: scrollPhysics,
);
},
);
}
/// Show Scroller sheet using a pre-set ScrollerSheetTemplate.
static Future<T?> scrollerTemplate<T extends Object?>(BuildContext context, AstromicScrollerSheetTemplate<T> template) async => await scroller<T>(
context,
headSectionBuilder: template.headSectionBuilder,
contentSectionBuilder: template.contentSectionBuilder,
footerSectionBuilder: template.footerSectionBuilder,
//
configuration: template.configuration,
style: template.style,
);
}