Skip to content

Commit

Permalink
chore(sentry): improve integration
Browse files Browse the repository at this point in the history
  • Loading branch information
vareversat committed Jun 26, 2023
1 parent e7a0013 commit 977ea95
Show file tree
Hide file tree
Showing 15 changed files with 120 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flutter.build.action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
run: flutter build appbundle --build-number="$BUILD_NUMBER" --dart-define SENTRY_DSN="$SENTRY_DSN" --dart-define ENV="$ENV"
env:
BUILD_NUMBER: ${{ env.BUILD_NUMBER }}
PASSPHRASE: ${{ secrets.SENTRY_DSN }}
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
ENV: ${{ inputs.env }}
- name: 'Save AAB'
if: ${{ inputs.android_output == 'aab' }}
Expand Down
11 changes: 9 additions & 2 deletions lib/chabo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,15 @@ class Chabo extends StatelessWidget {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: state.themeData,
home: const ForecastScreen(),
navigatorObservers: [SentryNavigatorObserver()],
navigatorObservers: [
SentryNavigatorObserver(
setRouteNameAsTransaction: true,
),
],
initialRoute: ForecastScreen.routeName,
routes: {
ForecastScreen.routeName: (context) => const ForecastScreen(),
},
localizationsDelegates: const [
AppLocalizations.delegate,
GlobalMaterialLocalizations.delegate,
Expand Down
21 changes: 21 additions & 0 deletions lib/custom_widget_state.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
import 'package:chabo/bloc/theme/theme_bloc.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

class CustomWidgetState<T extends StatefulWidget> extends State<T>
with WidgetsBindingObserver {
final String screenName;

CustomWidgetState({required this.screenName});

@override
void initState() {
Sentry.addBreadcrumb(
Breadcrumb(
message: 'Open $screenName',
level: SentryLevel.info,
category: 'screen.open',
type: 'Screen',
),
);
WidgetsBinding.instance.addObserver(this);
super.initState();
}

@override
void dispose() {
Sentry.addBreadcrumb(
Breadcrumb(
message: 'Close $screenName',
level: SentryLevel.info,
category: 'screen.close',
type: 'Screen',
),
);
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
Expand Down
6 changes: 4 additions & 2 deletions lib/dialogs/chabo_about_dialog/page_links_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ class _PageLinksWidget extends StatelessWidget {
colorScheme.onSecondaryContainer,
),
),
onPressed: () => Navigator.push(
context,
onPressed: () => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const ChangeLogScreen(),
settings: const RouteSettings(
name: ChangeLogScreen.routeName,
),
),
),
child: Row(
Expand Down
12 changes: 12 additions & 0 deletions lib/models/abstract_forecast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ abstract class AbstractForecast extends Equatable {
);
}

Map<String, dynamic> toJson() {
return {
'total_closing': totalClosing,
'is_during_dwo_days': isDuringTwoDays,
'closing_reason': closingReason.name,
'closed_duration': closedDuration.toString(),
'closing_type': closingType.name,
'circulation_closing_date': circulationClosingDate,
'circulation_re_opening_date': circulationReOpeningDate,
};
}

@override
List<Object?> get props => [
totalClosing,
Expand Down
7 changes: 7 additions & 0 deletions lib/models/boat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ class Boat extends Equatable {
);
}

Map<String, dynamic> toJson() {
return {
'name': name,
'is_living': isLeaving,
};
}

@override
List<Object?> get props => [name, isLeaving];
}
10 changes: 10 additions & 0 deletions lib/models/boat_forecast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,14 @@ class BoatForecast extends AbstractForecast {
? AppLocalizations.of(context)!.wineFestivalSailBoats
: boats.getNames(context);
}

@override
Map<String, dynamic> toJson() {
var json = super.toJson();
json.addAll({
'boats': boats.map((e) => e.toJson()).toList(),
});

return json;
}
}
4 changes: 4 additions & 0 deletions lib/screens/changelog_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_markdown/flutter_markdown.dart';

