Skip to content

Commit

Permalink
Renamed methods,
Browse files Browse the repository at this point in the history
added setBool and fixed other bugs
  • Loading branch information
Pato05 committed Sep 2, 2020
1 parent 2dda641 commit 755f2ef
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
default:
result.notImplemented();
break;
case "setBool":
result.success(_sharedPrefs.edit().putBoolean(call.argument("name"), call.argument("value")).commit());
break;
case "getBool":
result.success(_sharedPrefs.getBoolean(call.argument("name"), false));
break;
}
});
}
Expand Down
12 changes: 9 additions & 3 deletions lib/androidApiWrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class APIWrapper {

Future<bool> saveFiles(Map files) {
print('called api.saveFiles($files)');
return saveString('uploaded_files', json.encode(files));
return setString('uploaded_files', json.encode(files));
}

Future<bool> saveString(String name, String content) =>
Future<bool> setString(String name, String content) =>
_methodChannel.invokeMethod(
'saveString', <String, String>{'name': name, 'content': content});

Expand All @@ -47,6 +47,12 @@ class APIWrapper {
_methodChannel.invokeMethod(
'getString', <String, String>{'name': name, 'default': defaultValue});

Future<bool> getBool(String name) =>
_methodChannel.invokeMethod('getBool', <String, String>{'name': name});

Future<bool> setBool(String name, bool value) => _methodChannel
.invokeMethod('setBool', <String, dynamic>{'name': name, 'value': value});

Future<Map> getFile() async {
String filePath = await _methodChannel.invokeMethod('getFile');
print(filePath);
Expand Down Expand Up @@ -90,7 +96,7 @@ class APIWrapper {

String fileName = file['name'];
int fileSize = file['size'];
MediaType mime = mimeTypes[fileName.split('.').last] ??
MediaType mime = mimeTypes[fileName.split('.').last.toLowerCase()] ??
MediaType('application', 'octet-stream');
print(mime);
print('processing file upload');
Expand Down
7 changes: 5 additions & 2 deletions lib/apiWrapperStub.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ class APIWrapper {
throw UnsupportedError('');
Future<bool> saveFiles(Map files) => throw UnsupportedError('');
Future<Map> getFiles() => throw UnsupportedError('');
Future<bool> saveString(String name, String content) =>
Future<bool> setString(String name, String content) =>
throw UnsupportedError('');
Future<String> getString(String name, String defaultValue) async =>
Future<String> getString(String name, String defaultValue) =>
throw UnsupportedError('');

Future<bool> getBool(String name) => throw UnsupportedError('');
Future<bool> setBool(String name, bool content) => throw UnsupportedError('');

Future<Map> uploadFile(
Map file, {
Function(int, int) onProgress,
Expand Down
8 changes: 4 additions & 4 deletions lib/appSettings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'apiWrapperStub.dart'
if (dart.library.html) 'webApiWrapper.dart';

class AppSettings {
static Map files;
static Map<String, Map> files;
static APIWrapper api = APIWrapper();
static String filesTheme = 'new';
static String fabTheme = 'extended';
Expand All @@ -20,7 +20,7 @@ class AppSettings {

static Future<Map<String, dynamic>> getFiles() async {
if (files == null) {
files = await api.getFiles();
files = (await api.getFiles()).cast<String, Map>();
}
return files;
}
Expand All @@ -31,7 +31,7 @@ class AppSettings {
}

static Future<bool> saveSettings() async {
return await api.saveString('fabTheme', fabTheme) &&
await api.saveString('filesTheme', filesTheme);
return await api.setString('fabTheme', fabTheme) &&
await api.setString('filesTheme', filesTheme);
}
}
108 changes: 57 additions & 51 deletions lib/fileInfo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,57 +77,63 @@ class _FileInfoRouteState extends State<FileInfoRoute> {
)
],
),
body: Padding(
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 50),
child: ListView(children: [
ConstrainedBox(
constraints: BoxConstraints(maxHeight: 170),
child: Center(
child: Icon(widget.fileIcon,
size: 56, color: Colors.grey.shade700)),
),
Padding(
child: Text(
widget.filename,
style: TextStyle(fontSize: 26, fontWeight: FontWeight.w500),
overflow: TextOverflow.visible,
),
padding: EdgeInsets.symmetric(vertical: 23)),
Table(
columnWidths: {
0: const FlexColumnWidth(0.3),
2: const FlexColumnWidth(0.7),
},
children: [
[
Text('Size', style: TextStyle(fontSize: fontSize)),
Text(humanSize(widget.fileSize),
style: TextStyle(fontSize: fontSize))
],
[
Text('URL', style: TextStyle(fontSize: fontSize)),
SelectableText(widget.url,
style: TextStyle(fontSize: fontSize))
],
[
Text('Uploaded on', style: TextStyle(fontSize: fontSize)),
Text(
uploadDateFormatted,
style: TextStyle(fontSize: fontSize),
)
body: ListView(children: [
Padding(
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 50),
child: Column(mainAxisSize: MainAxisSize.max, children: [
ConstrainedBox(
constraints: BoxConstraints(maxHeight: 170),
child: Center(
child: Icon(widget.fileIcon,
size: 56, color: Colors.grey.shade700)),
),
Row(children: [
Padding(
child: Text(
widget.filename,
style: TextStyle(
fontSize: 26, fontWeight: FontWeight.w500),
overflow: TextOverflow.visible,
textAlign: TextAlign.start,
),
padding: EdgeInsets.symmetric(vertical: 23))
]),
Table(
columnWidths: {
0: const FlexColumnWidth(0.3),
2: const FlexColumnWidth(0.7),
},
children: [
[
Text('Size', style: TextStyle(fontSize: fontSize)),
Text(humanSize(widget.fileSize),
style: TextStyle(fontSize: fontSize))
],
[
Text('URL', style: TextStyle(fontSize: fontSize)),
SelectableText(widget.url,
style: TextStyle(fontSize: fontSize))
],
[
Text('Uploaded on', style: TextStyle(fontSize: fontSize)),
Text(
uploadDateFormatted,
style: TextStyle(fontSize: fontSize),
)
]
]
]
.map((e) => TableRow(
children: e
.map((wid) => TableCell(
verticalAlignment:
TableCellVerticalAlignment.middle,
child: Container(
child: wid,
margin: EdgeInsets.only(bottom: 30))))
.toList()))
.toList(),
),
])));
.map((e) => TableRow(
children: e
.map((wid) => TableCell(
verticalAlignment:
TableCellVerticalAlignment.middle,
child: Container(
child: wid,
margin: EdgeInsets.only(bottom: 30))))
.toList()))
.toList(),
),
]))
]));
}
}
Loading

0 comments on commit 755f2ef

Please sign in to comment.