Save the data for use in another testcase use flutter gherkin

a dhiyaul asikin
1 min readFeb 8, 2021

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 File

Future<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();

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

a dhiyaul asikin
a dhiyaul asikin

No responses yet

Write a response