-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.dart
110 lines (105 loc) · 3.18 KB
/
main.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
108
109
110
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_expandable_text/flutter_expandable_text.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const Home(),
);
}
}
class Home extends StatelessWidget {
const Home({Key? key}) : super(key: key);
final String _text =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do '
'eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim '
'ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut '
'aliquip ex ea commodo consequat. Duis aute irure dolor';
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Flutter Expandable Text')),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Trim after 20 characters',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
const SizedBox(height: 10),
ExpandableText(
_text,
trimType: TrimType.characters,
trim: 20,
),
const SizedBox(height: 20),
const Text(
'Trim after 2 lines',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
const SizedBox(height: 10),
ExpandableText(
_text,
trimType: TrimType.lines,
trim: 2,
onLinkPressed: (expanded) {
if (kDebugMode) {
if (expanded) {
print('Was Exapnded');
} else {
print('Was Collapsed');
}
}
},
),
const SizedBox(height: 20),
const Text(
'Custom styling',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
),
),
const SizedBox(height: 10),
ExpandableText(
_text,
trimType: TrimType.lines,
trim: 2,
readLessText: 'customised collapse',
readMoreText: 'customised expand',
linkTextStyle: const TextStyle(
color: Colors.green, fontWeight: FontWeight.bold),
onLinkPressed: (expanded) {
if (kDebugMode) {
if (expanded) {
print('Was Exapnded');
} else {
print('Was Collapsed');
}
}
},
),
],
),
),
);
}
}