Skip to content

Commit

Permalink
Merge pull request #457 from pangeachat/blue7/08
Browse files Browse the repository at this point in the history
Added null checks, error handling, and used non-null version of l10n
  • Loading branch information
ggurdin authored Jul 16, 2024
2 parents 13f980d + 057f07d commit 8d8e7ea
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 85 deletions.
7 changes: 6 additions & 1 deletion lib/pages/chat/input_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,12 @@ class InputBar extends StatelessWidget {
textInputAction: textInputAction,
autofocus: autofocus!,
inputFormatters: [
LengthLimitingTextInputFormatter((maxPDUSize / 3).floor()),
//#Pangea
//LengthLimitingTextInputFormatter((maxPDUSize / 3).floor()),
//setting max character count to 1000
//after max, nothing else can be typed
LengthLimitingTextInputFormatter(1000),
//Pangea#
],
onSubmitted: (text) {
// fix for library for now
Expand Down
7 changes: 2 additions & 5 deletions lib/pangea/controllers/my_analytics_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,8 @@ class MyAnalyticsController {
/// top level analytics sending function. Gather recent messages and activity records,
/// convert them into the correct formats, and send them to the analytics room
Future<void> _updateAnalytics() async {
// if missing important info, don't send analytics
if (userL2 == null || _client.userID == null) {
debugger(when: kDebugMode);
return;
}
// if missing important info, don't send analytics. Could happen if user just signed up.
if (userL2 == null || _client.userID == null) return;

// analytics room for the user and current target language
final Room analyticsRoom = await _client.getMyAnalyticsRoom(userL2!);
Expand Down
51 changes: 18 additions & 33 deletions lib/pangea/pages/p_user_age/p_user_age_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,25 @@ class PUserAgeView extends StatelessWidget {
),
body: ListView(
children: [
Container(
margin: const EdgeInsets.only(top: 10),
padding: const EdgeInsets.all(15),
child: Text(
L10n.of(context)!.yourBirthdayPlease,
textAlign: TextAlign.justify,
style: const TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(
height: 10,
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Theme.of(context)
.colorScheme
.onSecondaryContainer
.withAlpha(50),
color: Theme.of(context).colorScheme.onSecondaryContainer.withAlpha(50),
),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(15),
child: Text(
L10n.of(context)!.yourBirthdayPlease,
textAlign: TextAlign.justify,
style: const TextStyle(
color: Colors.black,
fontSize: 14,
fontWeight: FontWeight.normal,
),
),
),
ListTile(
title: Text(
L10n.of(context)!.certifyAge(13),
Expand Down Expand Up @@ -70,23 +63,16 @@ class PUserAgeView extends StatelessWidget {
],
),
),
const SizedBox(
height: 10,
),
if (controller.error != null)
Padding(
padding: const EdgeInsets.all(12),
child: Text(
controller.error!,
style: const TextStyle(color: Colors.white),
),
),
const SizedBox(height: 20),
Hero(
tag: 'loginButton',
child: Padding(
padding: const EdgeInsets.all(12),
padding: const EdgeInsets.symmetric(horizontal: 12),
child: ElevatedButton(
onPressed: controller.createUserInPangea,
style: ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(50),
),
child: controller.loading
? const LinearProgressIndicator()
: Text(L10n.of(context)!.getStarted),
Expand All @@ -95,7 +81,6 @@ class PUserAgeView extends StatelessWidget {
),
],
),
// ),
);
}
}
2 changes: 2 additions & 0 deletions lib/pangea/widgets/chat/message_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ class MessageToolbarState extends State<MessageToolbar> {
late StreamSubscription<MessageMode> toolbarModeStream;

void updateMode(MessageMode newMode) {
//Early exit from the function if the widget has been unmounted to prevent updates on an inactive widget.
if (!mounted) return;
if (updatingMode) return;
debugPrint("updating toolbar mode");
final bool subscribed =
Expand Down
102 changes: 56 additions & 46 deletions lib/utils/error_reporter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,67 @@ class ErrorReporter {
void onErrorCallback(Object error, [StackTrace? stackTrace]) async {
Logs().e(message ?? 'Error caught', error, stackTrace);
// #Pangea
// Attempt to retrieve the L10n instance using the current context
final L10n? l10n = L10n.of(context);

// Check if the L10n instance is null
if (l10n == null) {
// Log an error message saying that the localization object is null
Logs().e('Localization object is null, cannot show error message.');
// Exits early to prevent further execution
return;
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
L10n.of(context)!.oopsSomethingWentWrong,
l10n.oopsSomethingWentWrong, // Use the non-null L10n instance to get the error message
),
),
);
// final text = '$error\n${stackTrace ?? ''}';
// await showAdaptiveDialog(
// context: context,
// builder: (context) => AlertDialog.adaptive(
// title: Text(L10n.of(context)!.reportErrorDescription),
// content: SizedBox(
// height: 256,
// width: 256,
// child: SingleChildScrollView(
// child: HighlightView(
// text,
// language: 'sh',
// theme: shadesOfPurpleTheme,
// ),
// ),
// ),
// actions: [
// TextButton(
// onPressed: () => Navigator.of(context).pop(),
// child: Text(L10n.of(context)!.close),
// ),
// TextButton(
// onPressed: () => Clipboard.setData(
// ClipboardData(text: text),
// ),
// child: Text(L10n.of(context)!.copy),
// ),
// TextButton(
// onPressed: () => launchUrl(
// AppConfig.newIssueUrl.resolveUri(
// Uri(
// queryParameters: {
// 'template': 'bug_report.yaml',
// 'title': '[BUG]: ${message ?? error.toString()}',
// },
// ),
// ),
// mode: LaunchMode.externalApplication,
// ),
// child: Text(L10n.of(context)!.report),
// ),
// ],
// ),
// );
// Pangea#
}
// final text = '$error\n${stackTrace ?? ''}';
// await showAdaptiveDialog(
// context: context,
// builder: (context) => AlertDialog.adaptive(
// title: Text(L10n.of(context)!.reportErrorDescription),
// content: SizedBox(
// height: 256,
// width: 256,
// child: SingleChildScrollView(
// child: HighlightView(
// text,
// language: 'sh',
// theme: shadesOfPurpleTheme,
// ),
// ),
// ),
// actions: [
// TextButton(
// onPressed: () => Navigator.of(context).pop(),
// child: Text(L10n.of(context)!.close),
// ),
// TextButton(
// onPressed: () => Clipboard.setData(
// ClipboardData(text: text),
// ),
// child: Text(L10n.of(context)!.copy),
// ),
// TextButton(
// onPressed: () => launchUrl(
// AppConfig.newIssueUrl.resolveUri(
// Uri(
// queryParameters: {
// 'template': 'bug_report.yaml',
// 'title': '[BUG]: ${message ?? error.toString()}',
// },
// ),
// ),
// mode: LaunchMode.externalApplication,
// ),
// child: Text(L10n.of(context)!.report),
// ),
// ],
// ),
// );
// Pangea#
}

0 comments on commit 8d8e7ea

Please sign in to comment.