class ChangeLogScreen extends StatefulWidget {
static const routeName = '/changelog-screen';

const ChangeLogScreen({Key? key}) : super(key: key);

@override
Expand All @@ -16,6 +18,8 @@ class ChangeLogScreen extends StatefulWidget {
}

class _ChangeLogScreenState extends CustomWidgetState<ChangeLogScreen> {
_ChangeLogScreenState() : super(screenName: 'changelog-screen');

String _getChangelogPath(BuildContext context) {
return Const.changelogPath.replaceAll(
Const.changelogPlaceholder,
Expand Down
2 changes: 2 additions & 0 deletions lib/screens/error_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ErrorScreen extends StatefulWidget {
}

class _ErrorScreenState extends CustomWidgetState<ErrorScreen> {
_ErrorScreenState() : super(screenName: 'error-screen');

@override
Widget build(BuildContext context) {
return Scaffold(
Expand Down
4 changes: 4 additions & 0 deletions lib/screens/forecast_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class ForecastScreen extends StatefulWidget {
static const routeName = '/forecast-screen';

const ForecastScreen({Key? key}) : super(key: key);

@override
Expand All @@ -27,6 +29,8 @@ class ForecastScreen extends StatefulWidget {
}

class _ForecastScreenState extends CustomWidgetState<ForecastScreen> {
_ForecastScreenState() : super(screenName: 'forecast-screen');

@override
Widget build(BuildContext context) {
return BlocBuilder<FloatingActionsCubit, FloatingActionsState>(
Expand Down
16 changes: 15 additions & 1 deletion lib/screens/notification_screen/custom_list_tile_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,21 @@ class _CustomListTileWidget extends StatelessWidget {
Switch.adaptive(
thumbIcon: thumbIcon,
value: enabled,
onChanged: onChanged,
onChanged: (value) {
Sentry.addBreadcrumb(
Breadcrumb(
message: 'Change "$title" state',
level: SentryLevel.info,
category: 'notification.change-state',
type: 'Notification',
data: {
'old-state': !value,
'new-state': value,
},
),
);
onChanged(value);
},
),
],
),
Expand Down
18 changes: 10 additions & 8 deletions lib/screens/notification_screen/notification_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,28 @@ import 'package:chabo/widgets/time_slot_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

part 'custom_list_tile_widget.dart';

part 'favorite_slots_day_picker_dialog.dart';

part 'favorite_slots_widget.dart';

class NotificationScreen extends StatefulWidget {
final bool highlightTimeSlots;
final bool? highlightTimeSlots;
static const routeName = '/notification-screen';

const NotificationScreen({
Key? key,
required this.highlightTimeSlots,
this.highlightTimeSlots,
}) : super(key: key);

@override
State<NotificationScreen> createState() => _NotificationScreenState();
}

class _NotificationScreenState extends CustomWidgetState<NotificationScreen> {
_NotificationScreenState() : super(screenName: 'notification-screen');

@override
Widget build(BuildContext context) {
return BlocBuilder<FloatingActionsCubit, FloatingActionsState>(
Expand Down Expand Up @@ -78,7 +80,7 @@ class _NotificationScreenState extends CustomWidgetState<NotificationScreen> {
return Column(
children: [
_FavoriteSlotsWidget(
highlightTimeSlots: widget.highlightTimeSlots,
highlightTimeSlots: widget.highlightTimeSlots ?? false,
timeSlotsEnabledForNotifications:
notificationState.timeSlotsEnabledForNotifications,
),
Expand Down Expand Up @@ -147,7 +149,7 @@ class _NotificationScreenState extends CustomWidgetState<NotificationScreen> {
);
},
).then(
(value) => {
(value) => {
if (value != null)
{
BlocProvider.of<NotificationBloc>(context).add(
Expand Down Expand Up @@ -198,7 +200,7 @@ class _NotificationScreenState extends CustomWidgetState<NotificationScreen> {
);
},
).then(
(value) => {
(value) => {
if (value != null)
{
BlocProvider.of<NotificationBloc>(context).add(
Expand Down Expand Up @@ -248,7 +250,7 @@ class _NotificationScreenState extends CustomWidgetState<NotificationScreen> {
);
},
).then(
(value) => {
(value) => {
if (value != null)
{
BlocProvider.of<NotificationBloc>(context).add(
Expand Down
16 changes: 16 additions & 0 deletions lib/widgets/bottom_sheets/forecast_information_bottom_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:chabo/models/abstract_forecast.dart';
import 'package:chabo/screens/notification_screen/notification_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

class ForecastInformationBottomSheet extends StatefulWidget {
final AbstractForecast forecast;
Expand Down Expand Up @@ -54,6 +55,18 @@ class _ForecastInformationBottomSheetState
Widget build(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;

print(widget.forecast.toJson());

Sentry.addBreadcrumb(
Breadcrumb(
message: 'Open ForecastInformationBottomSheet',
level: SentryLevel.info,
category: 'screen.open',
type: 'Screen',
data: widget.forecast.toJson(),
),
);

return Column(
mainAxisSize: MainAxisSize.min,
children: [
Expand Down Expand Up @@ -151,6 +164,9 @@ class _ForecastInformationBottomSheetState
builder: (context) => const NotificationScreen(
highlightTimeSlots: true,
),
settings: const RouteSettings(
name: NotificationScreen.routeName,
),
),
),
},
Expand Down
5 changes: 3 additions & 2 deletions lib/widgets/floating_actions/floating_actions_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,9 @@ class _FloatingActionsWidgetState extends State<FloatingActionsWidget>
Navigator.of(context).push(
BottomToTopPageRoute(
builder: (context) =>
const NotificationScreen(
highlightTimeSlots: false,
const NotificationScreen(),
settings: const RouteSettings(
name: NotificationScreen.routeName,
),
),
);
Expand Down
2 changes: 2 additions & 0 deletions lib/widgets/forecast/status_widget/status_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class StatusWidget extends StatefulWidget {
}

class StatusWidgetState extends CustomWidgetState<StatusWidget> {
StatusWidgetState() : super(screenName: 'status-widget');

@override
void initState() {
SchedulerBinding.instance.addPostFrameCallback(
Expand Down

0 comments on commit 977ea95

Please sign in to comment.