improve ITStep Transitions
This commit is contained in:
parent
629b5e48e3
commit
fdbbd0e603
2 changed files with 180 additions and 58 deletions
|
|
@ -28,6 +28,7 @@ class ITController {
|
||||||
String? sourceText;
|
String? sourceText;
|
||||||
List<ITStep> completedITSteps = [];
|
List<ITStep> completedITSteps = [];
|
||||||
CurrentITStep? currentITStep;
|
CurrentITStep? currentITStep;
|
||||||
|
CurrentITStep? nextITStep;
|
||||||
GoldRouteTracker goldRouteTracker = GoldRouteTracker.defaultTracker;
|
GoldRouteTracker goldRouteTracker = GoldRouteTracker.defaultTracker;
|
||||||
List<int> payLoadIds = [];
|
List<int> payLoadIds = [];
|
||||||
|
|
||||||
|
|
@ -42,6 +43,7 @@ class ITController {
|
||||||
sourceText = null;
|
sourceText = null;
|
||||||
completedITSteps = [];
|
completedITSteps = [];
|
||||||
currentITStep = null;
|
currentITStep = null;
|
||||||
|
nextITStep = null;
|
||||||
goldRouteTracker = GoldRouteTracker.defaultTracker;
|
goldRouteTracker = GoldRouteTracker.defaultTracker;
|
||||||
payLoadIds = [];
|
payLoadIds = [];
|
||||||
|
|
||||||
|
|
@ -130,36 +132,75 @@ class ITController {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentITStep = null;
|
if (nextITStep == null) {
|
||||||
|
currentITStep = null;
|
||||||
|
|
||||||
final ITResponseModel res = await _customInputTranslation(currentText);
|
final ITResponseModel res = await _customInputTranslation(currentText);
|
||||||
// final ITResponseModel res = await (useCustomInput ||
|
// final ITResponseModel res = await (useCustomInput ||
|
||||||
// currentText.isEmpty ||
|
// currentText.isEmpty ||
|
||||||
// translationId == null ||
|
// translationId == null ||
|
||||||
// completedITSteps.last.chosenContinuance?.indexSavedByServer ==
|
// completedITSteps.last.chosenContinuance?.indexSavedByServer ==
|
||||||
// null
|
// null
|
||||||
// ? _customInputTranslation(currentText)
|
// ? _customInputTranslation(currentText)
|
||||||
// : _systemChoiceTranslation(translationId));
|
// : _systemChoiceTranslation(translationId));
|
||||||
|
|
||||||
if (res.goldContinuances != null && res.goldContinuances!.isNotEmpty) {
|
if (res.goldContinuances != null && res.goldContinuances!.isNotEmpty) {
|
||||||
goldRouteTracker = GoldRouteTracker(
|
goldRouteTracker = GoldRouteTracker(
|
||||||
res.goldContinuances!,
|
res.goldContinuances!,
|
||||||
sourceText!,
|
sourceText!,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentITStep = CurrentITStep(
|
||||||
|
sourceText: sourceText!,
|
||||||
|
currentText: currentText,
|
||||||
|
responseModel: res,
|
||||||
|
storedGoldContinuances: goldRouteTracker.continuances,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
_addPayloadId(res);
|
||||||
|
} else {
|
||||||
|
currentITStep = nextITStep;
|
||||||
|
nextITStep = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
currentITStep = CurrentITStep(
|
|
||||||
sourceText: sourceText!,
|
|
||||||
currentText: currentText,
|
|
||||||
responseModel: res,
|
|
||||||
storedGoldContinuances: goldRouteTracker.continuances,
|
|
||||||
);
|
|
||||||
|
|
||||||
_addPayloadId(res);
|
|
||||||
|
|
||||||
if (isTranslationDone) {
|
if (isTranslationDone) {
|
||||||
choreographer.altTranslator.setTranslationFeedback();
|
choreographer.altTranslator.setTranslationFeedback();
|
||||||
choreographer.getLanguageHelp(true);
|
choreographer.getLanguageHelp(true);
|
||||||
|
} else {
|
||||||
|
getNextTranslationData();
|
||||||
|
}
|
||||||
|
} catch (e, s) {
|
||||||
|
debugger(when: kDebugMode);
|
||||||
|
if (e is! http.Response) {
|
||||||
|
ErrorHandler.logError(e: e, s: s);
|
||||||
|
}
|
||||||
|
choreographer.errorService.setErrorAndLock(
|
||||||
|
ChoreoError(type: ChoreoErrorType.unknown, raw: e),
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
choreographer.stopLoading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void>getNextTranslationData() async {
|
||||||
|
try {
|
||||||
|
if (completedITSteps.length < goldRouteTracker.continuances.length) {
|
||||||
|
final String currentText = choreographer.currentText;
|
||||||
|
final String nextText =
|
||||||
|
goldRouteTracker.continuances[completedITSteps.length].text;
|
||||||
|
|
||||||
|
final ITResponseModel res =
|
||||||
|
await _customInputTranslation(currentText + nextText);
|
||||||
|
|
||||||
|
nextITStep = CurrentITStep(
|
||||||
|
sourceText: sourceText!,
|
||||||
|
currentText: nextText,
|
||||||
|
responseModel: res,
|
||||||
|
storedGoldContinuances: goldRouteTracker.continuances,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
nextITStep = null;
|
||||||
}
|
}
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
debugger(when: kDebugMode);
|
debugger(when: kDebugMode);
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:developer';
|
import 'dart:developer';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
@ -86,45 +87,48 @@ class ChoiceItem extends StatelessWidget {
|
||||||
waitDuration: onLongPress != null
|
waitDuration: onLongPress != null
|
||||||
? const Duration(milliseconds: 500)
|
? const Duration(milliseconds: 500)
|
||||||
: const Duration(days: 1),
|
: const Duration(days: 1),
|
||||||
child: Container(
|
child: SelectiveRotatingWidget(
|
||||||
margin: const EdgeInsets.all(2),
|
selected: entry.value.color != null,
|
||||||
padding: EdgeInsets.zero,
|
child: Container(
|
||||||
decoration: isSelected
|
margin: const EdgeInsets.all(2),
|
||||||
? BoxDecoration(
|
padding: EdgeInsets.zero,
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
decoration: isSelected
|
||||||
border: Border.all(
|
? BoxDecoration(
|
||||||
color: entry.value.color ?? theme.colorScheme.primary,
|
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||||
style: BorderStyle.solid,
|
border: Border.all(
|
||||||
width: 2.0,
|
color: entry.value.color ?? theme.colorScheme.primary,
|
||||||
|
style: BorderStyle.solid,
|
||||||
|
width: 2.0,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
child: TextButton(
|
||||||
|
style: ButtonStyle(
|
||||||
|
padding: MaterialStateProperty.all(
|
||||||
|
const EdgeInsets.symmetric(horizontal: 7),
|
||||||
|
),
|
||||||
|
//if index is selected, then give the background a slight primary color
|
||||||
|
backgroundColor: MaterialStateProperty.all<Color>(
|
||||||
|
entry.value.color != null
|
||||||
|
? entry.value.color!.withOpacity(0.2)
|
||||||
|
: theme.colorScheme.primary.withOpacity(0.1),
|
||||||
|
),
|
||||||
|
textStyle: MaterialStateProperty.all(
|
||||||
|
BotStyle.text(context),
|
||||||
|
),
|
||||||
|
shape: MaterialStateProperty.all(
|
||||||
|
RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
)
|
|
||||||
: null,
|
|
||||||
child: TextButton(
|
|
||||||
style: ButtonStyle(
|
|
||||||
padding: MaterialStateProperty.all(
|
|
||||||
const EdgeInsets.symmetric(horizontal: 7),
|
|
||||||
),
|
|
||||||
//if index is selected, then give the background a slight primary color
|
|
||||||
backgroundColor: MaterialStateProperty.all<Color>(
|
|
||||||
entry.value.color != null
|
|
||||||
? entry.value.color!.withOpacity(0.2)
|
|
||||||
: theme.colorScheme.primary.withOpacity(0.1),
|
|
||||||
),
|
|
||||||
textStyle: MaterialStateProperty.all(
|
|
||||||
BotStyle.text(context),
|
|
||||||
),
|
|
||||||
shape: MaterialStateProperty.all(
|
|
||||||
RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
onLongPress:
|
||||||
onLongPress:
|
onLongPress != null ? () => onLongPress!(entry.key) : null,
|
||||||
onLongPress != null ? () => onLongPress!(entry.key) : null,
|
onPressed: () => onPressed(entry.key),
|
||||||
onPressed: () => onPressed(entry.key),
|
child: Text(
|
||||||
child: Text(
|
entry.value.text,
|
||||||
entry.value.text,
|
style: BotStyle.text(context),
|
||||||
style: BotStyle.text(context),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
@ -135,3 +139,80 @@ class ChoiceItem extends StatelessWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SelectiveRotatingWidget extends StatefulWidget {
|
||||||
|
final Widget child;
|
||||||
|
final bool selected;
|
||||||
|
|
||||||
|
const SelectiveRotatingWidget({super.key, required this.child, required this.selected});
|
||||||
|
|
||||||
|
@override
|
||||||
|
SelectiveRotatingWidgetState createState() => SelectiveRotatingWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class SelectiveRotatingWidgetState extends State<SelectiveRotatingWidget> with SingleTickerProviderStateMixin {
|
||||||
|
late final AnimationController _controller;
|
||||||
|
late final Animation<double> _animation;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
_controller = AnimationController(
|
||||||
|
duration: const Duration(milliseconds: 300),
|
||||||
|
vsync: this,
|
||||||
|
);
|
||||||
|
|
||||||
|
_animation = TweenSequence<double>([
|
||||||
|
TweenSequenceItem<double>(
|
||||||
|
tween: Tween<double>(begin: 0, end: -8 * pi / 180),
|
||||||
|
weight: 1.0,
|
||||||
|
),
|
||||||
|
TweenSequenceItem<double>(
|
||||||
|
tween: Tween<double>(begin: -8 * pi / 180, end: 16 * pi / 180),
|
||||||
|
weight: 2.0,
|
||||||
|
),
|
||||||
|
TweenSequenceItem<double>(
|
||||||
|
tween: Tween<double>(begin: 16 * pi / 180, end: 0),
|
||||||
|
weight: 1.0,
|
||||||
|
),
|
||||||
|
]).animate(_controller);
|
||||||
|
|
||||||
|
if (widget.selected) {
|
||||||
|
_controller.repeat(reverse: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(SelectiveRotatingWidget oldWidget) {
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
if (widget.selected != oldWidget.selected) {
|
||||||
|
if (widget.selected) {
|
||||||
|
_controller.repeat(reverse: true);
|
||||||
|
} else {
|
||||||
|
_controller.stop();
|
||||||
|
_controller.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AnimatedBuilder(
|
||||||
|
animation: _animation,
|
||||||
|
builder: (context, child) {
|
||||||
|
return Transform.rotate(
|
||||||
|
angle: _animation.value,
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: widget.child,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue