Skip to content

Commit

Permalink
fix: Flutter format
Browse files Browse the repository at this point in the history
  • Loading branch information
rj-since-2000 committed Aug 8, 2021
1 parent acf75b4 commit 82fedcf
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 131 deletions.
1 change: 1 addition & 0 deletions lib/models/torrent.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:rutorrentflutter/models/account.dart';

enum Status {
downloading,
paused,
Expand Down
62 changes: 31 additions & 31 deletions lib/services/api/prod_api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,49 +107,49 @@ class ProdApiService implements IApiService {
log.v("Fetching torrent lists from all accounts");
List<Account?>? accounts = _authenticationService!.accounts.value;
while (true) {
List<Torrent> allTorrentList = [];
try {
for (Account? account in accounts) {
try {
var response = await ioClient.post(Uri.parse(httpRpcPluginUrl),
headers: getAuthHeader(),
body: {
'mode': 'list',
});
allTorrentList.addAll(_parseTorrentData(response.body, account)!);
} catch (e) {
print(e);
List<Torrent> allTorrentList = [];
try {
for (Account? account in accounts) {
try {
var response = await ioClient.post(Uri.parse(httpRpcPluginUrl),
headers: getAuthHeader(),
body: {
'mode': 'list',
});
allTorrentList.addAll(_parseTorrentData(response.body, account)!);
} catch (e) {
print(e);
}
}
} catch (e) {
print('Account Changes');
}
} catch (e) {
print('Account Changes');
}
yield allTorrentList;
await Future.delayed(Duration(seconds: 1), () {});
yield allTorrentList;
await Future.delayed(Duration(seconds: 1), () {});
}
}

/// Gets list of torrents for a particular account
Stream<List<Torrent?>?> getTorrentList() async* {
log.v("Fetching torrent lists from all accounts");
while (true) {
try {
var response = await ioClient
.post(Uri.parse(httpRpcPluginUrl), headers: getAuthHeader(), body: {
'mode': 'list',
});

yield _parseTorrentData(response.body, account)!;
} catch (e) {
print('Exception caught in getTorrentList Api Request ' + e.toString());
/*returning null since the stream has to be active all the times to return something
try {
var response = await ioClient
.post(Uri.parse(httpRpcPluginUrl), headers: getAuthHeader(), body: {
'mode': 'list',
});

yield _parseTorrentData(response.body, account)!;
} catch (e) {
print('Exception caught in getTorrentList Api Request ' + e.toString());
/*returning null since the stream has to be active all the times to return something
this usually occurs when there is no torrent task available or when the connect
to rTorrent is not established
*/
yield null;
}
// Producing artificial delay of one second
await Future.delayed(Duration(seconds: 1), () {});
yield null;
}
// Producing artificial delay of one second
await Future.delayed(Duration(seconds: 1), () {});
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/services/functional_services/authentication_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import 'package:stacked_services/stacked_services.dart';
Logger log = getLogger("AuthenticationService");

///[Service] used for all functionalities related to authentication and its state
class AuthenticationService extends ChangeNotifier{
class AuthenticationService extends ChangeNotifier {
SharedPreferencesService? _sharedPreferencesService =
locator<SharedPreferencesService>();
NavigationService _navigationService = locator<NavigationService>();

///List of user accounts
ValueNotifier<List<Account>> _accounts = new ValueNotifier(new List<Account>.empty());
ValueNotifier<List<Account>> _accounts =
new ValueNotifier(new List<Account>.empty());

///Temp account used to verify login credentials
Account? _tempAccount;
Expand All @@ -43,8 +44,7 @@ class AuthenticationService extends ChangeNotifier{
Future<List<Account?>> saveLogin(Account? account) async {
log.i("User being saved");
if (account == null) return [];
List<Account> accounts =
await _sharedPreferencesService!.fetchSavedLogin();
List<Account> accounts = await _sharedPreferencesService!.fetchSavedLogin();
bool alreadyLoggedIn = false;

for (int index = 0; index < accounts.length; index++) {
Expand Down
4 changes: 2 additions & 2 deletions lib/services/functional_services/notification_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ class NotificationService {
///
/// }
///
/// dispatchLocalNotification(
/// dispatchLocalNotification(
///
/// key : _notificationService.< Notification_Channel_Name >,
/// key : _notificationService.< Notification_Channel_Name >,
///
/// customData : notificationsMap
///
Expand Down
124 changes: 65 additions & 59 deletions lib/ui/views/Settings/settings_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'package:rutorrentflutter/ui/views/Settings/settings_viewmodel.dart';
import 'package:stacked/stacked.dart';

class SettingsView extends StatelessWidget {

const SettingsView({Key? key}) : super(key: key);

@override
Expand All @@ -23,66 +22,73 @@ class SettingsView extends StatelessWidget {
child: Column(
children: <Widget>[
ValueListenableBuilder(
valueListenable: model.accounts,
builder: (context, List<Account> accounts, snapshot) {
return ExpansionTile(
title: Text('Manage Accounts',
style: TextStyle(fontWeight: FontWeight.w600)),
children: <Widget>[
ListView.builder(
shrinkWrap: true,
itemCount: accounts.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
// CHANGE PASSWORD
model.showPasswordChangeDialog(context, index);
},
child: ListTile(
dense: true,
leading: Icon(
Icons.supervisor_account,
color: !AppStateNotifier.isDarkModeOn
? Colors.black
: Colors.white,
),
title: Text(
Uri.parse(accounts[index].url ?? "").host,
style: TextStyle(
fontSize: 14, fontWeight: FontWeight.w600)),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
accounts[index].username ?? "",
style: TextStyle(
fontWeight: FontWeight.w600, fontSize: 12),
),
SizedBox(height: 3,),
Text(
'Change Password',
valueListenable: model.accounts,
builder: (context, List<Account> accounts, snapshot) {
return ExpansionTile(
title: Text('Manage Accounts',
style: TextStyle(fontWeight: FontWeight.w600)),
children: <Widget>[
ListView.builder(
shrinkWrap: true,
itemCount: accounts.length,
itemBuilder: (context, index) {
return GestureDetector(
onTap: () {
// CHANGE PASSWORD
model.showPasswordChangeDialog(
context, index);
},
child: ListTile(
dense: true,
leading: Icon(
Icons.supervisor_account,
color: !AppStateNotifier.isDarkModeOn
? Colors.black
: Colors.white,
),
title: Text(
Uri.parse(accounts[index].url ?? "").host,
style: TextStyle(
fontWeight: FontWeight.w600, fontSize: 12),
),
],
fontSize: 14,
fontWeight: FontWeight.w600)),
subtitle: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
accounts[index].username ?? "",
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 12),
),
SizedBox(
height: 3,
),
Text(
'Change Password',
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 12),
),
],
),
trailing: IconButton(
icon: Icon(
Icons.delete_forever,
color: Theme.of(context).primaryColor,
size: 28,
),
onPressed: () {
// DELETE ACCOUNT
model.showDeleteAccountDialog(
context, index);
}),
),
trailing: IconButton(
icon: Icon(
Icons.delete_forever,
color: Theme.of(context).primaryColor,
size: 28,
),
onPressed: () {
// DELETE ACCOUNT
model.showDeleteAccountDialog(context, index);
}),
),
);
})
],
);
}
),
);
})
],
);
}),
ListTile(
title: Text('Notifications',
style: TextStyle(fontWeight: FontWeight.w600)),
Expand Down
3 changes: 2 additions & 1 deletion lib/ui/views/torrent_detail/torrent_detail_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ class TorrentDetailView extends StatelessWidget {
child: IconButton(
color: Colors.black,
iconSize: 40,
icon: Icon(model.torrent.isOpen == 0
icon: Icon(model.torrent.isOpen ==
0
? Icons.play_arrow
: model.torrent.getState == 0
? (Icons.play_arrow)
Expand Down
6 changes: 4 additions & 2 deletions lib/ui/views/torrent_detail/torrent_detail_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ class TorrentDetailViewModel extends BaseViewModel {
toggleTorrentCurrentStatus() async {
await _apiService.toggleTorrentStatus(torrent);
await _torrentService.refreshTorrentList();
_torrent = _torrentService.torrentsList.value.firstWhere((tor) => tor.hash==_torrent.hash);
_torrent = _torrentService.torrentsList.value
.firstWhere((tor) => tor.hash == _torrent.hash);
notifyListeners();
}

stopTorrent() async {
await _apiService.stopTorrent(_torrent.hash ?? "");
await _torrentService.refreshTorrentList();
_torrent = _torrentService.torrentsList.value.firstWhere((tor) => tor.hash==_torrent.hash);
_torrent = _torrentService.torrentsList.value
.firstWhere((tor) => tor.hash == _torrent.hash);
notifyListeners();
}

Expand Down
18 changes: 9 additions & 9 deletions lib/ui/widgets/dumb_widgets/add_another_account_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import 'package:flutter/material.dart';

// ignore: non_constant_identifier_names
Widget AddAnotherAccountWidget({required Function onTap}) {
return Container(
child: ListTile(
dense: true,
leading: Icon(Icons.add),
title: Text('Add another account'),
onTap: () => onTap(),
),
);
}
return Container(
child: ListTile(
dense: true,
leading: Icon(Icons.add),
title: Text('Add another account'),
onTap: () => onTap(),
),
);
}
3 changes: 1 addition & 2 deletions lib/ui/widgets/dumb_widgets/filter_tile_list_widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ List filterTileIcons = [
Icons.error,
];


// List<FilterTile> filterTileList = [
// FilterTile(
// icon: Icons.filter_tilt_shift,
Expand All @@ -69,4 +68,4 @@ List filterTileIcons = [
// icon: Icons.error,
// filter: Filter.Error,
// ),
// ];
// ];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

23 changes: 11 additions & 12 deletions lib/ui/widgets/smart_widgets/drawer/drawer_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,17 @@ class DrawerView extends StatelessWidget {
children: <Widget>[
ShowDiskSpace(model.diskSpace),
ValueListenableBuilder(
valueListenable: model.getAccountValueListenable,
builder: (context, accounts, snapshot) {
return ExpansionTile(
leading: Icon(Icons.supervisor_account,
color: !AppStateNotifier.isDarkModeOn
? Colors.black
: Colors.white),
title: Text('Accounts'),
children: model.getAccountsList(context),
);
}
),
valueListenable: model.getAccountValueListenable,
builder: (context, accounts, snapshot) {
return ExpansionTile(
leading: Icon(Icons.supervisor_account,
color: !AppStateNotifier.isDarkModeOn
? Colors.black
: Colors.white),
title: Text('Accounts'),
children: model.getAccountsList(context),
);
}),
ExpansionTile(
initiallyExpanded: true,
leading: Icon(Icons.sort,
Expand Down
Loading

0 comments on commit 82fedcf

Please sign in to comment.