Skip to content

Commit d47173b

Browse files
authored
remote package:http from package:intl (#928)
1 parent 904f1c5 commit d47173b

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

pkgs/intl/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 0.20.2-wip
2+
* Remove the dependency on `package:http`.
3+
14
## 0.20.1
25
* Upgrade `package:web` dependency constraint to `1.1.0`, fixes issue
36
[#916](https://github.com/dart-lang/i18n/issues/916).

pkgs/intl/lib/date_symbol_data_http_request.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export 'src/data/dates/locale_list.dart';
2020
/// The [url] parameter should end with a "/". For example,
2121
/// "http://localhost:8000/dates/"
2222
Future<void> initializeDateFormatting(String locale, String url) {
23-
//Initialize symbols
23+
// Initialize symbols
2424
var symbolReader = HttpRequestDataReader('${url}symbols/');
2525
LazyLocaleData symbolsInitializer() => LazyLocaleData(
2626
symbolReader,
@@ -29,7 +29,7 @@ Future<void> initializeDateFormatting(String locale, String url) {
2929
);
3030
initializeDateSymbols(symbolsInitializer);
3131

32-
//Initialize patterns
32+
// Initialize patterns
3333
var patternsReader = HttpRequestDataReader('${url}patterns/');
3434
LazyLocaleData patternsInitializer() => LazyLocaleData(
3535
patternsReader,
@@ -43,7 +43,7 @@ Future<void> initializeDateFormatting(String locale, String url) {
4343
availableLocalesForDateFormatting.contains,
4444
)!;
4545

46-
//Initialize locale for both symbols and patterns
46+
/// Initialize locale for both symbols and patterns.
4747
Future<List<void>> initLocale(
4848
LazyLocaleData symbols,
4949
LazyLocaleData patterns,

pkgs/intl/lib/src/http_request_data_reader.dart

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,40 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
/// This contains a reader that accesses data using the HttpRequest
6-
/// facility, and thus works only in the web browser.
5+
/// This contains a reader that accesses data using the HttpRequest facility,
6+
/// and thus works only in the web browser.
77
library;
88

99
import 'dart:async';
10-
import 'package:http/http.dart';
10+
import 'dart:js_interop';
11+
12+
import 'package:web/web.dart';
13+
1114
import 'intl_helpers.dart';
1215

1316
class HttpRequestDataReader implements LocaleDataReader {
1417
/// The base url from which we read the data.
15-
String url;
18+
final String url;
1619

1720
HttpRequestDataReader(this.url);
1821

1922
@override
2023
Future<String> read(String locale) {
21-
final Client client = Client();
22-
return _getString('$url$locale.json', client).timeout(
24+
return _getString('$url$locale.json').timeout(
2325
Duration(seconds: 5),
2426
onTimeout: () {
25-
client.close();
2627
throw TimeoutException('Timeout while reading $locale');
2728
},
2829
);
2930
}
3031

31-
Future<String> _getString(String url, Client client) async {
32-
final response = await client.get(Uri.parse(url));
32+
Future<String> _getString(String url) async {
33+
final response = await window.fetch(url.toJS).toDart;
3334

34-
if ((response.statusCode >= 200 && response.statusCode < 300) ||
35-
response.statusCode == 0 ||
36-
response.statusCode == 304) {
37-
return response.body;
35+
if ((response.status >= 200 && response.status < 300) ||
36+
response.status == 0 ||
37+
response.status == 304) {
38+
return (await response.text().toDart).toDart;
3839
} else {
3940
throw Exception('Failed to load $url');
4041
}

pkgs/intl/pubspec.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: intl
2-
version: 0.20.1
2+
version: 0.20.2-wip
33
description: >-
44
Contains code to deal with internationalized/localized messages, date and
55
number formatting and parsing, bi-directional text, and other
@@ -16,8 +16,7 @@ environment:
1616

1717
dependencies:
1818
clock: ^1.1.0
19-
http: ^1.0.0
20-
meta: ^1.0.2
19+
meta: ^1.3.0
2120
path: ^1.8.0
2221
web: ^1.1.0
2322

@@ -26,4 +25,4 @@ dev_dependencies:
2625
ffi: ^2.1.3
2726
fixnum: ^1.0.0
2827
lints: ^5.0.0
29-
test: ^1.16.0
28+
test: ^1.16.6

0 commit comments

Comments
 (0)