Skip to content

Commit

Permalink
Fix some runtime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sudo-panda committed Aug 13, 2023
1 parent 432b0b8 commit 6e01a01
Show file tree
Hide file tree
Showing 17 changed files with 278 additions and 219 deletions.
3 changes: 2 additions & 1 deletion lib/assets/app_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class AppTheme {
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: _darkPrimaryVariantColor),
),
), colorScheme: ColorScheme.light(
),
colorScheme: ColorScheme.dark(
primary: _darkPrimaryColor,
secondary: _iconColor,
background: _darkBackgroundColor,
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/database_actions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ class DatabaseActions {
}

static Future<bool> addTracked(
String code, String exchange, String name, bool pinned) async {
String code, String exchange, String? name, bool pinned) async {
return await Db().insert(Db.tblTracked, {
Db.colCode: code,
Db.colExch: exchange,
Expand Down
12 changes: 6 additions & 6 deletions lib/models/database/portfolio.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:folio/services/database/database.dart';

class Portfolio {
late int rowid;
late String bseCode;
late String nseCode;
late int qty;
late double msr;
late double esr;
late int? rowid;
late String? bseCode;
late String? nseCode;
late int? qty;
late double? msr;
late double? esr;

Portfolio.fromDbTuple(Map<String, dynamic> tuple) {
rowid = tuple["rowid"];
Expand Down
16 changes: 8 additions & 8 deletions lib/models/stock/latest.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
class Latest {
double value = 0.0;
String change = "";
String percentageChange = "";
double? value;
String? change;
String? percentageChange;
int sign = 0;
String updated = "";
String? updated;

Latest();

Expand All @@ -13,14 +13,14 @@ class Latest {
@override
String toString() {
return 'value: ' +
value.toStringAsFixed(2) +
(value?.toStringAsFixed(2) ?? "NULL") +
'\nchange: ' +
change +
(change ?? "NULL") +
'\npercentageChange: ' +
percentageChange +
(percentageChange ?? "NULL") +
'\nsign: ' +
sign.toString() +
'\ntime: ' +
updated;
(updated ?? "NULL");
}
}
32 changes: 17 additions & 15 deletions lib/models/stock/stock.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class Stock {
_tracked = Tracked.fromDbTuple(tuple),
_latest = Latest();

int get id => _portfolio.rowid;
int? get id => _portfolio.rowid;

String? get name => _tracked?.name;
String? get name => _tracked.name;

String? get exchange => _tracked?.exchange;
String get exchange => _tracked.exchange;

String? get code => _tracked?.code;
String get code => _tracked.code;

int? get qty => _portfolio?.qty;

Expand Down Expand Up @@ -53,9 +53,9 @@ class Stock {

bool get pinned => _tracked.pinned;

String get bseCode => _portfolio.bseCode;
String? get bseCode => _portfolio.bseCode;

String get nseCode => _portfolio.nseCode;
String? get nseCode => _portfolio.nseCode;

set pinned(bool pin) {
_tracked.pinned = pin;
Expand All @@ -65,28 +65,30 @@ class Stock {
_tracked.name = name;
}

set bseCode(String code) {
set bseCode(String? code) {
if (code == null) return;
_portfolio.bseCode = code;

if (_tracked.exchange == "BSE") {
_tracked.code = code;
}
}

set nseCode(String code) {
set nseCode(String? code) {
if (code == null) return;
_portfolio.nseCode = code;

if (_tracked.exchange == "NSE") {
_tracked.code = code;
}
}

set latest(Latest data) {
_latest.change = data?.change ?? _latest.change;
_latest.percentageChange =
data?.percentageChange ?? _latest.percentageChange;
_latest.sign = data?.sign ?? 0;
_latest.updated = data!.updated;
_latest.value = data!.value;
set latest(Latest? data) {
if (data == null) return;
_latest.change = data.change;
_latest.percentageChange = data.percentageChange;
_latest.sign = data.sign;
_latest.updated = data.updated;
_latest.value = data.value;
}
}
4 changes: 2 additions & 2 deletions lib/services/query/query_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class QueryAPI {
},
);

if (r.statusCode == 200) {
if (r.statusCode == 200 && r.data != null) {
var data = jsonDecode(r.data!.substring(4))['PriceUpdate']['entities']
.first['financial_entity']['common_entity_data'];

Expand Down Expand Up @@ -94,7 +94,7 @@ class QueryAPI {
},
);

if (r.statusCode == 200) {
if (r.statusCode == 200 && r.data != null) {
var ret = jsonDecode(r.data!.substring(4))['PriceUpdate']['entities']
.first['financial_entity']['common_entity_data']['name']
.toString();
Expand Down
4 changes: 2 additions & 2 deletions lib/services/query/query_bse_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class QueryBSEAPI {
"seriesid": "",
},
);
if (r.statusCode == 200) {
if (r.statusCode == 200 && r.data != null) {
var data = jsonDecode(r.data!);
double currVal = double.parse(data['CurrVal']);
double prevClose = double.parse(data['PrevClose']);
Expand Down Expand Up @@ -70,7 +70,7 @@ class QueryBSEAPI {
"seriesid": "",
},
);
if (r.statusCode == 200) {
if (r.statusCode == 200 && r.data != null) {
return jsonDecode(r.data!)['Cmpname']['FullN'].toString();
} else {
log("query_bse_api.getName($code) => \n " +
Expand Down
11 changes: 8 additions & 3 deletions lib/services/query/query_nse_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class NetworkService {
throw new Exception("Error while fetching data: " +
statusCode.toString() +
"\n\n" +
response.request!.headers.toString());
(response.request?.headers?.toString() ??
"<<< Headers are NULL >>>"));
}
return res;
}
Expand Down Expand Up @@ -99,7 +100,9 @@ class QueryNSEAPI {
try {
await session.get(uri, headers);
} catch (e) {
dev.log("query_nse_api.getCurrentData($code) => \nNSE: Error getting cookies : " + e.toString());
dev.log(
"query_nse_api.getCurrentData($code) => \nNSE: Error getting cookies : " +
e.toString());
}

uri = Uri.https(
Expand Down Expand Up @@ -151,7 +154,9 @@ class QueryNSEAPI {
try {
await session.get(uri, headers);
} catch (e) {
dev.log("query_nse_api.getCurrentData($code) => \nNSE: Error getting cookies : " + e.toString());
dev.log(
"query_nse_api.getCurrentData($code) => \nNSE: Error getting cookies : " +
e.toString());
}

uri = Uri.https(
Expand Down
18 changes: 9 additions & 9 deletions lib/views/portfolio/portfolio_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ class PortfolioTile extends StatelessWidget {
alignment: WrapAlignment.center,
runAlignment: WrapAlignment.center,
children: [
_portfolio?.bseCode != null
_portfolio.bseCode != null
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 10.0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"BSE - " + (_portfolio?.bseCode)!,
"BSE - " + _portfolio.bseCode!,
style: Theme.of(context).textTheme.bodyLarge,
),
SizedBox(
Expand All @@ -58,7 +58,7 @@ class PortfolioTile extends StatelessWidget {
await showDialog(
context: context,
builder: (context) => EditCodeDialog(
_portfolio!.bseCode!,
_portfolio.bseCode!,
"BSE",
updateBSECode),
);
Expand All @@ -70,14 +70,14 @@ class PortfolioTile extends StatelessWidget {
: Container(
width: 0,
),
_portfolio?.nseCode != null
_portfolio.nseCode != null
? Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.0),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Text(
"NSE - " + _portfolio!.nseCode,
"NSE - " + _portfolio.nseCode!,
style: Theme.of(context).textTheme.bodyLarge,
),
SizedBox(
Expand All @@ -96,7 +96,7 @@ class PortfolioTile extends StatelessWidget {
showDialog(
context: context,
builder: (context) => EditCodeDialog(
_portfolio!.nseCode!,
_portfolio.nseCode!,
"NSE",
updateNSECode),
);
Expand All @@ -118,7 +118,7 @@ class PortfolioTile extends StatelessWidget {
Expanded(
flex: 2,
child: Text(
_portfolio?.qty?.toString() ?? "N/A",
_portfolio.qty?.toString() ?? "",
textAlign: TextAlign.center,
style: Theme.of(context)
.textTheme
Expand All @@ -129,7 +129,7 @@ class PortfolioTile extends StatelessWidget {
Expanded(
flex: 3,
child: Text(
_portfolio?.msr?.toStringAsFixed(2) ?? "N/A",
_portfolio.msr?.toStringAsFixed(2) ?? "",
textAlign: TextAlign.center,
style: Theme.of(context)
.textTheme
Expand All @@ -140,7 +140,7 @@ class PortfolioTile extends StatelessWidget {
Expanded(
flex: 3,
child: Text(
_portfolio?.esr?.toStringAsFixed(2) ?? "N/A",
_portfolio?.esr?.toStringAsFixed(2) ?? "",
textAlign: TextAlign.center,
style: Theme.of(context)
.textTheme
Expand Down
6 changes: 3 additions & 3 deletions lib/views/settings/data/add_portfolio_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class _AddPortfolioDialogState extends State<AddPortfolioDialog> {
keyboardType: TextInputType.text,
controller: _nseCodeCtl,
validator: (value) {
if (value!.isEmpty) {
if (value == null || value.isEmpty) {
return 'Required';
}
return null;
Expand All @@ -83,7 +83,7 @@ class _AddPortfolioDialogState extends State<AddPortfolioDialog> {
keyboardType: TextInputType.text,
controller: _bseCodeCtl,
validator: (value) {
if (value!.isEmpty) {
if (value == null || value.isEmpty) {
return 'Required';
}
return null;
Expand Down Expand Up @@ -117,7 +117,7 @@ class _AddPortfolioDialogState extends State<AddPortfolioDialog> {
)),
child: Text("Add"),
onPressed: () {
if (_formKey.currentState!.validate()) {
if (_formKey.currentState != null && _formKey.currentState!.validate()) {
DatabaseActions.linkCodes({
'NSE': _nseCodeCtl.text,
'BSE': _bseCodeCtl.text,
Expand Down
Loading

0 comments on commit 6e01a01

Please sign in to comment.