Skip to content

Commit d9716fc

Browse files
committed
fix: remove unnecessary try catch
1 parent b957f9b commit d9716fc

4 files changed

Lines changed: 33 additions & 45 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.2.2
2+
3+
- fix: remove unnecessary try catch
4+
15
## 1.2.1+3
26

37
- chore: add more docs for API

lib/src/sheet_remote_config.dart

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,8 @@ class SheetRemoteConfig {
135135
/// ```
136136
/// {@endtemplate}
137137
String? getString(String key, {String? defaultValue}) {
138-
try {
139-
final valueAtKey = _inMemoryCachedConfig[key];
140-
return valueAtKey ?? defaultValue;
141-
} catch (e) {
142-
return defaultValue;
143-
}
138+
final valueAtKey = _inMemoryCachedConfig[key];
139+
return valueAtKey ?? defaultValue;
144140
}
145141

146142
/// Return the value of the given key from the in-memory cache as a [bool].
@@ -149,17 +145,13 @@ class SheetRemoteConfig {
149145
///
150146
/// {@macro get_value}
151147
bool? getBool(String key, {bool? defaultValue}) {
152-
try {
153-
final value = _inMemoryCachedConfig[key];
154-
if (value == null && value!.isEmpty) return defaultValue;
155-
final boolValue = bool.tryParse(
156-
value,
157-
caseSensitive: false,
158-
);
159-
return boolValue ?? defaultValue;
160-
} catch (e) {
161-
return defaultValue;
162-
}
148+
final valueAtKey = _inMemoryCachedConfig[key];
149+
if (valueAtKey == null || valueAtKey.isEmpty) return defaultValue;
150+
final boolValue = bool.tryParse(
151+
valueAtKey,
152+
caseSensitive: false,
153+
);
154+
return boolValue ?? defaultValue;
163155
}
164156

165157
/// Return the value of the given key from the in-memory cache as an [int].
@@ -168,14 +160,10 @@ class SheetRemoteConfig {
168160
///
169161
/// {@macro get_value}
170162
int? getInt(String key, {int? defaultValue}) {
171-
try {
172-
final valueAtKey = _inMemoryCachedConfig[key];
173-
if (valueAtKey == null && valueAtKey!.isEmpty) return defaultValue;
174-
final intValue = int.tryParse(valueAtKey);
175-
return intValue ?? defaultValue;
176-
} catch (e) {
177-
return defaultValue;
178-
}
163+
final valueAtKey = _inMemoryCachedConfig[key];
164+
if (valueAtKey == null || valueAtKey.isEmpty) return defaultValue;
165+
final intValue = int.tryParse(valueAtKey);
166+
return intValue ?? defaultValue;
179167
}
180168

181169
/// Return the value of the given key from the in-memory cache as a [double].
@@ -184,14 +172,10 @@ class SheetRemoteConfig {
184172
///
185173
/// {@macro get_value}
186174
double? getDouble(String key, {double? defaultValue}) {
187-
try {
188-
final valueAtKey = _inMemoryCachedConfig[key];
189-
if (valueAtKey == null && valueAtKey!.isEmpty) return defaultValue;
190-
final doubleValue = double.tryParse(valueAtKey);
191-
return doubleValue ?? defaultValue;
192-
} catch (e) {
193-
return defaultValue;
194-
}
175+
final valueAtKey = _inMemoryCachedConfig[key];
176+
if (valueAtKey == null || valueAtKey.isEmpty) return defaultValue;
177+
final doubleValue = double.tryParse(valueAtKey);
178+
return doubleValue ?? defaultValue;
195179
}
196180

197181
/// Return all the values from the in-memory cache.

pubspec.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ packages:
55
dependency: transitive
66
description:
77
name: _fe_analyzer_shared
8-
sha256: "16e298750b6d0af7ce8a3ba7c18c69c3785d11b15ec83f6dcd0ad2a0009b3cab"
8+
sha256: "45cfa8471b89fb6643fe9bf51bd7931a76b8f5ec2d65de4fb176dba8d4f22c77"
99
url: "https://pub.dev"
1010
source: hosted
11-
version: "76.0.0"
11+
version: "73.0.0"
1212
_macros:
1313
dependency: transitive
1414
description: dart
1515
source: sdk
16-
version: "0.3.3"
16+
version: "0.3.2"
1717
analyzer:
1818
dependency: transitive
1919
description:
2020
name: analyzer
21-
sha256: "1f14db053a8c23e260789e9b0980fa27f2680dd640932cae5e1137cce0e46e1e"
21+
sha256: "4959fec185fe70cce007c57e9ab6983101dbe593d2bf8bbfb4453aaec0cf470a"
2222
url: "https://pub.dev"
2323
source: hosted
24-
version: "6.11.0"
24+
version: "6.8.0"
2525
args:
2626
dependency: transitive
2727
description:
@@ -194,10 +194,10 @@ packages:
194194
dependency: "direct dev"
195195
description:
196196
name: lints
197-
sha256: c35bb79562d980e9a453fc715854e1ed39e24e7d0297a880ef54e17f9874a9d7
197+
sha256: "3315600f3fb3b135be672bf4a178c55f274bebe368325ae18462c89ac1e3b413"
198198
url: "https://pub.dev"
199199
source: hosted
200-
version: "5.1.1"
200+
version: "5.0.0"
201201
logging:
202202
dependency: transitive
203203
description:
@@ -210,10 +210,10 @@ packages:
210210
dependency: transitive
211211
description:
212212
name: macros
213-
sha256: "1d9e801cd66f7ea3663c45fc708450db1fa57f988142c64289142c9b7ee80656"
213+
sha256: "0acaed5d6b7eab89f63350bccd82119e6c602df0f391260d0e32b5e23db79536"
214214
url: "https://pub.dev"
215215
source: hosted
216-
version: "0.1.3-main.0"
216+
version: "0.1.2-main.4"
217217
matcher:
218218
dependency: transitive
219219
description:
@@ -242,10 +242,10 @@ packages:
242242
dependency: "direct dev"
243243
description:
244244
name: mockito
245-
sha256: f99d8d072e249f719a5531735d146d8cf04c580d93920b04de75bef6dfb2daf6
245+
sha256: "6841eed20a7befac0ce07df8116c8b8233ed1f4486a7647c7fc5a02ae6163917"
246246
url: "https://pub.dev"
247247
source: hosted
248-
version: "5.4.5"
248+
version: "5.4.4"
249249
node_preamble:
250250
dependency: transitive
251251
description:

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: dart_gsheet_remote_config
22
description: A package that allows you to use Google Sheets as a remote config for changing your Dart/Flutter app's behaviors, settings,.. without updating.
3-
version: 1.2.1+3
3+
version: 1.2.2
44
topics: [remote, config]
55
repository: https://github.com/dungngminh/dart_gsheet_remote_config
66

0 commit comments

Comments
 (0)