Moved buttons from list to formula.
This commit is contained in:
parent
8a42d53c77
commit
2400554259
4 changed files with 68 additions and 51 deletions
|
|
@ -156,41 +156,7 @@ class _FormulaListState extends State<FormulaList> {
|
||||||
trailing: Row(
|
trailing: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
PopupMenuButton(
|
// TOTHINK: Add buttons here, but I don't know which ones
|
||||||
icon: const Icon(Icons.share),
|
|
||||||
tooltip: 'Share or copy to clipboard',
|
|
||||||
onSelected: (value) {
|
|
||||||
if (value == 'share') {
|
|
||||||
FormulaList.shareFormula(formula);
|
|
||||||
} else if (value == 'copy') {
|
|
||||||
FormulaList.copyFormula(context, formula);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
itemBuilder: (context) => [
|
|
||||||
PopupMenuItem(
|
|
||||||
value: 'share',
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.share, size: 20),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Flexible(child: Text('Share', softWrap: false)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
PopupMenuItem(
|
|
||||||
value: 'copy',
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.copy, size: 20),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Flexible(child: Text('Copy to clipboard', softWrap: false)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
// dart
|
// dart
|
||||||
|
import 'package:d4rt_formulas/database/database_service.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_markdown_plus_latex/flutter_markdown_plus_latex.dart';
|
import 'package:flutter_markdown_plus_latex/flutter_markdown_plus_latex.dart';
|
||||||
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
|
import 'package:flutter_markdown_plus/flutter_markdown_plus.dart';
|
||||||
|
|
@ -7,6 +8,7 @@ import '../formula_models.dart';
|
||||||
import '../formula_evaluator.dart';
|
import '../formula_evaluator.dart';
|
||||||
import '../corpus.dart';
|
import '../corpus.dart';
|
||||||
import '../error_handler.dart';
|
import '../error_handler.dart';
|
||||||
|
import '../service_locator.dart';
|
||||||
import '../value_formatter.dart';
|
import '../value_formatter.dart';
|
||||||
import 'd4rt_editing_controller.dart';
|
import 'd4rt_editing_controller.dart';
|
||||||
import 'formula_list.dart';
|
import 'formula_list.dart';
|
||||||
|
|
@ -194,28 +196,69 @@ class _FormulaScreenState extends State<FormulaScreen> {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.delete_forever),
|
||||||
|
onPressed: () {
|
||||||
|
print( "Borrando");
|
||||||
|
showAlertDialog(BuildContext context) {
|
||||||
|
// set up the buttons
|
||||||
|
Widget cancelButton = TextButton(
|
||||||
|
child: Text("Cancel"),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
Widget deleteButton = TextButton(
|
||||||
|
child: Text("Delete"),
|
||||||
|
onPressed: () {
|
||||||
|
widget.corpus.forgetFormula(formula.originalFormula);
|
||||||
|
getDatabase().deleteFormula(formula.originalFormula.uuid);
|
||||||
|
Navigator.of(context)
|
||||||
|
..pop()..pop();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// set up the AlertDialog
|
||||||
|
AlertDialog alert = AlertDialog(
|
||||||
|
title: Text("Delete Formula"),
|
||||||
|
content: Text("Please confirm deletion of formula ${formula.name}"),
|
||||||
|
actions: [
|
||||||
|
cancelButton,
|
||||||
|
deleteButton,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
// show the dialog
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: showAlertDialog
|
||||||
|
);
|
||||||
|
},
|
||||||
|
tooltip: "Delete formula"
|
||||||
|
),
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.edit),
|
icon: const Icon(Icons.edit),
|
||||||
onPressed: formula is DerivedFormula
|
onPressed: formula is DerivedFormula
|
||||||
? null
|
? null
|
||||||
: () {
|
: () {
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) =>
|
builder: (context) =>
|
||||||
FormulaEditor(
|
FormulaEditor(
|
||||||
formula: formula as Formula,
|
formula: formula as Formula,
|
||||||
corpus: widget.corpus,
|
corpus: widget.corpus,
|
||||||
onSave: (updatedFormula) {
|
onSave: (updatedFormula) {
|
||||||
widget.onSave?.call(updatedFormula);
|
widget.onSave?.call(updatedFormula);
|
||||||
setState(() {
|
setState(() {
|
||||||
formula = updatedFormula;
|
formula = updatedFormula;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
);
|
||||||
|
},
|
||||||
tooltip: formula is DerivedFormula
|
tooltip: formula is DerivedFormula
|
||||||
? 'Cannot edit derived formula'
|
? 'Cannot edit derived formula'
|
||||||
: 'Edit Formula',
|
: 'Edit Formula',
|
||||||
|
|
|
||||||
|
|
@ -275,4 +275,11 @@ class Corpus{
|
||||||
return result.toList();
|
return result.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void forgetFormula(Formula formula) {
|
||||||
|
for (final tag in formula.tags) {
|
||||||
|
_tags[tag]?.remove(formula);
|
||||||
|
}
|
||||||
|
_allFormulas.remove(formula.uuid);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart';
|
||||||
|
|
||||||
String? formatOutput(dynamic result) {
|
String? formatOutput(dynamic result) {
|
||||||
if (result == null) return null;
|
if (result == null) return null;
|
||||||
|
return result.toString();
|
||||||
|
|
||||||
// Try to parse as number to format with commas
|
// Try to parse as number to format with commas
|
||||||
if (result is num) {
|
if (result is num) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue