added send file to server function
This commit is contained in:
4
Todo.txt
4
Todo.txt
@@ -1,4 +1,5 @@
|
||||
todo:
|
||||
TEST SEND FILE TO SERVER FUNCTION
|
||||
maybe auch vorschläge aus templates in dropdown menüs anzeigen
|
||||
im englischen abändern
|
||||
zurückfeld in datenansicht
|
||||
@@ -8,8 +9,7 @@ fehler beim speichern anzeigen
|
||||
nach koordinaten lkr auswählen (esri-leaflet-geocoder)
|
||||
fix ktage und nebeneinander positioniere
|
||||
textdateien auch an server senden
|
||||
ausvon und ausbis fixen (falsches datum übergeben (20000-01-01))
|
||||
|
||||
error check wenn dateiauswahl abgebrochen wurde einfügen
|
||||
|
||||
keine ahnung obs funktioniert:
|
||||
eintrg in db wenn http response (in sent column)
|
||||
|
||||
@@ -2,7 +2,7 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:fforte/addCam/cam_widgets.dart';
|
||||
import 'package:fforte/db_helper.dart';
|
||||
import 'package:fforte/other/db_helper.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// ignore_for_file: non_constant_identifier_names
|
||||
import 'package:fforte/db_helper.dart';
|
||||
import 'package:fforte/other/db_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
|
||||
@@ -47,7 +47,7 @@ class HomePage extends StatelessWidget {
|
||||
child: Text(AppLocalizations.of(context)!.addplace)),
|
||||
ElevatedButton(onPressed: () => Navigator.pushNamed(context, '/viewCams'),
|
||||
child: Text(AppLocalizations.of(context)!.viewplaces)),
|
||||
|
||||
ElevatedButton(onPressed: () {}, child: Text(AppLocalizations.of(context)!.sendfile))
|
||||
],
|
||||
)),
|
||||
],
|
||||
|
||||
@@ -84,5 +84,7 @@
|
||||
"filelocation": "Ort der zuletzt gespeicherten Datei:",
|
||||
"open": "öffnen",
|
||||
"date": "Datum",
|
||||
"location": "Standort"
|
||||
"location": "Standort",
|
||||
"sendfile": "Datei zum Server schicken",
|
||||
"pickfile": "Datei auswählen"
|
||||
}
|
||||
@@ -407,6 +407,16 @@
|
||||
"location": "Location",
|
||||
"@location": {
|
||||
"description": "Location text"
|
||||
},
|
||||
|
||||
"sendfile": "Send file to server",
|
||||
"@sendfile": {
|
||||
"description": "Send file to server button"
|
||||
},
|
||||
|
||||
"pickfile": "Pick file",
|
||||
"@pickfile": {
|
||||
"description": "Pick file button"
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:fforte/addCam/add_cam_main.dart';
|
||||
import 'package:fforte/intro_screen.dart';
|
||||
import 'package:fforte/settings.dart';
|
||||
import 'package:fforte/other/intro_screen.dart';
|
||||
import 'package:fforte/other/settings.dart';
|
||||
import 'package:fforte/viewCam/view_cams.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flex_color_scheme/flex_color_scheme.dart';
|
||||
|
||||
71
lib/other/send_file.dart
Normal file
71
lib/other/send_file.dart
Normal file
@@ -0,0 +1,71 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'dart:io';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
class SendFile extends StatefulWidget {
|
||||
const SendFile({super.key});
|
||||
|
||||
@override
|
||||
State<SendFile> createState() => _SendFileState();
|
||||
}
|
||||
|
||||
class _SendFileState extends State<SendFile> {
|
||||
File? pickedFile;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Column(
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
FilePickerResult? result =
|
||||
await FilePicker.platform.pickFiles();
|
||||
|
||||
if (result != null) {
|
||||
pickedFile = File(result.files.single.path!);
|
||||
} else {
|
||||
pickedFile = File("");
|
||||
}
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.pickfile)),
|
||||
Text(pickedFile.toString()),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
final dio = Dio();
|
||||
final SharedPreferences prefs =
|
||||
await SharedPreferences.getInstance();
|
||||
String? fileContent = await pickedFile?.readAsString();
|
||||
|
||||
dio.options.responseType = ResponseType.plain;
|
||||
Response response = Response(
|
||||
requestOptions: RequestOptions(path: ''), statusCode: 400);
|
||||
|
||||
try {
|
||||
response = await dio.post(prefs.getString('apiAddress') ?? "",
|
||||
data: jsonEncode(fileContent));
|
||||
} on DioException catch (e) {
|
||||
if (e.response?.statusCode == 500) {
|
||||
/* print('-------------------------');
|
||||
print('code 500'); */
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (response.statusCode == 201) {
|
||||
// print(response.statusCode);
|
||||
} else {
|
||||
//print(response.statusCode);
|
||||
}
|
||||
},
|
||||
child: Text(AppLocalizations.of(context)!.sendtoserver))
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:fforte/addCam/add_cam_main.dart';
|
||||
import 'package:fforte/db_helper.dart';
|
||||
import 'package:fforte/other/db_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
import 'package:flutter_popup_card/flutter_popup_card.dart';
|
||||
|
||||
Reference in New Issue
Block a user