git-touch-android-ios-app/lib/widgets/language_bar.dart

111 lines
3.2 KiB
Dart
Raw Permalink Normal View History

2022-09-18 14:37:33 +02:00
import 'package:antd_mobile/antd_mobile.dart';
2020-02-08 07:04:02 +01:00
import 'package:flutter/cupertino.dart';
2022-09-12 16:59:17 +02:00
import 'package:from_css_color/from_css_color.dart';
2020-02-08 07:04:02 +01:00
import 'package:git_touch/utils/utils.dart';
2020-10-08 08:49:46 +02:00
import 'package:github/github.dart' as github;
2020-02-08 07:04:02 +01:00
class LanguageBarItem {
LanguageBarItem({
2021-05-16 09:16:35 +02:00
required this.name,
required this.ratio,
String? hexColor,
}) : hexColor = hexColor ?? github.languageColors[name!];
2022-09-21 18:28:21 +02:00
String? name;
String? hexColor;
double? ratio;
2020-02-08 07:04:02 +01:00
}
class LanguageBar extends StatelessWidget {
2022-09-06 18:28:12 +02:00
const LanguageBar(this.items);
2022-09-21 18:28:21 +02:00
final List<LanguageBarItem> items;
2020-02-08 07:04:02 +01:00
2022-10-04 19:54:08 +02:00
static const _padding = 8.0;
2020-02-08 07:04:02 +01:00
@override
Widget build(BuildContext context) {
final langWidth = MediaQuery.of(context).size.width -
2022-10-04 19:54:08 +02:00
_padding * 2 - // left, right
(items.length - 1) - // space between items
1; // buffer for rounding
2020-02-08 07:04:02 +01:00
return CupertinoButton(
padding: EdgeInsets.zero,
minSize: 0,
2022-09-18 14:37:33 +02:00
onPressed: () async {
await AntPopup.show(
context: context,
closeOnMaskClick: true,
builder: _buildPopup,
);
2020-02-08 07:04:02 +01:00
},
2022-10-04 19:54:08 +02:00
child: Padding(
padding: const EdgeInsets.all(_padding),
2020-02-08 07:04:02 +01:00
child: ClipRRect(
2022-10-04 19:54:08 +02:00
borderRadius: BorderRadius.circular(100),
child: Wrap(
spacing: 1,
children: [
for (final lang in items)
Container(
color: fromCssColor(lang.hexColor!),
width: langWidth * lang.ratio!,
height: 12,
)
],
2020-02-08 07:04:02 +01:00
),
),
),
);
}
Widget _buildPopup(BuildContext context) {
return Container(
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorBackground,
2020-02-08 07:04:02 +01:00
padding: CommonStyle.padding,
height: 300,
child: SingleChildScrollView(
child: Table(children: [
for (final edge in items)
TableRow(children: [
Container(
padding: CommonStyle.padding,
child: Row(children: <Widget>[
Container(
width: 18,
height: 18,
decoration: BoxDecoration(
2022-09-12 16:59:17 +02:00
color: fromCssColor(edge.hexColor!),
2020-02-08 07:04:02 +01:00
shape: BoxShape.circle,
),
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 8),
2020-02-08 07:04:02 +01:00
Text(
2021-05-16 09:16:35 +02:00
edge.name!,
2020-02-08 07:04:02 +01:00
style: TextStyle(
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorText,
2020-02-08 07:04:02 +01:00
fontSize: 18,
2020-04-25 08:08:45 +02:00
decoration: TextDecoration.underline,
2022-09-24 20:46:37 +02:00
decorationColor: AntTheme.of(context).colorBackground,
2020-02-08 07:04:02 +01:00
),
),
]),
),
Container(
padding: CommonStyle.padding,
child: Text(
2021-05-16 09:16:35 +02:00
'${(edge.ratio! * 100).toStringAsFixed(1)}%',
2020-02-08 07:04:02 +01:00
style: TextStyle(
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorTextSecondary,
2020-02-08 07:04:02 +01:00
fontSize: 18,
2020-04-25 08:08:45 +02:00
decoration: TextDecoration.underline,
2022-09-24 20:46:37 +02:00
decorationColor: AntTheme.of(context).colorBackground,
2020-02-08 07:04:02 +01:00
),
),
),
])
]),
),
);
}
}