Skip to content

Commit 5bd9613

Browse files
authored
Web Min Version Test (#1537)
1 parent 84a3369 commit 5bd9613

File tree

7 files changed

+101
-26
lines changed

7 files changed

+101
-26
lines changed

.github/workflows/min_version_test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,20 @@ jobs:
5656
cd min_version_test
5757
flutter pub get
5858
flutter build ios --no-codesign
59+
60+
build-web:
61+
runs-on: ubuntu-latest
62+
timeout-minutes: 30
63+
64+
steps:
65+
- uses: actions/checkout@v3
66+
67+
- uses: subosito/flutter-action@48cafc24713cca54bbe03cdc3a423187d413aafa # [email protected]
68+
with:
69+
flutter-version: '3.0.0'
70+
71+
- name: Build web
72+
run: |
73+
cd min_version_test
74+
flutter pub get
75+
flutter build web --source-maps

min_version_test/lib/main.dart

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
import 'package:flutter/material.dart';
22

3-
import 'dart:io' if (dart.library.html) 'dart:html';
4-
5-
import 'package:logging/logging.dart';
6-
import 'package:dio/dio.dart';
7-
3+
import 'package:min_version_test/transaction/transaction_locator.dart'
4+
if (dart.library.html) 'package:min_version_test/transaction/file_transaction.dart'
5+
if (dart.library.io) 'package:min_version_test/transaction/web_transaction.dart';
86
import 'package:sentry_flutter/sentry_flutter.dart';
9-
import 'package:sentry_dio/sentry_dio.dart';
107
import 'package:sentry_logging/sentry_logging.dart';
118

129
// ATTENTION: Change the DSN below with your own to see the events in Sentry. Get one at sentry.io
@@ -94,33 +91,15 @@ class _MyHomePageState extends State<MyHomePage> {
9491

9592
Future<void> _incrementCounter() async {
9693
setState(() async {
97-
final transaction = Sentry.startTransaction(
98-
'incrementCounter',
99-
'task',
100-
bindToScope: true,
101-
);
94+
final transactionTest = getTransaction();
95+
await transactionTest.start();
10296

10397
// This call to setState tells the Flutter framework that something has
10498
// changed in this State, which causes it to rerun the build method below
10599
// so that the display can reflect the updated values. If we changed
106100
// _counter without calling setState(), then the build method would not be
107101
// called again, and so nothing would appear to happen.
108102
_counter++;
109-
110-
final dio = Dio();
111-
dio.addSentry();
112-
final log = Logger('_MyHomePageState');
113-
114-
try {
115-
final file = File('response.txt');
116-
final response = await dio.get<String>('https://flutter.dev/');
117-
await file.writeAsString(response.data ?? 'no response');
118-
119-
await transaction.finish(status: SpanStatus.ok());
120-
} catch (exception, stackTrace) {
121-
log.info(exception.toString(), exception, stackTrace);
122-
await transaction.finish(status: SpanStatus.internalError());
123-
}
124103
});
125104
}
126105

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import 'package:min_version_test/transaction/transaction.dart';
2+
import 'dart:io';
3+
4+
import 'package:logging/logging.dart';
5+
import 'package:dio/dio.dart';
6+
7+
import 'package:sentry_flutter/sentry_flutter.dart';
8+
import 'package:sentry_dio/sentry_dio.dart';
9+
10+
class FileTransaction implements Transaction {
11+
@override
12+
Future<void> start() async {
13+
final transaction = Sentry.startTransaction(
14+
'incrementCounter',
15+
'task',
16+
bindToScope: true,
17+
);
18+
19+
final dio = Dio();
20+
dio.addSentry();
21+
final log = Logger('_MyHomePageState');
22+
23+
try {
24+
final file = File('response.txt');
25+
final response = await dio.get<String>('https://flutter.dev/');
26+
await file.writeAsString(response.data ?? 'no response');
27+
28+
await transaction.finish(status: SpanStatus.ok());
29+
} catch (exception, stackTrace) {
30+
log.info(exception.toString(), exception, stackTrace);
31+
await transaction.finish(status: SpanStatus.internalError());
32+
}
33+
}
34+
}
35+
36+
Transaction getTransaction() => FileTransaction();
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class Transaction {
2+
Future<void> start() async {
3+
// Do nothing...
4+
}
5+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import 'package:min_version_test/transaction/transaction.dart';
2+
3+
Transaction getTransaction() =>
4+
throw UnsupportedError('Cannot create sample transaction.');
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import 'package:min_version_test/transaction/transaction.dart';
2+
3+
import 'package:logging/logging.dart';
4+
import 'package:dio/dio.dart';
5+
6+
import 'package:sentry_flutter/sentry_flutter.dart';
7+
import 'package:sentry_dio/sentry_dio.dart';
8+
9+
class WebTransaction implements Transaction {
10+
@override
11+
Future<void> start() async {
12+
final transaction = Sentry.startTransaction(
13+
'incrementCounter',
14+
'task',
15+
bindToScope: true,
16+
);
17+
18+
final dio = Dio();
19+
dio.addSentry();
20+
final log = Logger('_MyHomePageState');
21+
22+
try {
23+
final response = await dio.get<String>('https://flutter.dev/');
24+
print(response);
25+
26+
await transaction.finish(status: SpanStatus.ok());
27+
} catch (exception, stackTrace) {
28+
log.info(exception.toString(), exception, stackTrace);
29+
await transaction.finish(status: SpanStatus.internalError());
30+
}
31+
}
32+
}
33+
34+
Transaction getTransaction() => WebTransaction();

min_version_test/web/index.html

Whitespace-only changes.

0 commit comments

Comments
 (0)