-
Notifications
You must be signed in to change notification settings - Fork 4
/
example.dart
107 lines (97 loc) · 3.81 KB
/
example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import 'package:flutter/material.dart';
import 'package:hyphenatorx/hyphenatorx.dart';
import 'package:hyphenatorx/languages/languageconfig.dart';
import 'package:hyphenatorx/widget/texthyphenated.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
home: HyphenatorExampleWidget(),
);
}
}
class HyphenatorExampleWidget extends StatefulWidget {
const HyphenatorExampleWidget({Key? key}) : super(key: key);
@override
_HyphenatorExampleWidgetState createState() =>
_HyphenatorExampleWidgetState();
}
class _HyphenatorExampleWidgetState extends State<HyphenatorExampleWidget> {
String text = "subdivision";
final controller = TextEditingController();
late Future<Hyphenator> _future;
@override
void initState() {
super.initState();
controller.text = text;
controller.addListener(() {
setState(() {
text = controller.text;
});
});
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
_future = Hyphenator.loadAsync(Language.language_en_us, symbol: '_');
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: FutureBuilder<Hyphenator>(
future: _future,
builder: (BuildContext context, AsyncSnapshot<Hyphenator> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
final Hyphenator hyphernator = snapshot.data!;
return SingleChildScrollView(
child: Center(
child: SizedBox(
width: MediaQuery.of(context).size.width * 2 / 3,
child: Column(
children: [
TextField(
controller: controller,
decoration: const InputDecoration(
hintText: 'Enter some text'),
),
const SizedBox(height: 16),
text.isEmpty
? const Text('Enter some text')
: Text(hyphernator.hyphenateText(text),
style: const TextStyle(fontSize: 32)),
const SizedBox(height: 32),
text.isEmpty
? const SizedBox.shrink()
: Text(
'Cached hyphenated:\n\n${hyphernator.cachedHyphendWords}',
textAlign: TextAlign.center,
),
const SizedBox(height: 16),
text.isEmpty
? const SizedBox.shrink()
: Text(
'Cached non-hyphenated:\n\n${hyphernator.cachedNonHyphendWords}',
textAlign: TextAlign.center,
),
// const SizedBox(height: 32),
const Divider(),
const Text("Widget Test:"),
const SizedBox(height: 16),
const Text(
"TextHyphenated('subdivision', 'en_us', symbol:'@')"),
const SizedBox(height: 16),
const TextHyphenated('subdivision', 'en_us',
symbol: '@'),
],
))));
}),
);
}
}