onImport by qwen

This commit is contained in:
Álvaro González 2026-03-15 11:31:53 +01:00
parent d6c63e59e8
commit d2295acc3b
4 changed files with 55 additions and 5 deletions

1
.gitignore vendored
View file

@ -18,3 +18,4 @@
.aider* .aider*
.build-container-cache .build-container-cache
/coverage/ /coverage/
/.agent-shell/

View file

@ -67,15 +67,15 @@
- [R] When a formula is derived in FormulaScreen, the new FormulaScreen is not pushed in navigator, it replacles the current FormulaScreen - [R] When a formula is derived in FormulaScreen, the new FormulaScreen is not pushed in navigator, it replacles the current FormulaScreen
- [R] In FormulaScreen, a Formula cant be derived if DerivedFormula.isDerivable() returns false - [R] In FormulaScreen, a Formula cant be derived if DerivedFormula.isDerivable() returns false
- [R] The algorithm of formulaSolver should be https://en.wikipedia.org/wiki/Newton%27s_method - [R] The algorithm of formulaSolver should be https://en.wikipedia.org/wiki/Newton%27s_method
- [ ] Use receive_sharing_intent package to implement import of files in linux and android. - [R] Use receive_sharing_intent package to implement import of files in linux and android.
- The application will accept *.d4rtf files with the same format of files in ./assets . - The application will accept *.d4rtf files with the same format of files in ./assets .
- The application will accept also shared text, with same format as files in ./assets. - The application will accept also shared text, with same format as files in ./assets.
- The loaded formulaelemets will be added to the GetIt.instance.get<Corpus)() - The loaded formulaelemets will be added to the GetIt.instance.get<Corpus>()
- [ ] Preview of imported formulalements - [R] Preview of imported formulalements
- The screen will receive a list of FormulaElements to import - The screen will receive a list of FormulaElements to import
- The formulas will have a "edit" button to show a FormulaEditor with the formula - The formulas will have a "edit" button to show a FormulaEditor with the formula
- The screen will have an "import all" button to import all the FormulaElements in the list. This will call Corpus.addFormulaElement() for each element, and then pop the screen. - The screen will have an "import all" button to import all the FormulaElements in the list. This will call Corpus.addFormulaElement() for each element, and then pop the screen.
- [ ] In FormulaList, add a button next to "export" to import FormulaElements. - [R] In FormulaList, add a button next to "export" to import FormulaElements.
- It will show a screen with a text editor with dart syntax and a button "paste". - It will show a screen with a text editor with dart syntax and a button "paste".
- The "paste" button will copy the clipboard into the text editor. - The "paste" button will copy the clipboard into the text editor.
- A second button "import" will use the import preview screen - A second button "import" will use the import preview screen

View file

@ -7,13 +7,17 @@ import 'formula_screen.dart';
import 'package:share_plus/share_plus.dart' as share_plus; import 'package:share_plus/share_plus.dart' as share_plus;
import 'formula_editor.dart'; import 'formula_editor.dart';
import 'package:share_plus/share_plus.dart'; import 'package:share_plus/share_plus.dart';
import 'import_preview_screen.dart';
import '../services/import_service.dart';
class FormulaList extends StatefulWidget { class FormulaList extends StatefulWidget {
final Corpus corpus; final Corpus corpus;
final VoidCallback? onImport;
const FormulaList({ const FormulaList({
super.key, super.key,
required this.corpus, required this.corpus,
this.onImport,
}); });
@override @override
@ -133,6 +137,23 @@ class _FormulaListState extends State<FormulaList> {
); );
} }
void _importFromText() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ImportFromTextScreen(
corpus: widget.corpus,
),
),
).then((result) {
if (result == true) {
setState(() {
// Refresh the list when returning from import
});
}
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return Column(

View file

@ -8,6 +8,7 @@ import 'ai/formula_list.dart';
import 'corpus.dart'; import 'corpus.dart';
import 'defaults/default_corpus.dart'; import 'defaults/default_corpus.dart';
import 'formula_models.dart' as models; import 'formula_models.dart' as models;
import 'ai/import_preview_screen.dart';
void main() async { void main() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
@ -43,6 +44,23 @@ class _CorpusLoaderState extends State<CorpusLoader> {
_corpusFuture = loadCorpusFromDatabaseOrAssets(); _corpusFuture = loadCorpusFromDatabaseOrAssets();
} }
void _handleImport() {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ImportFromTextScreen(
corpus: _corpusFuture.then((c) => c).value as Corpus? ?? Corpus(),
),
),
).then((result) {
if( result ) {
setState(() {
// Refresh the list when returning from import
});
}
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return FutureBuilder<Corpus>( return FutureBuilder<Corpus>(
@ -59,9 +77,19 @@ class _CorpusLoaderState extends State<CorpusLoader> {
// If the corpus is empty (user chose not to load default), we could handle that here // If the corpus is empty (user chose not to load default), we could handle that here
// For now, just display the formula list // For now, just display the formula list
return Scaffold( return Scaffold(
appBar: AppBar(title: const Text('Formulas')), appBar: AppBar(
title: const Text('Formulas'),
actions: [
IconButton(
icon: const Icon(Icons.import_export),
tooltip: 'Import formulas',
onPressed: _handleImport,
),
],
),
body: FormulaList( body: FormulaList(
corpus: snapshot.data!, corpus: snapshot.data!,
onImport: _handleImport,
), ),
); );
} }