aboutsummaryrefslogtreecommitdiff
path: root/lib/widgets/common/basic/link_chip.dart
blob: 53ddc655382e2b03d46d1d0d822cccf20282b183 (plain) (blame)
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
import 'package:aves/theme/icons.dart';
import 'package:aves/widgets/aves_app.dart';
import 'package:flutter/material.dart';

class LinkChip extends StatelessWidget {
  final Widget? leading;
  final String text;
  final String? urlString;
  final Color? color;
  final TextStyle? textStyle;
  final VoidCallback? onTap;

  static const borderRadius = BorderRadius.all(Radius.circular(8));

  const LinkChip({
    super.key,
    this.leading,
    required this.text,
    this.urlString,
    this.color,
    this.textStyle,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle.merge(
      style: (textStyle ?? const TextStyle()).copyWith(color: color),
      child: InkWell(
        borderRadius: borderRadius,
        onTap: onTap ?? () => AvesApp.launchUrl(urlString),
        child: Padding(
          padding: const EdgeInsets.all(8),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              if (leading != null) ...[
                leading!,
                const SizedBox(width: 8),
              ],
              Flexible(
                child: Text(
                  text,
                  softWrap: false,
                  overflow: TextOverflow.fade,
                  maxLines: 1,
                ),
              ),
              const SizedBox(width: 8),
              Builder(
                builder: (context) => Icon(
                  AIcons.openOutside,
                  size: DefaultTextStyle.of(context).style.fontSize,
                  color: color,
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}