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

111 lines
3.3 KiB
Dart
Raw Normal View History

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/models/theme.dart';
import 'package:git_touch/utils/utils.dart';
2020-10-08 08:49:46 +02:00
import 'package:github/github.dart' as github;
2022-09-12 16:59:17 +02:00
import 'package:provider/provider.dart';
2020-02-08 07:04:02 +01:00
class LanguageBarItem {
2021-05-16 09:16:35 +02:00
String? name;
String? hexColor;
double? ratio;
2020-02-08 07:04:02 +01:00
LanguageBarItem({
2021-05-16 09:16:35 +02:00
required this.name,
required this.ratio,
String? hexColor,
}) : hexColor = hexColor ?? github.languageColors[name!];
2020-02-08 07:04:02 +01:00
}
class LanguageBar extends StatelessWidget {
final List<LanguageBarItem> items;
2022-09-06 18:28:12 +02:00
const LanguageBar(this.items);
2020-02-08 07:04:02 +01:00
@override
Widget build(BuildContext context) {
final langWidth = MediaQuery.of(context).size.width -
CommonStyle.padding.left -
CommonStyle.padding.right -
items.length +
1;
return CupertinoButton(
padding: EdgeInsets.zero,
minSize: 0,
onPressed: () {
showCupertinoModalPopup(context: context, builder: _buildPopup);
},
child: Container(
// color: theme.palette.background,
padding: CommonStyle.padding.copyWith(top: 8, bottom: 8),
child: ClipRRect(
borderRadius: BorderRadius.circular(5),
child: SizedBox(
height: 10,
child: Row(
children: join(
2022-09-06 18:28:12 +02:00
const SizedBox(width: 1),
2020-02-08 07:04:02 +01:00
items
.map((lang) => Container(
2022-09-12 16:59:17 +02:00
color: fromCssColor(lang.hexColor!),
2021-05-16 09:16:35 +02:00
width: langWidth * lang.ratio!))
2020-02-08 07:04:02 +01:00
.toList(),
),
),
),
),
),
);
}
Widget _buildPopup(BuildContext context) {
final theme = Provider.of<ThemeModel>(context);
return Container(
color: theme.palette.background,
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(
color: theme.palette.text,
fontSize: 18,
2020-04-25 08:08:45 +02:00
decoration: TextDecoration.underline,
decorationColor: theme.palette.background,
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(
color: theme.palette.secondaryText,
fontSize: 18,
2020-04-25 08:08:45 +02:00
decoration: TextDecoration.underline,
decorationColor: theme.palette.background,
2020-02-08 07:04:02 +01:00
),
),
),
])
]),
),
);
}
}