|
| 1 | +import 'package:flutter/cupertino.dart'; |
1 | 2 | import 'package:flutter/gestures.dart';
|
2 | 3 | import 'package:flutter/material.dart';
|
3 | 4 | import 'package:flutter/services.dart';
|
| 5 | +import 'package:flutter/widgets.dart'; |
4 | 6 | import 'package:html/dom.dart' as dom;
|
| 7 | +import 'package:flutter_gen/gen_l10n/zulip_localizations.dart'; |
5 | 8 |
|
6 | 9 | import '../api/core.dart';
|
7 | 10 | import '../api/model/model.dart';
|
@@ -78,6 +81,8 @@ class BlockContentList extends StatelessWidget {
|
78 | 81 | return Quotation(node: node);
|
79 | 82 | } else if (node is ListNode) {
|
80 | 83 | return ListNodeWidget(node: node);
|
| 84 | + } else if (node is SpoilerNode) { |
| 85 | + return Spoiler(node: node); |
81 | 86 | } else if (node is CodeBlockNode) {
|
82 | 87 | return CodeBlock(node: node);
|
83 | 88 | } else if (node is MathBlockNode) {
|
@@ -228,6 +233,97 @@ class ListItemWidget extends StatelessWidget {
|
228 | 233 | }
|
229 | 234 | }
|
230 | 235 |
|
| 236 | +class Spoiler extends StatefulWidget { |
| 237 | + const Spoiler({super.key, required this.node}); |
| 238 | + |
| 239 | + final SpoilerNode node; |
| 240 | + |
| 241 | + @override |
| 242 | + State<Spoiler> createState() => _SpoilerState(); |
| 243 | +} |
| 244 | + |
| 245 | +class _SpoilerState extends State<Spoiler> with TickerProviderStateMixin { |
| 246 | + bool expanded = false; |
| 247 | + late final AnimationController _controller = AnimationController( |
| 248 | + duration: const Duration(milliseconds: 400), |
| 249 | + vsync: this, |
| 250 | + ); |
| 251 | + late final Animation<double> _animation = CurvedAnimation( |
| 252 | + parent: _controller, |
| 253 | + curve: Curves.easeInOut, |
| 254 | + ); |
| 255 | + |
| 256 | + @override |
| 257 | + void dispose() { |
| 258 | + _controller.dispose(); |
| 259 | + super.dispose(); |
| 260 | + } |
| 261 | + |
| 262 | + void _handleTap() { |
| 263 | + setState(() { |
| 264 | + if (!expanded) { |
| 265 | + _controller.forward(); |
| 266 | + expanded = true; |
| 267 | + } else { |
| 268 | + _controller.reverse(); |
| 269 | + expanded = false; |
| 270 | + } |
| 271 | + }); |
| 272 | + } |
| 273 | + |
| 274 | + @override |
| 275 | + Widget build(BuildContext context) { |
| 276 | + final zulipLocalizations = ZulipLocalizations.of(context); |
| 277 | + final header = widget.node.header; |
| 278 | + final effectiveHeader = header.isNotEmpty |
| 279 | + ? header |
| 280 | + : [ParagraphNode(links: null, |
| 281 | + nodes: [TextNode(zulipLocalizations.spoilerDefaultHeaderText)])]; |
| 282 | + return Padding( |
| 283 | + padding: const EdgeInsets.fromLTRB(0, 5, 0, 15), |
| 284 | + child: DecoratedBox( |
| 285 | + decoration: BoxDecoration( |
| 286 | + border: Border.all(color: const Color(0xff808080)), |
| 287 | + borderRadius: BorderRadius.circular(10), |
| 288 | + ), |
| 289 | + child: Padding(padding: const EdgeInsetsDirectional.fromSTEB(10, 2, 8, 2), |
| 290 | + child: Column( |
| 291 | + children: [ |
| 292 | + GestureDetector( |
| 293 | + behavior: HitTestBehavior.translucent, |
| 294 | + onTap: _handleTap, |
| 295 | + child: Padding( |
| 296 | + padding: const EdgeInsets.all(5), |
| 297 | + child: Row(crossAxisAlignment: CrossAxisAlignment.end, children: [ |
| 298 | + Expanded( |
| 299 | + child: DefaultTextStyle.merge( |
| 300 | + style: weightVariableTextStyle(context, wght: 700), |
| 301 | + child: BlockContentList( |
| 302 | + nodes: effectiveHeader))), |
| 303 | + RotationTransition( |
| 304 | + turns: _animation.drive(Tween(begin: 0, end: 0.5)), |
| 305 | + child: const Icon(color: Color(0xffd4d4d4), size: 25, |
| 306 | + Icons.expand_more)), |
| 307 | + ]))), |
| 308 | + FadeTransition( |
| 309 | + opacity: _animation, |
| 310 | + child: const SizedBox(height: 0, width: double.infinity, |
| 311 | + child: DecoratedBox( |
| 312 | + decoration: BoxDecoration( |
| 313 | + border: Border( |
| 314 | + bottom: BorderSide(width: 1, color: Color(0xff808080))))))), |
| 315 | + SizeTransition( |
| 316 | + sizeFactor: _animation, |
| 317 | + axis: Axis.vertical, |
| 318 | + axisAlignment: -1, |
| 319 | + child: Padding( |
| 320 | + padding: const EdgeInsets.all(5), |
| 321 | + child: BlockContentList(nodes: widget.node.content))), |
| 322 | + ])))); |
| 323 | + } |
| 324 | +} |
| 325 | + |
| 326 | + |
231 | 327 | class MessageImage extends StatelessWidget {
|
232 | 328 | const MessageImage({super.key, required this.node});
|
233 | 329 |
|
|
0 commit comments