org_flutter 8.0.0 copy "org_flutter: ^8.0.0" to clipboard
org_flutter: ^8.0.0 copied to clipboard

Flutter widgets for displaying Emacs Org Mode (https://orgmode.org) content

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:org_flutter/org_flutter.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'org_flutter',
      restorationScopeId: 'example_root',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 2,
      child: Scaffold(
        appBar: AppBar(
          title: const Text('org_flutter'),
          bottom: const TabBar(
            tabs: [
              Tab(text: 'Simple'),
              Tab(text: 'Complex'),
            ],
          ),
        ),
        body: const TabBarView(children: [
          SimpleTab(),
          ComplexTab(),
        ]),
      ),
    );
  }
}

class SimpleTab extends StatelessWidget {
  const SimpleTab({super.key});

  @override
  Widget build(BuildContext context) {
    return const Org(
      '''* TODO [#A] foo bar
baz buzz''',
      restorationId: 'my_org_widget',
    );
  }
}

class ComplexTab extends StatefulWidget {
  const ComplexTab({super.key});

  @override
  State<ComplexTab> createState() => _ComplexTabState();
}

class _ComplexTabState extends State<ComplexTab> {
  late OrgDocument root;

  @override
  void initState() {
    root = OrgDocument.parse('''* TODO [#A] foo bar
~1~''');

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return OrgController(
      root: root,
      child: ListView(
        children: [
          OrgRootWidget(child: OrgDocumentWidget(root, shrinkWrap: true)),
          ElevatedButton(
            onPressed: _incrementCounter,
            child: const Text('Increment'),
          ),
        ],
      ),
    );
  }

  void _incrementCounter() {
    late OrgMarkup markupNode;
    root.visit<OrgMarkup>((node) {
      markupNode = node;
      return false; // stop visiting
    });
    final value = int.parse(markupNode.content);
    setState(() {
      root = root
          .editNode(markupNode)!
          .replace(OrgMarkup('~', '${value + 1}', '~', OrgStyle.code))
          .commit() as OrgDocument;
    });
  }
}
3
likes
0
points
1.5k
downloads

Publisher

verified publishermadlon-kay.com

Weekly Downloads

Flutter widgets for displaying Emacs Org Mode (https://orgmode.org) content

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, flutter_slidable, flutter_tex_js, highlighting, more, org_parser, petit_lisp, petitparser

More

Packages that depend on org_flutter