Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Platypus - appBar
class HomeScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Consumer<HomeProvider>(
builder: (_, homeProvider, __) => Scaffold(
appBar: AppBar(
// reset-button
leading: IconButton(
onPressed: () {
homeProvider.codeTextEditingController.text = '';
homeProvider.codeHighlightTheme = themeMap.keys.first;
homeProvider.codeProgrammingLanguage =
programmingLanguages.keys.first;
homeProvider.codeBackgroundColor = Colors.white;
homeProvider.isPreview = false;
homeProvider.windowThreeCirclesStyle =
WindowThreeCirclesStyle.Filled.toString();
homeProvider.windowThreeCirclesPosition = 'Left';
homeProvider.verticalPaddingBetweenCodeAndBackground = 20;
homeProvider.horizontalPaddingBetweenCodeAndBackground = 20;
homeProvider.codeFontSize = 16;
homeProvider.codeLineHeight = 0;
homeProvider.showShadow = false;
},
icon: Icon(Icons.refresh),
tooltip: 'Reset',
),
title: Text('Platypus'),
centerTitle: true,
actions: <Widget>[
// share icon to either share screenshot or export config
homeProvider.isPreview
? IconButton(
icon: Icon(Icons.share),
onPressed: () async {
homeProvider.screenshotMode = true;
final screenshot = await homeProvider
.codeScreenshotController
.capture(pixelRatio: window.devicePixelRatio);
final downloadPath =
await getApplicationDocumentsDirectory();
final fileName = DateTime.now().toString();
final fileToSave = await screenshot.readAsBytes();
final savedScreenshot =
await File('${downloadPath.path}/$fileName.png')
.writeAsBytes(fileToSave);
await showDialog(
context: context,
builder: (builder) => AlertDialog(
title: Text('Code Screenshot'),
content: Container(
child: Image.file(screenshot),
),
actions: <Widget>[
FlatButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Cancel'),
),
FlatButton(
onPressed: () async {
final generatedConfigFile =
await exportCurrentPlatypusConfig(
homeProvider);
await ShareExtend.share(
generatedConfigFile.path, 'file');
},
child: Text('Export Config'),
),
FlatButton(
onPressed: () async {
await ShareExtend.share(
savedScreenshot.path, 'file');
},
child: Text('Share'),
),
],
),
);
homeProvider.screenshotMode = false;
},
)
: Container(),
// toggle between edit/preview mode
homeProvider.isPreview
? IconButton(
tooltip: 'Switch to Editor',
onPressed: () {
homeProvider.isPreview = !homeProvider.isPreview;
},
icon: Icon(Icons.edit),
)
: IconButton(
tooltip: 'Switch to Preview',
onPressed: () {
homeProvider.isPreview = !homeProvider.isPreview;
},
icon: Icon(Icons.remove_red_eye),
),
// import existing style config JSON file from the local device
IconButton(
onPressed: () async {
final importConfigFile = await FilePicker.getFile();
if (importConfigFile != null) {
final config = await importConfigFile.readAsString();
final importedConfig = jsonDecode(config);
homeProvider.horizontalPaddingBetweenCodeAndBackground =
importedConfig['horizontal_padding'];
homeProvider.verticalPaddingBetweenCodeAndBackground =
importedConfig['vertical_padding'];
homeProvider.codeFontSize = importedConfig['font_size'];
homeProvider.codeLineHeight = importedConfig['line_height'];
homeProvider.windowThreeCirclesStyle =
importedConfig['window_circles_style'];
homeProvider.windowThreeCirclesPosition =
importedConfig['window_circles_position'];
homeProvider.showShadow = importedConfig['show_shadow'];
homeProvider.codeHighlightTheme =
importedConfig['highlight_theme'];
homeProvider.codeProgrammingLanguage =
importedConfig['programming_language'];
homeProvider.codeTextEditingController.text =
importedConfig['source_code'];
homeProvider.isPreview = true;
homeProvider.codeBackgroundColor =
Color(importedConfig['background_color']);
}
},
icon: Icon(Icons.attach_file),
),
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.