soft_hyphen_text 0.1.0
soft_hyphen_text: ^0.1.0 copied to clipboard
A Flutter package for wrapping text with soft hyphens.
import 'package:flutter/material.dart';
import 'package:soft_hyphen_text/soft_hyphen_text.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'SoftHyphenText Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const ShowcasePage(),
);
}
}
class ShowcasePage extends StatelessWidget {
const ShowcasePage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('SoftHyphenText Showcase'),
backgroundColor: Colors.deepPurple.shade100,
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'SoftHyphenText Widget',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 4),
const Text(
'Adds hyphens at soft hyphen positions when text wraps',
style: TextStyle(fontSize: 14),
),
const SizedBox(height: 16),
// Main comparison grid - only Long Word and Button Text
SizedBox(
height: 300, // Fixed height for the cards
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
child: _buildComparisonCard(
title: 'Long Word',
text: 'Pneumonoultramicroscopicsilicovolcanoconiosis',
width: 180,
color: Colors.blue.shade50,
),
),
const SizedBox(width: 16),
Expanded(
child: _buildComparisonCard(
title: 'Button Text',
text: 'SubmitForm',
width: 80,
color: Colors.purple.shade50,
),
),
],
),
),
],
),
),
);
}
Widget _buildComparisonCard({
required String title,
required String text,
required double width,
required Color color,
}) {
return Card(
elevation: 2,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
width: 8,
height: 8,
decoration: const BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
),
const SizedBox(width: 4),
const Text(
'With Hyphens',
style: TextStyle(fontSize: 12),
),
],
),
const SizedBox(height: 4),
Expanded(
flex: 1,
child: SingleChildScrollView(
child: Container(
width: width,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: color,
borderRadius: BorderRadius.circular(6),
),
child: SoftHyphenText(
text: text,
style: const TextStyle(fontSize: 14),
),
),
),
),
const SizedBox(height: 8),
Row(
children: [
Container(
width: 8,
height: 8,
decoration: const BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
),
const SizedBox(width: 4),
const Text(
'Without Hyphens',
style: TextStyle(fontSize: 12),
),
],
),
const SizedBox(height: 4),
Expanded(
flex: 1,
child: SingleChildScrollView(
child: Container(
width: width,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: color.withOpacity(0.5),
borderRadius: BorderRadius.circular(6),
),
child: Text(
text.replaceAll('\u00AD', ''),
style: const TextStyle(fontSize: 14),
),
),
),
),
],
),
),
],
),
),
);
}
}