title_generator 0.0.2
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.
Title Generator Plugin #
A Flutter plugin for generating smart titles from text using platform-specific Natural Language Processing capabilities.
Features #
- Cross-platform support: Works on both iOS and Android
- Native NLP: Uses iOS NaturalLanguage framework and Android text processing
- Smart title generation: Analyzes text content to generate contextual titles
- Easy integration: Simple API for generating titles from any text input
- Error handling: Graceful error handling with informative messages
- Platform optimization: Platform-specific algorithms for best results
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
title_generator: ^0.0.1
Then run:
flutter pub get
Quick Start #
import 'package:title_generator/title_generator.dart';
// Create an instance of the plugin
final titleGenerator = TitleGeneratorPlugin();
// Generate titles from text
List<String> titles = await titleGenerator.generateTitles("Your text content here");
print(titles); // ['Generated Title 1', 'Generated Title 2', ...]
Usage #
Basic Usage #
import 'package:title_generator/title_generator.dart';
class TitleGeneratorService {
final TitleGeneratorPlugin _titleGenerator = TitleGeneratorPlugin();
Future<List<String>> generateTitles(String text) async {
try {
return await _titleGenerator.generateTitles(text);
} catch (e) {
print('Error generating titles: $e');
return [];
}
}
}
Complete Example #
import 'package:flutter/material.dart';
import 'package:title_generator/title_generator.dart';
class TitleGeneratorDemo extends StatefulWidget {
@override
_TitleGeneratorDemoState createState() => _TitleGeneratorDemoState();
}
class _TitleGeneratorDemoState extends State<TitleGeneratorDemo> {
final TitleGeneratorPlugin _titleGenerator = TitleGeneratorPlugin();
List<String> _titles = [];
bool _isGenerating = false;
final TextEditingController _textController = TextEditingController();
Future<void> _generateTitles() async {
if (_textController.text.isEmpty) return;
setState(() {
_isGenerating = true;
});
try {
final titles = await _titleGenerator.generateTitles(_textController.text);
setState(() {
_titles = titles;
});
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Error generating titles: $e')),
);
} finally {
setState(() {
_isGenerating = false;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Title Generator Demo'),
backgroundColor: Colors.blue,
),
body: Padding(
padding: EdgeInsets.all(16.0),
child: Column(
children: [
TextField(
controller: _textController,
decoration: InputDecoration(
labelText: 'Enter your text',
border: OutlineInputBorder(),
hintText: 'Enter text to generate titles from...',
),
maxLines: 3,
),
SizedBox(height: 16),
ElevatedButton(
onPressed: _isGenerating ? null : _generateTitles,
child: _isGenerating
? CircularProgressIndicator(color: Colors.white)
: Text('Generate Titles'),
style: ElevatedButton.styleFrom(
minimumSize: Size(double.infinity, 50),
),
),
SizedBox(height: 16),
if (_titles.isNotEmpty) ...[
Text(
'Generated Titles:',
style: Theme.of(context).textTheme.headlineSmall,
),
SizedBox(height: 8),
Expanded(
child: ListView.builder(
itemCount: _titles.length,
itemBuilder: (context, index) => Card(
child: ListTile(
title: Text(_titles[index]),
leading: Icon(Icons.title),
),
),
),
),
],
],
),
),
);
}
@override
void dispose() {
_textController.dispose();
super.dispose();
}
}
Platform Support #
iOS #
- Uses Apple's NaturalLanguage framework
- Advanced NLP capabilities including part-of-speech tagging
- Generates titles based on noun and adjective combinations
- Leverages iOS-specific language processing features
Android #
- Uses platform-specific text processing
- Splits text into words and creates meaningful combinations
- Filters out short words and common stop words
- Optimized for Android performance
API Reference #
TitleGeneratorPlugin #
The main class for generating titles from text.
Methods
Future<List<String>> generateTitles(String text)
Generates smart titles from the provided text using platform-specific NLP capabilities.
Parameters:
text(String): The input text to generate titles from
Returns:
Future<List<String>>: A list of generated titles. If generation fails, returns a list with an error message.
Example:
final titles = await titleGenerator.generateTitles("Your article content here");
Future<String?> getPlatformVersion()
Returns the platform version string for debugging purposes.
Returns:
Future<String?>: Platform version information
Example:
final version = await titleGenerator.getPlatformVersion();
print('Platform version: $version');
Error Handling #
The plugin handles errors gracefully and returns error messages in the result list rather than throwing exceptions. This makes it easier to handle errors in your application.
List<String> titles = await titleGenerator.generateTitles(text);
if (titles.length == 1 && titles[0].startsWith('Error:')) {
// Handle error case
print('Generation failed: ${titles[0]}');
} else {
// Process successful results
for (String title in titles) {
print('Generated title: $title');
}
}
Example #
Run the example app to see the plugin in action:
cd example
flutter run
The example app demonstrates:
- Basic title generation
- Error handling
- UI integration
- Real-time title generation
Contributing #
We welcome contributions! Please feel free to submit issues or pull requests.
Development Setup #
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Code Style #
This project follows the Dart style guide and uses flutter_lints for code analysis.
License #
This project is licensed under the MIT License - see the LICENSE file for details.
Support #
If you encounter any issues or have questions:
Changelog #
See CHANGELOG.md for a list of changes and version history.