[FEAT] Added snackbar herlper and dialog helper.
This commit is contained in:
59
lib/src/dialog/dialog_helper.astromic.dart
Normal file
59
lib/src/dialog/dialog_helper.astromic.dart
Normal file
@@ -0,0 +1,59 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import './src/models/models.exports.dart';
|
||||
|
||||
class AstromicDialogHelper {
|
||||
/// Show a dialog.
|
||||
static Future<T?> show<T>(
|
||||
BuildContext context, {
|
||||
required Widget contentSection,
|
||||
Widget? stackedCloseWidget,
|
||||
AstromicDialogConfiguration configuration = const AstromicDialogConfiguration(),
|
||||
AstromicDialogStyle style = const AstromicDialogStyle(),
|
||||
void Function(T?)? onClose,
|
||||
}) async {
|
||||
//
|
||||
return await showDialog<T>(
|
||||
context: context,
|
||||
useSafeArea: configuration.safeAreaAware,
|
||||
builder: (BuildContext _) {
|
||||
return Container(
|
||||
margin: style.placement,
|
||||
//
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
Stack(
|
||||
children: [
|
||||
Container(
|
||||
width: (style.width ?? 0) - ((style.placement?.start ?? 0) + (style.placement?.start ?? 0)),
|
||||
//
|
||||
padding: style.contentPadding,
|
||||
decoration: BoxDecoration(
|
||||
color: style.backgroundColor,
|
||||
borderRadius: style.radius,
|
||||
),
|
||||
child: contentSection,
|
||||
),
|
||||
if (stackedCloseWidget != null)
|
||||
Positioned.directional(
|
||||
textDirection: style.textDirection,
|
||||
start: style.closeWidgetPlacement?.start,
|
||||
end: style.closeWidgetPlacement?.end,
|
||||
top: style.closeWidgetPlacement?.top,
|
||||
//
|
||||
child: stackedCloseWidget,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
//
|
||||
}
|
||||
}
|
||||
20
lib/src/dialog/src/models/configuration.model.dart
Normal file
20
lib/src/dialog/src/models/configuration.model.dart
Normal file
@@ -0,0 +1,20 @@
|
||||
class AstromicDialogConfiguration {
|
||||
//
|
||||
final bool isCentered;
|
||||
final bool safeAreaAware;
|
||||
const AstromicDialogConfiguration({
|
||||
this.isCentered = true,
|
||||
this.safeAreaAware = true,
|
||||
});
|
||||
//
|
||||
|
||||
AstromicDialogConfiguration copyWith({
|
||||
bool? isCentered,
|
||||
bool? safeAreaAware,
|
||||
}) {
|
||||
return AstromicDialogConfiguration(
|
||||
isCentered: isCentered ?? this.isCentered,
|
||||
safeAreaAware: safeAreaAware ?? this.safeAreaAware,
|
||||
);
|
||||
}
|
||||
}
|
||||
2
lib/src/dialog/src/models/models.exports.dart
Normal file
2
lib/src/dialog/src/models/models.exports.dart
Normal file
@@ -0,0 +1,2 @@
|
||||
export './style.model.dart';
|
||||
export './configuration.model.dart';
|
||||
25
lib/src/dialog/src/models/style.model.dart
Normal file
25
lib/src/dialog/src/models/style.model.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class AstromicDialogStyle {
|
||||
//
|
||||
final Color? backgroundColor;
|
||||
final BorderRadius? radius;
|
||||
final EdgeInsets? contentPadding;
|
||||
final double? width;
|
||||
final double? height;
|
||||
final TextDirection textDirection;
|
||||
final EdgeInsetsDirectional? placement;
|
||||
final EdgeInsetsDirectional? closeWidgetPlacement;
|
||||
|
||||
const AstromicDialogStyle({
|
||||
this.backgroundColor = Colors.white,
|
||||
this.radius,
|
||||
this.contentPadding = const EdgeInsets.all(12.0),
|
||||
this.width = 300,
|
||||
this.height,
|
||||
this.textDirection = TextDirection.ltr,
|
||||
this.placement,
|
||||
this.closeWidgetPlacement,
|
||||
});
|
||||
//
|
||||
}
|
||||
1
lib/src/dialog/src/src.exports.dart
Normal file
1
lib/src/dialog/src/src.exports.dart
Normal file
@@ -0,0 +1 @@
|
||||
export './models/models.exports.dart';
|
||||
41
lib/src/snackbar/snackbar_helper.astromic.dart
Normal file
41
lib/src/snackbar/snackbar_helper.astromic.dart
Normal file
@@ -0,0 +1,41 @@
|
||||
import 'package:flutter_snackbar_plus/flutter_snackbar_plus.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class AstromicSnackbarHelper {
|
||||
static setDefault({
|
||||
// Style
|
||||
FlutterSnackBarStyle? style,
|
||||
// Configuration
|
||||
FlutterSnackBarConfiguration? configuration,
|
||||
}) =>
|
||||
FlutterSnackBar().initialize(configuration: configuration, style: style);
|
||||
|
||||
static showTemplated(
|
||||
BuildContext context, {
|
||||
// Leading
|
||||
Widget? leading,
|
||||
// Main Content
|
||||
required String title,
|
||||
String? message,
|
||||
Widget? content,
|
||||
// Trailing
|
||||
Widget? trailing,
|
||||
// Style
|
||||
FlutterSnackBarStyle? style,
|
||||
// Configuration
|
||||
FlutterSnackBarConfiguration? configuration,
|
||||
}) =>
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
FlutterSnackBar.showTemplated(context, title: title, leading: leading, message: message, content: content, trailing: trailing, style: style, configuration: configuration);
|
||||
});
|
||||
|
||||
static showCustom(
|
||||
BuildContext context, {
|
||||
required Widget child,
|
||||
// Style
|
||||
FlutterSnackBarStyle? style = const FlutterSnackBarStyle(),
|
||||
// Configuration
|
||||
FlutterSnackBarConfiguration? configuration = const FlutterSnackBarConfiguration(),
|
||||
}) =>
|
||||
FlutterSnackBar.showCustom(context, child: child, configuration: configuration, style: style);
|
||||
}
|
||||
Reference in New Issue
Block a user