main
 1import 'package:flutter/material.dart';
 2
 3/// Base for fullscreen dialoges that allow value input.
 4class FullscreenDialoge extends StatelessWidget {
 5  /// Create a dialoge that has a icon- and a textbutton in the app bar.
 6  const FullscreenDialoge({super.key,
 7    this.body,
 8    required this.actionButtonText,
 9    this.onActionButtonPressed,
10    required this.bottomAppBar,
11    this.closeIcon = Icons.close,
12    this.actions = const <Widget>[],
13  });
14
15  /// The primary content of the dialoge.
16  final Widget? body;
17
18  /// Icon of button leading in the app bar.
19  ///
20  /// When pressing on the icon button the context gets popped.
21  ///
22  /// Setting this icon to null will hide the button entirely.
23  final IconData? closeIcon;
24
25  /// Primary content of the text button at the right end of the app bar.
26  ///
27  /// Usually `localizations.btnSave`
28  ///
29  /// Setting the text to null will hide the button entirely.
30  final String? actionButtonText;
31
32  /// Action on press of the button.
33  ///
34  /// Setting this to null will disable the button. To hide it refer to
35  /// [actionButtonText].
36  final void Function()? onActionButtonPressed;
37
38  /// Whether to move the app bar to the bottom of the screen.
39  ///
40  /// Setting this to false will let the app bar stay at the top.
41  final bool bottomAppBar;
42
43  /// Secondary actions to display on the app bar.
44  ///
45  /// Positioned somewhere between close and primary action button.
46  ///
47  /// Recommended to be used with [CheckboxMenuButton].
48  final List<Widget> actions;
49
50  @override
51  Widget build(BuildContext context) => Dialog.fullscreen(
52    child: Scaffold(
53      body: _buildBody(),
54      appBar: bottomAppBar ? null : _buildAppBar(context),
55      bottomNavigationBar: bottomAppBar ? BottomAppBar(
56        color: Colors.transparent,
57        shadowColor: Colors.transparent,
58        surfaceTintColor: Colors.transparent,
59        child: _buildAppBar(context),
60      ) : null,
61    ),
62  );
63
64  PreferredSizeWidget _buildAppBar(BuildContext context) => AppBar(
65    forceMaterialTransparency: true,
66    leading: (closeIcon == null) ? null : IconButton(
67      onPressed: () => Navigator.pop(context, null),
68      icon: Icon(closeIcon),
69    ),
70    title: Row(
71      mainAxisAlignment: MainAxisAlignment.center,
72      children: actions,
73    ),
74    actions: [
75      if (actionButtonText != null)
76        TextButton(
77          onPressed: onActionButtonPressed,
78          child:  Text(actionButtonText!),
79        ),
80    ],
81  );
82
83  Widget? _buildBody() {
84    if (body == null) return null;
85    if (!bottomAppBar) return body;
86    return Padding(
87      padding: const EdgeInsets.only(top: 4.0),
88      child: body,
89    );
90  }
91
92}