Skip to content

Commit 3c44b7b

Browse files
committed
build: remove retrofit and retrofit_generator
1 parent c38aeaf commit 3c44b7b

File tree

10 files changed

+85
-226
lines changed

10 files changed

+85
-226
lines changed

.cspell/framework-words.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cupertino
1313
dorny
1414
dotenv
1515
draggable
16+
endtemplate
1617
fastlane
1718
firestore
1819
flutterfire
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Dependency Adoption Principles
2+
3+
## Why we prefer fewer dependencies
4+
5+
- Smaller dependency graph is easier to audit and keep secure.
6+
- Fewer transitive packages reduce upgrade churn and version conflicts.
7+
- Build and CI setup stay simpler and more predictable.
8+
9+
## Why we prefer less code generation
10+
11+
- Generated code increases maintenance cost and review overhead.
12+
- Build steps become slower and more fragile.
13+
- Debugging becomes harder when logic is hidden behind generated layers.
14+
15+
## Guidance for adding dependencies
16+
17+
When proposing a new package, confirm:
18+
19+
1. It solves a concrete problem we cannot reasonably address with existing tools.
20+
2. The dependency impact is small and well-scoped.
21+
3. Code generation is optional or clearly worth the trade-off.
22+
23+
If a package requires heavy code generation (like retrofit), document the reason
24+
and consider a lighter alternative first.
25+
26+
## History: removal of retrofit / freezed / riverpod_generator
27+
28+
We removed `retrofit`, `freezed` and `riverpod_generator` from this template.
29+
The intent was to reduce the dependency surface and limit code generation.

packages/flutter_app/lib/package_adaptor/pub_dev_api_client_provider.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
22
import 'package:pub_dev_api_client/pub_dev_api_client.dart';
33

44
final pubDevApiClientProvider = Provider<PubDevApiClient>((ref) {
5-
return PubDevApiClient.fromParameters(
5+
return PubDevApiClient(
66
baseUrl: 'https://pub.dev/api',
77
timeoutDuration: const Duration(seconds: 30),
88
);

packages/pub_dev_api_client/build.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,3 @@ targets:
1414
checked: true
1515
explicit_to_json: true
1616
field_rename: snake
17-
retrofit_generator:
18-
generate_for:
19-
include:
20-
- lib/**/*_client.dart
Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,60 @@
11
import 'package:dio/dio.dart';
2-
import 'package:retrofit/retrofit.dart' hide Headers;
32

43
import 'models/models.dart';
54

6-
part 'pub_dev_api_client.g.dart';
7-
5+
/// {@template pub_dev_api_client.PubDevApiClient}
86
/// Client for the Pub.dev API.
9-
@RestApi()
10-
abstract class PubDevApiClient {
11-
/// Internal constructor.
12-
factory PubDevApiClient.internal(Dio dio, {String baseUrl}) =
13-
_PubDevApiClient;
14-
15-
/// Create a client from parameters.
16-
factory PubDevApiClient.fromParameters({
7+
/// {@endtemplate}
8+
class PubDevApiClient {
9+
/// {@macro pub_dev_api_client.PubDevApiClient}
10+
PubDevApiClient({
1711
required String baseUrl,
1812
required Duration timeoutDuration,
19-
}) {
20-
return _PubDevApiClient(
21-
Dio(
22-
BaseOptions(
23-
baseUrl: baseUrl,
24-
connectTimeout: timeoutDuration,
25-
sendTimeout: timeoutDuration,
26-
receiveTimeout: timeoutDuration,
27-
contentType: Headers.jsonContentType,
28-
),
29-
)..interceptors.add(LogInterceptor(responseBody: true)),
30-
);
31-
}
13+
}) : _dio = Dio(
14+
BaseOptions(
15+
baseUrl: baseUrl,
16+
connectTimeout: timeoutDuration,
17+
sendTimeout: timeoutDuration,
18+
receiveTimeout: timeoutDuration,
19+
contentType: Headers.jsonContentType,
20+
),
21+
)..interceptors.add(LogInterceptor(responseBody: true));
22+
23+
final Dio _dio;
3224

3325
/// Get packages by search word.
34-
@GET('/search')
3526
Future<GetSearchedPackagesResponseBody> getSearchedPackages({
36-
@Query('q') String? searchWord,
37-
@Query('sort') String? sort = 'top',
38-
@Query('page') int? page,
39-
});
27+
String? searchWord,
28+
String? sort = 'top',
29+
int? page,
30+
}) async {
31+
final queryParameters = <String, dynamic>{
32+
'q': searchWord,
33+
'sort': sort,
34+
'page': page,
35+
}..removeWhere((_, value) => value == null);
36+
final response = await _dio.get<Map<String, dynamic>>(
37+
'/search',
38+
queryParameters: queryParameters,
39+
);
40+
final data = response.data;
41+
if (data == null) {
42+
throw StateError('Response data is null.');
43+
}
44+
return GetSearchedPackagesResponseBody.fromJson(data);
45+
}
4046

4147
/// Get particular package details.
42-
@GET('/packages/{name}')
4348
Future<GetPackageDetailsResponseBody> getPackageDetails({
44-
@Path('name') required String packageName,
45-
});
49+
required String packageName,
50+
}) async {
51+
final response = await _dio.get<Map<String, dynamic>>(
52+
'/packages/$packageName',
53+
);
54+
final data = response.data;
55+
if (data == null) {
56+
throw StateError('Response data is null.');
57+
}
58+
return GetPackageDetailsResponseBody.fromJson(data);
59+
}
4660
}

packages/pub_dev_api_client/lib/src/pub_dev_api_client.g.dart

Lines changed: 0 additions & 115 deletions
This file was deleted.

packages/pub_dev_api_client/pubspec.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ dependencies:
1212
equatable: ^2.0.5
1313
json_annotation: ^4.9.0
1414
mock_web_server: ^5.0.0-nullsafety.1
15-
retrofit: ^4.6.0
1615

1716
dev_dependencies:
1817
altive_lints: ^2.1.0
1918
build_runner: ^2.4.13
2019
json_serializable: ^6.9.5
21-
retrofit_generator: ^10.2.0
2220
test: ^1.28.0

packages/pub_dev_api_client/test/src/pub_dev_api_client_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:test/test.dart';
77

88
void main() {
99
PubDevApiClient createClient({required String baseUrl}) {
10-
final client = PubDevApiClient.fromParameters(
10+
final client = PubDevApiClient(
1111
baseUrl: baseUrl,
1212
timeoutDuration: const Duration(milliseconds: 30000),
1313
);
@@ -30,7 +30,7 @@ void main() {
3030
group('fromParameters', () {
3131
test('Ensure that RestApiClient can be instantiated '
3232
'using the fromParameters constructor', () {
33-
final client = PubDevApiClient.fromParameters(
33+
final client = PubDevApiClient(
3434
baseUrl: 'https://example.com/api-base-url',
3535
timeoutDuration: const Duration(seconds: 30),
3636
);

0 commit comments

Comments
 (0)