Files
lunasea/lib/core/ui/message.dart
Jagandeep Brar a1d68cd234 [share_plus] iOS 12 and lower crashes at launch due to missing LinkPresentation.framework (#442)
* chore(packages): Added pedantic package to enforce linting and styling
* feat(lunasea): Enforce effective dart styling
* Comment and format colours class
* Localize additional classes in Dashboard, cleanup additional code
* chore(lunasea): Major refactor by running dartfmt on the entire codebase, added widget return for page routers
* Additional work on conforming to effective dart style
* fix(share_plus): Roll back share_plus package to 2.0.0 to support iOS 12 or lower
* chore(lunasea): Fix remaining enabled analysis warnings
2021-04-24 04:26:39 -05:00

141 lines
3.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:lunasea/core.dart';
class LunaMessage extends StatelessWidget {
final String text;
final Color textColor;
final String buttonText;
final Function onTap;
final bool useSafeArea;
LunaMessage({
Key key,
@required this.text,
this.textColor = Colors.white,
this.buttonText,
this.onTap,
this.useSafeArea = true,
}) {
assert(text != null);
if (buttonText != null)
assert(onTap != null, 'onTap must be defined if buttonText is defined');
}
/// Return a message that is meant to be shown within a [ListView].
factory LunaMessage.inList({
Key key,
@required String text,
bool useSafeArea = false,
}) {
assert(text != null);
return LunaMessage(
key: key,
text: text,
useSafeArea: useSafeArea,
);
}
/// Returns a centered message with a simple message, with a button to pop out of the route.
factory LunaMessage.goBack({
Key key,
@required String text,
@required BuildContext context,
bool useSafeArea = true,
}) {
assert(context != null);
return LunaMessage(
key: key,
text: text,
buttonText: 'lunasea.GoBack'.tr(),
onTap: () => Navigator.of(context).pop(),
useSafeArea: useSafeArea,
);
}
/// Return a pre-structured "An Error Has Occurred" message, with a "Try Again" button shown.
factory LunaMessage.error({
Key key,
@required Function onTap,
bool useSafeArea = true,
}) {
assert(onTap != null);
return LunaMessage(
key: key,
text: 'lunasea.AnErrorHasOccurred'.tr(),
buttonText: 'lunasea.TryAgain'.tr(),
onTap: onTap,
useSafeArea: useSafeArea,
);
}
/// Return a pre-structured "<module> Is Not Enabled" message, with a "Return to Dashboard" button shown.
factory LunaMessage.moduleNotEnabled({
Key key,
@required BuildContext context,
@required String module,
bool useSafeArea = true,
}) {
assert(module != null);
assert(context != null);
return LunaMessage(
key: key,
text: 'lunasea.ModuleIsNotEnabled'.tr(args: [module]),
buttonText: 'lunasea.ReturnToDashboard'.tr(),
onTap: () async => LunaModule.DASHBOARD.launch(),
useSafeArea: useSafeArea,
);
}
@override
Widget build(BuildContext context) {
return SafeArea(
top: useSafeArea,
left: useSafeArea,
right: useSafeArea,
bottom: useSafeArea,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Card(
margin: LunaUI.MARGIN_CARD,
elevation: LunaUI.ELEVATION,
shape: LunaUI.shapeBorder,
child: Row(
children: [
Expanded(
child: Container(
child: Text(
text,
textAlign: TextAlign.center,
style: TextStyle(
color: textColor,
fontWeight: LunaUI.FONT_WEIGHT_BOLD,
fontSize: LunaUI.FONT_SIZE_MESSAGES,
),
),
margin:
EdgeInsets.symmetric(vertical: 24.0, horizontal: 12.0),
),
),
],
),
),
if (buttonText != null)
LunaButtonContainer(
children: [
LunaButton.text(
text: buttonText,
icon: null,
onTap: onTap,
color: Colors.white,
backgroundColor: LunaColours.accent,
),
],
),
],
),
);
}
}