Save the data for use in another testcase use flutter gherkin
To save files to disk, combine the path_provider
plugin with the dart:io
library.
Create function to save datafile :
import ‘dart:async’;
import ‘dart:io’;
// import ‘package:path_provider/path_provider.dart’;class CounterStorage {
//Save to data local hp
// Future<String> get _localPath async {
// final directory = await getApplicationDocumentsDirectory();
// return directory.path;
// }
// name FileFuture<File> get _localFile async {
// final path = await _localPath;
return await File(Directory.current.path+’/filetext/nameproduct.txt’).create(recursive: true);
}// Write text to file
Future<File> writeCounter(String text) async {
final file = await _localFile;
// Write the file
return file.writeAsString(‘$text’);
}//Read File
Future<String> readCounter() async {
try {
final file = await _localFile;
// Read the file
String contents = await file.readAsString();
return contents;
} catch (e) {
// If encountering an error, return 0
return ‘’;
}
}
}
Then, after that create in test case :
import ‘location_path_function_savedatafile.dart’
CounterStorage counterStorage = CounterStorage();
counterStorage.writeCounter(‘Ayam nelongso’);
String read = await counterStorage.readCounter();