title_generator 0.0.2 copy "title_generator: ^0.0.2" to clipboard
title_generator: ^0.0.2 copied to clipboard

Generate smart titles from text using platform-specific Natural Language Processing capabilities. Supports iOS and Android with native NLP integration.

example/lib/main.dart

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

import 'package:flutter/services.dart';
import 'package:title_generator/title_generator_plugin.dart';

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

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

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  List<String> _generatedTitles = [];
  bool _isGenerating = false;
  final _textController = TextEditingController();
  final _titleGeneratorPlugin = TitleGeneratorPlugin();

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

  @override
  void dispose() {
    _textController.dispose();
    super.dispose();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;
    // Platform messages may fail, so we use a try/catch PlatformException.
    // We also handle the message potentially returning null.
    try {
      platformVersion =
          await _titleGeneratorPlugin.getPlatformVersion() ?? 'Unknown platform version';
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _platformVersion = platformVersion;
    });
  }

  Future<void> _generateTitles() async {
    if (_textController.text.trim().isEmpty) {
      ScaffoldMessenger.of(context).showSnackBar(
        const SnackBar(content: Text('Please enter some text')),
      );
      return;
    }

    setState(() {
      _isGenerating = true;
    });

    try {
      final titles = await _titleGeneratorPlugin.generateTitles(_textController.text);
      if (mounted) {
        setState(() {
          _generatedTitles = titles;
        });
      }
    } catch (e) {
      if (mounted) {
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(content: Text('Error generating titles: $e')),
        );
      }
    } finally {
      setState(() {
        _isGenerating = false;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Title Generator Plugin Demo'),
        ),
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Text('Running on: $_platformVersion', style: Theme.of(context).textTheme.bodySmall),
              const SizedBox(height: 20),
              TextField(
                controller: _textController,
                maxLines: 4,
                decoration: const InputDecoration(
                  labelText: 'Enter text to generate titles from',
                  border: OutlineInputBorder(),
                  hintText: 'Enter your content here...',
                ),
              ),
              const SizedBox(height: 16),
              ElevatedButton(
                onPressed: _isGenerating ? null : _generateTitles,
                child: _isGenerating 
                  ? const CircularProgressIndicator()
                  : const Text('Generate Titles'),
              ),
              const SizedBox(height: 20),
              if (_generatedTitles.isNotEmpty) ...[
                Text(
                  'Generated Titles:',
                  style: Theme.of(context).textTheme.titleMedium,
                ),
                const SizedBox(height: 8),
                Expanded(
                  child: ListView.builder(
                    itemCount: _generatedTitles.length,
                    itemBuilder: (context, index) {
                      return Card(
                        child: ListTile(
                          title: Text(_generatedTitles[index]),
                          leading: Text('${index + 1}'),
                        ),
                      );
                    },
                  ),
                ),
              ],
            ],
          ),
        ),
      ),
    );
  }
}
1
likes
155
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

Generate smart titles from text using platform-specific Natural Language Processing capabilities. Supports iOS and Android with native NLP integration.

Repository (GitHub)
View/report issues

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on title_generator

Packages that implement title_generator