From 958050311e5ac7d32cfd530aca4d8648695567b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Gonz=C3=A1lez?= Date: Thu, 2 Apr 2026 21:01:22 +0200 Subject: [PATCH] solved layout issue --- TODO.md | 1 + lib/ai/formula_editor.dart | 271 +++++++++++++++++++------------------ lib/main.dart | 15 +- 3 files changed, 147 insertions(+), 140 deletions(-) diff --git a/TODO.md b/TODO.md index b86211d..bcec37d 100644 --- a/TODO.md +++ b/TODO.md @@ -79,6 +79,7 @@ - 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. - A second button "import" will use the import preview screen + -[R] Launch test app_test.dart. Iterate until the test pass. - [ ] Add a uuid column to the table or FormulaElements, so it is not necessary to load all the formulas to find a formula by uuid. This will improve performance when updating and deleting. - [ ] Make formulaSolver() asyncronous, and show a CircularProgressIndicator while the formula is being solved. Honor a new optinal parameter "timeout" in formulaSolver, that will throw a TimeoutException. - [ ] When importing FormulaElements, save the FormulaElements in the database (currently, they are only added to the Corpus in memory). diff --git a/lib/ai/formula_editor.dart b/lib/ai/formula_editor.dart index d12a5af..a3a2856 100644 --- a/lib/ai/formula_editor.dart +++ b/lib/ai/formula_editor.dart @@ -439,74 +439,74 @@ class _FormulaEditorState extends State { ), ), const SizedBox(width: 8), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - DropdownButtonFormField( - value: _getBaseUnit(variable.unit), - decoration: const InputDecoration( - border: OutlineInputBorder(), - labelText: "Base unit", - contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 0), - ), - items: [ - const DropdownMenuItem( - value: null, - child: Text('None', style: TextStyle(fontSize: 14)), - ), - ..._getAllBaseUnits().map((baseUnit) { - return DropdownMenuItem( - value: baseUnit, - child: Text(baseUnit, style: const TextStyle(fontSize: 14)), - ); - }).toList(), - ], - onChanged: (baseUnit) { - setState(() { - variable.unit = baseUnit; - }); - }, + Flexible( + flex: 1, + child: DropdownButtonFormField( + isDense: true, + isExpanded: true, + value: _getBaseUnit(variable.unit), + decoration: const InputDecoration( + border: OutlineInputBorder(), + labelText: "Base unit", + contentPadding: EdgeInsets.symmetric(horizontal: 8, vertical: 0), + ), + dropdownColor: Theme.of(context).colorScheme.surface, + menuMaxHeight: 300, + items: [ + const DropdownMenuItem( + value: null, + child: Text('None', style: TextStyle(fontSize: 11)), ), + ..._getAllBaseUnits().map((baseUnit) { + return DropdownMenuItem( + value: baseUnit, + child: Text(baseUnit, style: const TextStyle(fontSize: 11)), + ); + }).toList(), ], + onChanged: (baseUnit) { + setState(() { + variable.unit = baseUnit; + }); + }, ), ), const SizedBox(width: 8), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - DropdownButtonFormField( - value: variable.unit, - decoration: const InputDecoration( - border: OutlineInputBorder(), - labelText: "Derived unit", - contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 0), - ), - items: [ - const DropdownMenuItem( - value: null, - child: Text('None', style: TextStyle(fontSize: 14)), - ), - ..._getDerivedUnits(variable.unit).map((unit) { - final unitSpec = widget.corpus.getUnit(unit); - return DropdownMenuItem( - value: unit, - child: Text( - '${unitSpec.symbol} - ${unit}', - style: const TextStyle(fontSize: 14), - overflow: TextOverflow.ellipsis, - ), - ); - }).toList(), - ], - onChanged: (unit) { - setState(() { - variable.unit = unit; - }); - }, + Flexible( + flex: 1, + child: DropdownButtonFormField( + isDense: true, + isExpanded: true, + value: variable.unit, + decoration: const InputDecoration( + border: OutlineInputBorder(), + labelText: "Unit", + contentPadding: EdgeInsets.symmetric(horizontal: 8, vertical: 0), + ), + dropdownColor: Theme.of(context).colorScheme.surface, + menuMaxHeight: 300, + items: [ + const DropdownMenuItem( + value: null, + child: Text('None', style: TextStyle(fontSize: 10)), ), + ..._getDerivedUnits(variable.unit).map((unit) { + final unitSpec = widget.corpus.getUnit(unit); + return DropdownMenuItem( + value: unit, + child: Text( + '${unitSpec.symbol}', + style: const TextStyle(fontSize: 10), + overflow: TextOverflow.ellipsis, + ), + ); + }).toList(), ], + onChanged: (unit) { + setState(() { + variable.unit = unit; + }); + }, ), ), const SizedBox(width: 8), @@ -514,6 +514,8 @@ class _FormulaEditorState extends State { icon: const Icon(Icons.delete, color: Colors.red), onPressed: () => _removeInputVariable(index), tooltip: 'Delete variable', + padding: EdgeInsets.zero, + constraints: const BoxConstraints(), ), ], ), @@ -542,74 +544,74 @@ class _FormulaEditorState extends State { ), ), const SizedBox(width: 8), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - DropdownButtonFormField( - value: _getBaseUnit(_outputVariable.unit), - decoration: const InputDecoration( - border: OutlineInputBorder(), - labelText: "Base unit", - contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 0), - ), - items: [ - const DropdownMenuItem( - value: null, - child: Text('None', style: TextStyle(fontSize: 14)), - ), - ..._getAllBaseUnits().map((baseUnit) { - return DropdownMenuItem( - value: baseUnit, - child: Text(baseUnit, style: const TextStyle(fontSize: 14)), - ); - }).toList(), - ], - onChanged: (baseUnit) { - setState(() { - _outputVariable.unit = baseUnit; - }); - }, + Flexible( + flex: 1, + child: DropdownButtonFormField( + isDense: true, + isExpanded: true, + value: _getBaseUnit(_outputVariable.unit), + decoration: const InputDecoration( + border: OutlineInputBorder(), + labelText: "Base unit", + contentPadding: EdgeInsets.symmetric(horizontal: 8, vertical: 0), + ), + dropdownColor: Theme.of(context).colorScheme.surface, + menuMaxHeight: 300, + items: [ + const DropdownMenuItem( + value: null, + child: Text('None', style: TextStyle(fontSize: 11)), ), + ..._getAllBaseUnits().map((baseUnit) { + return DropdownMenuItem( + value: baseUnit, + child: Text(baseUnit, style: const TextStyle(fontSize: 11)), + ); + }).toList(), ], + onChanged: (baseUnit) { + setState(() { + _outputVariable.unit = baseUnit; + }); + }, ), ), const SizedBox(width: 8), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - DropdownButtonFormField( - value: _outputVariable.unit, - decoration: const InputDecoration( - border: OutlineInputBorder(), - labelText: "Derived unit", - contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 0), - ), - items: [ - const DropdownMenuItem( - value: null, - child: Text('None', style: TextStyle(fontSize: 14)), - ), - ..._getDerivedUnits(_outputVariable.unit).map((unit) { - final unitSpec = widget.corpus.getUnit(unit); - return DropdownMenuItem( - value: unit, - child: Text( - '${unitSpec.symbol} - ${unit}', - style: const TextStyle(fontSize: 14), - overflow: TextOverflow.ellipsis, - ), - ); - }).toList(), - ], - onChanged: (unit) { - setState(() { - _outputVariable.unit = unit; - }); - }, + Flexible( + flex: 1, + child: DropdownButtonFormField( + isDense: true, + isExpanded: true, + value: _outputVariable.unit, + decoration: const InputDecoration( + border: OutlineInputBorder(), + labelText: "Unit", + contentPadding: EdgeInsets.symmetric(horizontal: 8, vertical: 0), + ), + dropdownColor: Theme.of(context).colorScheme.surface, + menuMaxHeight: 300, + items: [ + const DropdownMenuItem( + value: null, + child: Text('None', style: TextStyle(fontSize: 10)), ), + ..._getDerivedUnits(_outputVariable.unit).map((unit) { + final unitSpec = widget.corpus.getUnit(unit); + return DropdownMenuItem( + value: unit, + child: Text( + '${unitSpec.symbol}', + style: const TextStyle(fontSize: 10), + overflow: TextOverflow.ellipsis, + ), + ); + }).toList(), ], + onChanged: (unit) { + setState(() { + _outputVariable.unit = unit; + }); + }, ), ), ], @@ -622,18 +624,23 @@ class _FormulaEditorState extends State { Widget _buildD4rtCodeSection() { return Card( - child: Expanded( - child: Padding( - padding: const EdgeInsets.all(16.0), - child: CodeTheme( - data: CodeThemeData(styles: monokaiSublimeTheme), - child: Padding( - padding: const EdgeInsets.all(8.0), - child: SingleChildScrollView( - child: CodeField(controller: _d4rtCodeController), + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text('D4RT Code (Dart syntax)', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)), + const SizedBox(height: 8), + ConstrainedBox( + constraints: const BoxConstraints(minHeight: 200), + child: CodeTheme( + data: CodeThemeData(styles: monokaiSublimeTheme), + child: SingleChildScrollView( + child: CodeField(controller: _d4rtCodeController), + ), ), ), - ), + ], ), ), ); diff --git a/lib/main.dart b/lib/main.dart index 94778f8..f289c53 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -57,16 +57,15 @@ class _CorpusLoaderState extends State { Navigator.push( context, MaterialPageRoute( - builder: (context) => ImportFromTextScreen( - corpus: corpus, - ), + builder: (context) => + ImportFromTextScreen( + corpus: corpus, + ), ), ).then((result) { - if (result) { - setState(() { - // Refresh the list when returning from import - }); - } + setState(() { + // Refresh the list when returning from import + }); }); }); }