toon_formater 1.0.2
toon_formater: ^1.0.2 copied to clipboard
Token-Oriented Object Notation (TOON) – A compact, deterministic JSON format for LLM prompts (Dart implementation)
example/lib/main.dart
import 'package:flutter/material.dart';
import 'user_model.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'TOON Example',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String _toonOutput = '';
String _parsedName = '';
@override
void initState() {
super.initState();
_testToon();
}
void _testToon() {
final user = User(
name: 'Alice',
age: 30,
email: 'alice@example.com',
);
// Convert to TOON format
final toon = user.toToon();
setState(() {
_toonOutput = toon;
});
// Parse from TOON format
final parsed = User.fromToon(toon);
setState(() {
_parsedName = parsed.name;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('TOON Format Example'),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'TOON Output:',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(8),
),
child: SelectableText(
_toonOutput,
style: const TextStyle(fontFamily: 'monospace'),
),
),
const SizedBox(height: 24),
const Text(
'Parsed Name:',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Text(
_parsedName,
style: const TextStyle(fontSize: 16),
),
],
),
),
);
}
}