besprechung

This commit is contained in:
Nico
2025-06-06 19:46:29 +02:00
parent 7d85090d4e
commit ccf1643711
13 changed files with 256 additions and 210 deletions

View File

@@ -1,69 +1,80 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:fforte/l10n/app_localizations.dart';
import 'package:fforte/screens/sharedMethods/http_request.dart';
import 'package:file_picker/file_picker.dart';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SendFile extends StatefulWidget {
const SendFile({super.key});
class SendFile {
static Future<void> sendFile() async {
File? pickedFile;
@override
State<SendFile> createState() => _SendFileState();
}
FilePickerResult? result = await FilePicker.platform.pickFiles();
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))
],
),
);
if (result != null) {
pickedFile = File(result.files.single.path!);
String fileContent = await pickedFile.readAsString();
await HttpRequestService.httpRequest(saveDataString: fileContent);
}
}
}
// 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))
// ],
// ),
// );
// }
// }