feat: switch to async unit loading with temperature corpus
Co-authored-by: aider (openrouter/deepseek/deepseek-r1:free) <aider@aider.chat>
This commit is contained in:
parent
19fd9552c8
commit
666fa20e7b
1 changed files with 32 additions and 20 deletions
|
|
@ -2,29 +2,41 @@ import 'package:d4rt_formulas/ai/FormulaWidget.dart';
|
||||||
import 'package:d4rt_formulas/formula_models.dart';
|
import 'package:d4rt_formulas/formula_models.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:resource/resource.dart';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
//runApp(const MyApp());
|
runApp(MaterialApp(
|
||||||
Formula formula = sampleFormula();
|
home: FutureBuilder<UnitCorpus>(
|
||||||
runApp( MaterialApp( home: FormulaWidget(formula: formula)) );
|
future: createTestCorpus(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
|
if (snapshot.hasError) {
|
||||||
|
return Center(child: Text('Error loading units: ${snapshot.error}'));
|
||||||
|
}
|
||||||
|
return UnitList(corpus: snapshot.data!);
|
||||||
|
}
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
},
|
||||||
|
),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
Formula sampleFormula(){
|
Future<UnitCorpus> createTestCorpus() async {
|
||||||
final literal = """
|
final corpus = UnitCorpus();
|
||||||
{
|
final resources = ["lib/units/temperature.d4rt.units"];
|
||||||
"name": "Newton's second law",
|
|
||||||
"input": [
|
for (final resourcePath in resources) {
|
||||||
{ "name": 'm', "magnitude": 'mass'},
|
try {
|
||||||
{ "name": 'a', "magnitude": 'acceleration'}
|
final resource = Resource(resourcePath);
|
||||||
],
|
final literal = await resource.readAsString(encoding: utf8);
|
||||||
"output": { "name": 'F', "magnitude": 'force'},
|
final units = UnitSpec.fromArrayStringLiteral(literal);
|
||||||
"d4rtCode": '''
|
corpus.loadUnits(units);
|
||||||
F = a * m;
|
} catch (e) {
|
||||||
'''
|
print('Error loading $resourcePath: $e');
|
||||||
}
|
}
|
||||||
""";
|
}
|
||||||
|
return corpus;
|
||||||
final formula = Formula.fromStringLiteral(literal);
|
|
||||||
return formula;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue