exportCurrentTest method
Attempts to export the current test via the testWriter
value. This will
return true
if and only if the current testWriter
both returns true
and no exceptions were thrown along the way.
If there is no name for the current test, this will prompt for a name to
submit with. Should the user cancel that name, this will abort, not call
the testWriter
and return a value of false
.
The clear
value instructs the controller to clear the current test on a
successful export or not.
Implementation
Future<bool> exportCurrentTest({
bool clear = true,
required BuildContext context,
}) async {
var save = true;
var exported = false;
final theme = Theme.of(context);
if (currentTest.name?.isNotEmpty != true) {
final translator = Translator.of(context);
String? name = '';
var suiteName = currentTest.suiteName ?? '';
name = await showDialog<String>(
context: context,
builder: (BuildContext context) => Theme(
data: theme,
child: AlertDialog(
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(null),
child: Text(
translator.translate(TestTranslations.atf_button_cancel),
),
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(name),
child: Text(
translator.translate(TestTranslations.atf_button_submit),
),
),
],
content: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
TextFormField(
autocorrect: false,
autofocus: true,
autovalidateMode: AutovalidateMode.always,
decoration: InputDecoration(
labelText: translator.translate(
TestTranslations.atf_test_name,
),
),
initialValue: name,
onChanged: (value) => name = value,
validator: (value) =>
Validator(validators: [RequiredValidator()]).validate(
context: context,
label: translator.translate(
TestTranslations.atf_test_name,
),
value: value,
),
),
const SizedBox(
height: 16.0,
),
TextFormField(
autocorrect: false,
autofocus: false,
decoration: InputDecoration(
labelText: translator.translate(
TestTranslations.atf_suite_name,
),
),
initialValue: suiteName,
onChanged: (value) => suiteName = value,
),
],
),
title: Text(translator.translate(TestTranslations.atf_test_name)),
),
),
);
if (name?.isNotEmpty == true) {
save = true;
currentTest = currentTest.copyWith(
name: name,
suiteName: suiteName.isNotEmpty == true ? suiteName : null,
);
selectedSuiteName = suiteName;
} else {
save = false;
}
}
if (save == true) {
exported = await _testWriter(context, currentTest);
if (exported == true && clear == true) {
currentTest = Test();
}
}
return exported;
}