Skip to content

Commit

Permalink
feat: add ExpandableText widget
Browse files Browse the repository at this point in the history
  • Loading branch information
kkweon committed Jun 20, 2021
1 parent e53026b commit da5da10
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 15 deletions.
63 changes: 63 additions & 0 deletions client/lib/widgets/components/expandable_text.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';

class ExpandableText extends StatefulWidget {
const ExpandableText({
Key? key,
required this.text,
}) : super(key: key);

final String text;

@override
_ExpandableTextState createState() => _ExpandableTextState();
}

class _ExpandableTextState extends State<ExpandableText> {
bool _isExpanded = false;

@override
Widget build(BuildContext context) {
if (_isExpanded) {
return Card(
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
widget.text,
softWrap: true,
),
IconButton(
onPressed: onPressed,
icon: const Icon(Icons.keyboard_arrow_up, size: 50)),
],
),
));
}

return Stack(alignment: Alignment.bottomCenter, children: [
Card(
child: Container(
padding: const EdgeInsets.only(top: 15, left: 15, right: 15),
height: 100,
child: Text(
widget.text,
overflow: TextOverflow.fade,
maxLines: 3,
softWrap: true,
))),
Positioned(
bottom: 10,
child: IconButton(
onPressed: onPressed,
icon: const Icon(Icons.keyboard_arrow_down, size: 50)))
]);
}

void onPressed() {
setState(() {
_isExpanded = !_isExpanded;
});
}
}
17 changes: 2 additions & 15 deletions client/lib/widgets/detail/abstract.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:pr12er/protos/pkg/pr12er/messages.pb.dart';
import 'package:pr12er/widgets/components/expandable_text.dart';

// ignore: must_be_immutable
class PaperAbstractWidget extends StatelessWidget {
Expand All @@ -18,21 +19,7 @@ class PaperAbstractWidget extends StatelessWidget {
"Abstract",
style: Theme.of(context).textTheme.headline1,
),
Stack(alignment: Alignment.bottomCenter, children: [
// ignore: sized_box_for_whitespace
Card(
child: Container(
padding:
const EdgeInsets.only(top: 15, left: 15, right: 15),
height: 150,
child: Text(
paper.abstract,
overflow: TextOverflow.fade,
softWrap: true,
))),
const Positioned(
bottom: -10, child: Icon(Icons.keyboard_arrow_down, size: 50))
])
ExpandableText(text: paper.abstract)
],
));
}
Expand Down

0 comments on commit da5da10

Please sign in to comment.