170 lines
5.1 KiB
Dart
170 lines
5.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
import 'package:testing/src/esp_log.dart';
|
|
import 'package:testing/testing_code.dart';
|
|
import 'package:file_picker/file_picker.dart';
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
const HomeScreen({super.key});
|
|
|
|
@override
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
String output = '';
|
|
final TextEditingController _controller = TextEditingController();
|
|
final ScrollController _scrollController = ScrollController();
|
|
String jsonFilePath = '';
|
|
String fsqFilePath = '';
|
|
Future<void> pickJsonFile() async {
|
|
final result = await FilePicker.platform.pickFiles(
|
|
type: FileType.custom,
|
|
allowedExtensions: ['json'],
|
|
);
|
|
|
|
if (result != null && result.files.single.path != null) {
|
|
jsonFilePath = result.files.single.path!;
|
|
Logger.log("JSON file selected: $jsonFilePath");
|
|
} else {
|
|
Logger.log("JSON file not selected");
|
|
}
|
|
}
|
|
|
|
Future<void> pickFsqFile() async {
|
|
final result = await FilePicker.platform.pickFiles(
|
|
type: FileType.custom,
|
|
allowedExtensions: ['fsq'],
|
|
);
|
|
|
|
if (result != null && result.files.single.path != null) {
|
|
fsqFilePath = result.files.single.path!;
|
|
Logger.log("FSQ file selected: $fsqFilePath");
|
|
} else {
|
|
Logger.log("FSQ file not selected");
|
|
}
|
|
}
|
|
|
|
Future<void> requestStoragePermission() async {
|
|
final status = await Permission.storage.request();
|
|
if (status.isGranted) {
|
|
Logger.log(" Storage permission granted");
|
|
} else if (status.isDenied) {
|
|
Logger.log(" Storage permission denied");
|
|
} else if (status.isPermanentlyDenied) {
|
|
Logger.log(
|
|
" Storage permission permanently denied. Please enable it from settings.",
|
|
);
|
|
openAppSettings();
|
|
}
|
|
}
|
|
|
|
final String jsonFileName = 'json1.json';
|
|
final String fsqFileName = 'Greaves_Bosch_BS6_2.fsq';
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
requestStoragePermission();
|
|
Logger.uiLogger = (msg) {
|
|
setState(() {
|
|
output += '$msg\n';
|
|
});
|
|
Future.delayed(Duration(milliseconds: 100), () {
|
|
if (_scrollController.hasClients) {
|
|
_scrollController.jumpTo(_scrollController.position.maxScrollExtent);
|
|
}
|
|
});
|
|
};
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_controller.dispose();
|
|
_scrollController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(title: Text('Home Screen')),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(16.0),
|
|
child: Column(
|
|
children: [
|
|
// TextField(
|
|
// controller: _controller,
|
|
// onSubmitted: (v) {
|
|
// waitForSimulatedECUResponse(
|
|
// simulatedEcuResponse: v
|
|
// .replaceAll(" ", "")
|
|
// .toUpperCase()
|
|
// .trim(),
|
|
// );
|
|
// },
|
|
// decoration: InputDecoration(
|
|
// labelText: 'Enter command',
|
|
// border: OutlineInputBorder(),
|
|
// ),
|
|
// ),
|
|
// SizedBox(height: 20),
|
|
Wrap(
|
|
spacing: 10,
|
|
runSpacing: 10,
|
|
children: [
|
|
ElevatedButton(
|
|
onPressed: pickJsonFile,
|
|
child: const Text('Pick JSON File'),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: pickFsqFile,
|
|
child: const Text('Pick FSQ File'),
|
|
),
|
|
ElevatedButton(
|
|
onPressed: () async {
|
|
await start(jsonFilePath, fsqFilePath);
|
|
},
|
|
child: const Text('Start'),
|
|
),
|
|
// ElevatedButton(
|
|
// onPressed: () async {
|
|
// await waitForSimulatedECUResponse();
|
|
// },
|
|
// child: const Text('Send 7E00'),
|
|
// ),
|
|
],
|
|
),
|
|
SizedBox(height: 20),
|
|
Expanded(
|
|
child: Container(
|
|
width: double.infinity,
|
|
decoration: BoxDecoration(
|
|
color: Colors.black,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
padding: const EdgeInsets.all(8),
|
|
child: Scrollbar(
|
|
controller: _scrollController,
|
|
thumbVisibility: true,
|
|
child: SingleChildScrollView(
|
|
controller: _scrollController,
|
|
child: SelectableText(
|
|
output,
|
|
style: const TextStyle(
|
|
color: Colors.greenAccent,
|
|
fontFamily: 'Courier',
|
|
fontSize: 14,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|