showNiceDrawer<T> function

Future<T?> showNiceDrawer<T>({
  1. required BuildContext context,
  2. required Widget child,
  3. String? title,
  4. double width = 360,
  5. NiceDrawerPosition position = NiceDrawerPosition.right,
})

Side drawer panel.

Implementation

Future<T?> showNiceDrawer<T>({
  required BuildContext context,
  required Widget child,
  String? title,
  double width = 360,
  NiceDrawerPosition position = NiceDrawerPosition.right,
}) {
  return showGeneralDialog<T>(
    context: context,
    barrierDismissible: true,
    barrierLabel: 'NiceDrawer',
    barrierColor: Colors.black54,
    transitionDuration: const Duration(milliseconds: 300),
    transitionBuilder: (ctx, anim, secondAnim, dialogChild) {
      final offset = position == NiceDrawerPosition.right
          ? Offset(1 - anim.value, 0)
          : Offset(anim.value - 1, 0);
      return FractionalTranslation(
        translation: offset,
        child: dialogChild,
      );
    },
    pageBuilder: (ctx, _, __) {
      final theme = NiceTheme.of(ctx);
      return Align(
        alignment: position == NiceDrawerPosition.right
            ? Alignment.centerRight
            : Alignment.centerLeft,
        child: Material(
          elevation: 16,
          child: SizedBox(
            width: width,
            height: double.infinity,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: [
                if (title != null)
                  Container(
                    padding: EdgeInsets.all(theme.spacing * 2),
                    decoration: BoxDecoration(
                      border: Border(
                        bottom: BorderSide(color: theme.colors.border),
                      ),
                    ),
                    child: Row(
                      children: [
                        Expanded(
                          child:
                              Text(title, style: theme.typography.label),
                        ),
                        IconButton(
                          onPressed: () => Navigator.of(ctx).pop(),
                          icon: const Icon(Icons.close, size: 20),
                        ),
                      ],
                    ),
                  ),
                Expanded(child: child),
              ],
            ),
          ),
        ),
      );
    },
  );
}