in frontend/frontend-flutter/lib/main.dart [1922:2357]
Container _buildStepper() {
final canCancel = currentStep > 0;
final canContinue = currentStep < 3;
StepState? stateStepperUploaded;
bool? isActiveUploaded;
StepState? stateStepperExtracted;
bool? isActiveExtracted;
StepState? stateStepperCompared;
bool? isActiveCompared;
StepState? stateStepperCommitted;
bool? isActiveCommitted;
StepState? stateStepperEnterQuestion;
bool? isActiveEnterQuestion;
String? messageStepperEnterQuestion = "";
StepState? stateStepperGenerateSQL;
bool? isActiveGenerateSQL;
String? messageStepperGenerateSQL = "";
StepState? stateStepperRunQuery;
bool? isActiveRunQuery;
String? messageStepperRunQuery = "";
StepState? stateStepperGetGraphDescription;
bool? isActiveGetGraphDescription;
String? messageStepperGraphDescription = "";
StepState? stateStepperGetTextSummary;
bool? isActiveGetTextSummary;
String? messageStepperGetTextSummary = "";
String? message = "";
void setStepsStates(UpdateStepperState state) {
print('Main : _buildStepper() : setStepsStates() : Start');
print(
'Main : _buildStepper() : setStepsStates() : status = ${state.status}');
print('Main : _buildStepper() : currentStep : $currentStep');
switch (state.status) {
case StepperStatus.initial:
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.initial');
currentStep = 0;
stateStepperEnterQuestion = StepState.disabled;
isActiveEnterQuestion = false;
stateStepperGenerateSQL = StepState.disabled;
isActiveGenerateSQL = false;
stateStepperRunQuery = StepState.disabled;
isActiveRunQuery = false;
stateStepperGetGraphDescription = StepState.disabled;
isActiveGetGraphDescription = false;
stateStepperGetTextSummary = StepState.disabled;
isActiveGetTextSummary = false;
message = state.message;
break;
case StepperStatus.enter_question:
stepperExpertInfoList.clear();
currentStep = 0;
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.enter_question');
stateStepperEnterQuestion = StepState.complete;
isActiveEnterQuestion = true;
stateStepperGenerateSQL = StepState.disabled;
isActiveGenerateSQL = false;
stateStepperRunQuery = StepState.disabled;
isActiveRunQuery = false;
stateStepperGetGraphDescription = StepState.disabled;
isActiveGetGraphDescription = false;
stateStepperGetTextSummary = StepState.disabled;
isActiveGetTextSummary = false;
messageStepperEnterQuestion = "Question entered in 0 s";
overallProcessingTime = 0;
stepperExpertInfoList.add(StepperExpertInfo());
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.enter_question : stepperExpertInfoList.length = ${stepperExpertInfoList.length}');
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.enter_question : stepperExpertInfoList = ${stepperExpertInfoList}');
break;
case StepperStatus.generate_sql:
currentStep = 1;
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.generate_sql');
stateStepperEnterQuestion = StepState.complete;
isActiveEnterQuestion = true;
stateStepperGenerateSQL = StepState.complete;
isActiveGenerateSQL = true;
stateStepperRunQuery = StepState.disabled;
isActiveRunQuery = false;
stateStepperGetGraphDescription = StepState.disabled;
isActiveGetGraphDescription = false;
stateStepperGetTextSummary = StepState.disabled;
isActiveGetTextSummary = false;
messageStepperGenerateSQL = state.message! +
" " +
((state.debugInfo.stepDuration!.toDouble()) / 1000).toString() +
" s";
overallProcessingTime = overallProcessingTime +
(state.debugInfo.stepDuration!.toDouble()) / 1000;
stepperExpertInfoList.add(state.debugInfo);
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.generate_sql : stepperExpertInfoList.length = ${stepperExpertInfoList.length}');
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.generate_sql : stepperExpertInfoList = ${stepperExpertInfoList}');
break;
case StepperStatus.run_query:
currentStep = 2;
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.run_query');
stateStepperEnterQuestion = StepState.complete;
isActiveEnterQuestion = true;
stateStepperGenerateSQL = StepState.complete;
isActiveGenerateSQL = true;
stateStepperRunQuery = StepState.complete;
isActiveRunQuery = true;
stateStepperGetGraphDescription = StepState.disabled;
isActiveGetGraphDescription = false;
stateStepperGetTextSummary = StepState.disabled;
isActiveGetTextSummary = false;
messageStepperRunQuery = state.message! +
" " +
((state.debugInfo.stepDuration!.toDouble()) / 1000).toString() +
" s";
overallProcessingTime = overallProcessingTime +
(state.debugInfo.stepDuration!.toDouble()) / 1000;
stepperExpertInfoList.add(state.debugInfo);
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.run_query : stepperExpertInfoList.length = ${stepperExpertInfoList.length}');
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.run_query : stepperExpertInfoList = ${stepperExpertInfoList}');
break;
case StepperStatus.get_graph_description:
currentStep = 3;
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.get_graph_description');
stateStepperEnterQuestion = StepState.complete;
isActiveEnterQuestion = true;
stateStepperGenerateSQL = StepState.complete;
isActiveGenerateSQL = true;
stateStepperRunQuery = StepState.complete;
isActiveRunQuery = true;
stateStepperGetGraphDescription = StepState.complete;
isActiveGetGraphDescription = true;
stateStepperGetTextSummary = StepState.disabled;
isActiveGetTextSummary = false;
messageStepperGraphDescription = state.message! +
" " +
((state.debugInfo.stepDuration!.toDouble()) / 1000).toString() +
" s";
overallProcessingTime = overallProcessingTime +
(state.debugInfo.stepDuration!.toDouble()) / 1000;
stepperExpertInfoList.add(state.debugInfo);
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.get_graph_description : stepperExpertInfoList.length = ${stepperExpertInfoList.length}');
print(
'Main : _buildStepper() : setStepsStates() : Switch: StepperStatus.get_graph_description : stepperExpertInfoList = ${stepperExpertInfoList}');
break;
default:
currentStep = 0;
stateStepperUploaded = StepState.disabled;
isActiveUploaded = false;
stateStepperExtracted = StepState.disabled;
isActiveExtracted = false;
stateStepperCompared = StepState.disabled;
isActiveCompared = false;
stateStepperCommitted = StepState.disabled;
isActiveCommitted = false;
message = state.message;
}
}
Future<void> _dialogRequestGenerated(
BuildContext context, StepperExpertInfo debugInfo, String title) {
print(
"Main: _dialogRequestGenerated() : title = $title : debugInfo.response = ${debugInfo.response}");
return showDialog<void>(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(title),
content: SingleChildScrollView(
child: Container(
width: screenSize!.width / 2,
child: Column(
children: [
_createDebugInfoCard(
Icon(Icons.link),
'URI POST',
'URI used in this step.',
'assets/images/https.png',
Text(
debugInfo.uri!,
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(fontSize: 16),
),
debugInfo.uri!),
_createDebugInfoCard(
//FaIcon(icon),
Icon(Icons.https),
'HTTPS Body',
'Json body of the request',
'assets/images/json.png',
Container(
child: JsonViewer(jsonDecode(debugInfo.body!))),
debugInfo.body!),
_createDebugInfoCard(
//FaIcon(icon),
Icon(Icons.https),
'HTTPS Headers',
'Headers sent in the HTTPS request.',
'assets/images/https_header.png',
Container(
child: JsonViewer(jsonDecode(debugInfo.header!))),
debugInfo.header!),
_createDebugInfoCard(
FaIcon(FontAwesomeIcons.reply),
'HTTPS Response',
'HTTPS body of the response',
'assets/images/json.png',
(!debugInfo.response!.contains('syntax error') && !debugInfo.response!.contains('SyntaxError') ) ?
Container(
child:
JsonViewer(jsonDecode(debugInfo.response!..replaceAll('"', '\\"')))) : Container(child: Text(debugInfo.response!)),
debugInfo.response!),
_createDebugInfoCard(
FaIcon(FontAwesomeIcons.code),
'Status Code',
'HTTPS answer status code',
'assets/images/status_code.png',
Text(
debugInfo.statusCode!.toString(),
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(fontSize: 16),
),
debugInfo.statusCode!.toString()),
_createDebugInfoCard(
Icon(Icons.timer),
'Processing Time',
'Step duration in seconds',
'assets/images/elapsed_time.png',
Text(
(debugInfo.stepDuration!.toDouble() / 1000)
.toString() +
" s",
style: Theme.of(context)
.textTheme
.bodyMedium!
.copyWith(fontSize: 16),
),
(debugInfo.stepDuration!.toDouble() / 1000)
.toString() +
" s"),
//Text("SQL request\n: ${debugInfo.generatedSQLText}"),
],
)),
), //Text(DicInfoExtractedMap.toString(),),
actions: <Widget>[
TextButton(
style: TextButton.styleFrom(
textStyle: Theme.of(context).textTheme.labelLarge,
),
child: const Text('Ok'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
return Container(
child: BlocBuilder<UpdateStepperCubit, UpdateStepperState>(
builder: (context, state) {
setStepsStates(state);
return Stepper(
controlsBuilder: (BuildContext context, ControlsDetails controls) {
return Container(); //to remove the continue and cancel buttons
},
type: StepperType.horizontal,
currentStep: currentStep,
onStepTapped: (int index) {
String title = "";
print(
'HomePage() : build() : Stepper : onStepTapped() : index = $index');
switch (index) {
case 0:
title = "";
break;
case 1:
title = "SQL Request Generation";
break;
case 2:
title = "Data Retrieval";
break;
case 3:
title = "Graph Description Retrieval";
break;
default:
title = "";
break;
}
print(
'HomePage() : build() : END : Stepper : onStepTapped() : index = $index');
print(
'HomePage() : build() : END : Stepper : onStepTapped() : TextToDocParameter.isTextTodocGlobal = ${TextToDocParameter.isTextTodocGlobal}');
print(
'HomePage() : build() : END : Stepper : onStepTapped() : stepperExpertInfoList.length = ${stepperExpertInfoList.length}');
//temporary knob to dispaly info about TextToDoc request/answer
if (TextToDocParameter.isTextTodocGlobal &&
index == 3 &&
stepperExpertInfoList.length == 2) {
print(
'HomePage() : build() : END : Stepper : onStepTapped() : if(TextToDocParameter.isTextTodocGlobal && index == 4 && stepperExpertInfoList.length == 2 ) = $index');
stepperExpertInfoList.insert(1, StepperExpertInfo());
stepperExpertInfoList.insert(1, StepperExpertInfo());
}
if (TextToDocParameter.isTextTodocGlobal && index < 3) {
return;
}
//end of temporary knob
_dialogRequestGenerated(
context, stepperExpertInfoList[index], title);
},
onStepContinue: () {},
onStepCancel: () {},
steps: [
Step(
title: Text("Question Typed",
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 18.0)),
subtitle: Text(messageStepperEnterQuestion!),
state: stateStepperEnterQuestion!, //stateStepperUploaded!,
isActive: isActiveEnterQuestion!, //isActiveUploaded!,
content: LimitedBox(
maxWidth: screenSize!.width, //100,
maxHeight: 40,
child: Container(
color: Colors.black12, //CupertinoColors.systemGrey,
child: Center(
child: Padding(
padding: const EdgeInsets.only(right: 8, left: 8),
child: Text(message!,
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 18.0,
color: stateStepperEnterQuestion! ==
StepState.complete
? Colors.green
: Colors.red)),
))),
),
),
Step(
title: Text("SQL Request Generated",
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 18.0)),
subtitle: Text(messageStepperGenerateSQL!),
state: stateStepperGenerateSQL!, //stateStepperExtracted!,
isActive: isActiveGenerateSQL!, //isActiveExtracted!,
content: LimitedBox(
maxWidth: screenSize!.width, //100,
maxHeight: 40,
child: Container(
color: Colors.black12,
child: Center(
child: Padding(
padding: const EdgeInsets.only(right: 8, left: 8),
child: Text(message!,
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 18.0,
color: Colors.green)),
),
)),
),
),
Step(
title: Text("Data Retrieved",
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 18.0)),
subtitle: Text(messageStepperRunQuery!),
state:
stateStepperRunQuery!, //StepState.disabled, //stateStepperCompared!,
isActive: isActiveRunQuery!, //isActiveCompared!,
content: LimitedBox(
maxWidth: screenSize!.width, //100,
maxHeight: 40,
child: Container(
color: Colors.black12,
child: Center(
child: Padding(
padding: const EdgeInsets.only(right: 8, left: 8),
child: Text(message!,
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 18.0,
color: Colors.green)),
))),
),
),
Step(
title: Text("Graph & Table Generated",
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 18.0)),
subtitle: Text(messageStepperGraphDescription!),
state:
stateStepperGetGraphDescription!, //StepState.disabled, //stateStepperCompared!,
isActive: isActiveGetGraphDescription!, //isActiveCompared!,
content: LimitedBox(
maxWidth: screenSize!.width, //100,
maxHeight: 40,
child: Container(
color: Colors.black12,
child: Center(
child: Padding(
padding: const EdgeInsets.only(right: 8, left: 8),
child: Text(
"The overall time to generate the natural language answer is ${double.parse(overallProcessingTime.toStringAsFixed(2))} s.",
style: TextStyle(
fontWeight: FontWeight.normal,
fontSize: 18.0,
color: Colors.green)),
))),
),
),
],
);
},
),
);
}