Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: symbol bar #1317

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
328 changes: 194 additions & 134 deletions mobile-app/lib/ui/views/learn/challenge/challenge_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class ChallengeView extends StatelessWidget {
);

model.initiateFile(editor, challenge, currFile, editableRegion);
model.listenToFocusedController(editor);

SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
if (keyboard && !model.showPanel) {
Expand All @@ -116,6 +117,7 @@ class ChallengeView extends StatelessWidget {
}
}
});

editor.onTextChange.stream.listen((text) {
model.fileService.saveFileInCache(
challenge,
Expand Down Expand Up @@ -356,158 +358,216 @@ class ChallengeView extends StatelessWidget {
BuildContext context,
) {
return BottomAppBar(
height: 116,
padding: const EdgeInsets.only(bottom: 8),
color: const Color(0xFF0a0a23),
child: Row(
child: Column(
children: [
SizedBox(
width: 1,
height: 1,
child: InAppWebView(
onWebViewCreated: (controller) {
model.setTestController = controller;
},
onConsoleMessage: (controller, console) {
model.handleConsoleLogMessagges(console, challenge);
},
),
SymbolBar(
model: model,
editor: editor,
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 8),
color: model.showPanel && model.panelType == PanelType.instruction
? Colors.white
: const Color.fromRGBO(0x3B, 0x3B, 0x4F, 1),
child: IconButton(
icon: Icon(
Icons.info_outline_rounded,
size: 32,
Row(
children: [
SizedBox(
width: 1,
height: 1,
child: InAppWebView(
onWebViewCreated: (controller) {
model.setTestController = controller;
},
onConsoleMessage: (controller, console) {
model.handleConsoleLogMessagges(console, challenge);
},
),
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 8),
color:
model.showPanel && model.panelType == PanelType.instruction
? Colors.white
: const Color.fromRGBO(0x3B, 0x3B, 0x4F, 1),
child: IconButton(
icon: Icon(
Icons.info_outline_rounded,
size: 32,
color: model.showPanel &&
model.panelType == PanelType.instruction
? const Color.fromRGBO(0x3B, 0x3B, 0x4F, 1)
: Colors.white,
),
onPressed: () {
if (model.showPanel &&
model.panelType != PanelType.instruction) {
model.setPanelType = PanelType.instruction;
} else {
model.setPanelType = PanelType.instruction;
if (MediaQuery.of(context).viewInsets.bottom > 0) {
FocusManager.instance.primaryFocus?.unfocus();
if (!model.showPanel) {
model.setShowPanel = true;
model.setHideAppBar = true;
),
onPressed: () {
if (model.showPanel &&
model.panelType != PanelType.instruction) {
model.setPanelType = PanelType.instruction;
} else {
model.setPanelType = PanelType.instruction;
if (MediaQuery.of(context).viewInsets.bottom > 0) {
FocusManager.instance.primaryFocus?.unfocus();
if (!model.showPanel) {
model.setShowPanel = true;
model.setHideAppBar = true;
}
} else {
model.setHideAppBar = !model.hideAppBar;
model.setShowPanel = !model.showPanel;
}
}
} else {
model.setHideAppBar = !model.hideAppBar;
model.setShowPanel = !model.showPanel;
}
}
},
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 8),
color: !model.showPreview
? const Color.fromRGBO(0x3B, 0x3B, 0x4F, 1)
: Colors.white,
child: IconButton(
icon: Icon(
Icons.remove_red_eye_outlined,
size: 32,
color: model.showPreview
},
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
),
Container(
margin: const EdgeInsets.symmetric(horizontal: 8),
color: !model.showPreview
? const Color.fromRGBO(0x3B, 0x3B, 0x4F, 1)
: Colors.white,
child: IconButton(
icon: Icon(
Icons.remove_red_eye_outlined,
size: 32,
color: model.showPreview
? const Color.fromRGBO(0x3B, 0x3B, 0x4F, 1)
: Colors.white,
),
onPressed: () async {
ChallengeFile currFile = model.currentFile(challenge);

String currText =
await model.fileService.getExactFileFromCache(
challenge,
currFile,
);

model.setMounted = false;

editor.fileTextStream.sink.add(FileIDE(
id: challenge.id + currFile.name,
ext: currFile.ext.name.toUpperCase(),
name: currFile.name,
content: currText == '' ? currFile.contents : currText,
hasRegion: currFile.editableRegionBoundaries.isNotEmpty,
region: EditorRegionOptions(
start: currFile.editableRegionBoundaries.isNotEmpty
? currFile.editableRegionBoundaries[0]
: null,
end: currFile.editableRegionBoundaries.isNotEmpty
? currFile.editableRegionBoundaries[1]
: null,
),
));
model.setEditorText =
currText == '' ? currFile.contents : currText;
model.setShowPreview = !model.showPreview;

if (!model.showProjectPreview && !model.showConsole) {
model.setShowProjectPreview = true;
}

model.refresh();
},
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
),
onPressed: () async {
ChallengeFile currFile = model.currentFile(challenge);
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
margin: const EdgeInsets.symmetric(horizontal: 8),
color: !model.hasTypedInEditor
? const Color.fromARGB(255, 9, 79, 125)
: model.completedChallenge
? const Color.fromRGBO(0x20, 0xD0, 0x32, 1)
: const Color.fromRGBO(0x1D, 0x9B, 0xF0, 1),
child: IconButton(
icon: model.runningTests
? const CircularProgressIndicator()
: model.completedChallenge
? const Icon(Icons.arrow_forward_rounded,
size: 30)
: const Icon(Icons.done_rounded, size: 30),
onPressed: model.hasTypedInEditor
? () async {
model.setAfterFirstTest = false;
model.setConsoleMessages = [];
model.setUserConsoleMessages = [];
if (model.showPanel &&
model.panelType == PanelType.pass) {
model.learnService.goToNextChallenge(
model.block!.challenges.length,
challengesCompleted,
challenge,
block,
);
}

String currText = await model.fileService.getExactFileFromCache(
challenge,
currFile,
);
model.setShowPanel = false;
model.setIsRunningTests = true;
await model.runner.setWebViewContent(
challenge,
controller: model.testController!,
);
FocusManager.instance.primaryFocus?.unfocus();
}
: null,
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
),
],
),
),
],
),
],
),
);
}
}

model.setMounted = false;

editor.fileTextStream.sink.add(FileIDE(
id: challenge.id + currFile.name,
ext: currFile.ext.name.toUpperCase(),
name: currFile.name,
content: currText == '' ? currFile.contents : currText,
hasRegion: currFile.editableRegionBoundaries.isNotEmpty,
region: EditorRegionOptions(
start: currFile.editableRegionBoundaries.isNotEmpty
? currFile.editableRegionBoundaries[0]
: null,
end: currFile.editableRegionBoundaries.isNotEmpty
? currFile.editableRegionBoundaries[1]
: null,
),
));
model.setEditorText =
currText == '' ? currFile.contents : currText;
model.setShowPreview = !model.showPreview;
class SymbolBar extends StatelessWidget {
const SymbolBar({
super.key,
required this.editor,
required this.model,
});

if (!model.showProjectPreview && !model.showConsole) {
model.setShowProjectPreview = true;
}
final Editor editor;
final ChallengeViewModel model;

model.refresh();
},
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
static List<String> symbols = ['<', '/', '>', '\\', '\'', '"', '='];

@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.only(bottom: 8),
height: 50,
color: const Color(0xFF1b1b32),
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: symbols.length,
itemBuilder: (context, index) {
return Padding(
padding: const EdgeInsets.symmetric(
vertical: 4,
horizontal: 1,
),
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
Container(
margin: const EdgeInsets.symmetric(horizontal: 8),
color: !model.hasTypedInEditor
? const Color.fromARGB(255, 9, 79, 125)
: model.completedChallenge
? const Color.fromRGBO(0x20, 0xD0, 0x32, 1)
: const Color.fromRGBO(0x1D, 0x9B, 0xF0, 1),
child: IconButton(
icon: model.runningTests
? const CircularProgressIndicator()
: model.completedChallenge
? const Icon(Icons.arrow_forward_rounded, size: 30)
: const Icon(Icons.done_rounded, size: 30),
onPressed: model.hasTypedInEditor
? () async {
model.setAfterFirstTest = false;
model.setConsoleMessages = [];
model.setUserConsoleMessages = [];
if (model.showPanel &&
model.panelType == PanelType.pass) {
model.learnService.goToNextChallenge(
model.block!.challenges.length,
challengesCompleted,
challenge,
block,
);
}

model.setShowPanel = false;
model.setIsRunningTests = true;
await model.runner.setWebViewContent(
challenge,
controller: model.testController!,
);
FocusManager.instance.primaryFocus?.unfocus();
}
: null,
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
),
child: TextButton(
onPressed: () {
model.insertSymbol(symbols[index], editor);
},
style: TextButton.styleFrom(
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.zero),
),
],
),
child: Text(symbols[index]),
),
),
],
);
},
),
);
}
Expand Down
Loading
Loading