fable_flow_lite 0.0.1 copy "fable_flow_lite: ^0.0.1" to clipboard
fable_flow_lite: ^0.0.1 copied to clipboard

A lightweight visual novel player for Flutter.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show rootBundle;
import 'package:fable_flow_lite/fable_flow_lite.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Lite Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

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

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  String? _scriptContent;
  bool _isLoading = true;

  @override
  void initState() {
    super.initState();
    _loadScript();
  }

  Future<void> _loadScript() async {
    try {
      final String content = await rootBundle.loadString('assets/script.json');
      setState(() {
        _scriptContent = content;
        _isLoading = false;
      });
    } catch (e) {
      debugPrint('Error loading script: $e');
      setState(() {
        _isLoading = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _isLoading
          ? const Center(child: CircularProgressIndicator())
          : _scriptContent == null
              ? const Center(child: Text('Failed to load script'))
              : StoryPlayer.fromJson(
                  jsonContent: _scriptContent!,
                  onComplete: () {
                    ScaffoldMessenger.of(context).showSnackBar(
                      const SnackBar(content: Text('Story Completed!')),
                    );
                    // Reset or go back
                  },
                  title: 'Lite Player Example',
                  // Customization
                  dialogBoxDecoration: BoxDecoration(
                    color: Colors.blue.withValues(alpha: 0.5),
                    borderRadius: BorderRadius.circular(20),
                    border: Border.all(color: Colors.white, width: 2),
                  ),
                  characterNameStyle: const TextStyle(
                    color: Colors.yellow,
                    fontSize: 20,
                    fontWeight: FontWeight.bold,
                    shadows: [
                      Shadow(
                        offset: Offset(1, 1),
                        blurRadius: 2,
                        color: Colors.black,
                      ),
                    ],
                  ),
                  dialogTextStyle: const TextStyle(
                    color: Colors.white,
                    fontSize: 18,
                    shadows: [
                      Shadow(
                        offset: Offset(1, 1),
                        blurRadius: 2,
                        color: Colors.black,
                      ),
                    ],
                  ),
                  // baseDir is null because we are using network images in the example script
                  // If using local assets, we would need to handle that.
                ),
    );
  }
}
1
likes
140
points
71
downloads

Publisher

unverified uploader

Weekly Downloads

A lightweight visual novel player for Flutter.

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

fable_flow_engine, flutter, flutter_cache_manager, http

More

Packages that depend on fable_flow_lite