Skip to content

Commit

Permalink
Adjust language avatar sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
alkaitagi committed Jul 2, 2022
1 parent 0781c9b commit d9708d8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 34 deletions.
8 changes: 7 additions & 1 deletion lib/modules/dictionary/widgets/search_toolbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,13 @@ class SearchToolbarState extends State<SearchToolbar> {
OptionItem.divider(),
for (final l in GlobalStore.languages.keys)
OptionItem.tile(
LanguageAvatar(l),
Transform.scale(
scale: 1.5,
child: LanguageAvatar(
l,
radius: 12,
),
),
Text(
l.titled,
style: const TextStyle(fontWeight: FontWeight.w500),
Expand Down
10 changes: 6 additions & 4 deletions lib/modules/home/widgets/languages_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ class LanguagesMap extends StatelessWidget {
preferBelow: false,
child: InkWell(
onTap: () => onToggle(language),
child: LanguageAvatar(
null,
url: language.flag,
radius: 10,
child: Padding(
padding: const EdgeInsets.all(2),
child: LanguageAvatar(
null,
url: language.flag,
),
),
),
),
Expand Down
25 changes: 8 additions & 17 deletions lib/shared/widgets/language_avatar.dart
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
import 'package:avzag/store.dart';
import 'package:flutter/material.dart';

class LanguageAvatar extends StatefulWidget {
class LanguageAvatar extends StatelessWidget {
final String? language;
final String? url;
final double radius;
static const double R = 12;
final double? radius;

const LanguageAvatar(
this.language, {
this.url,
this.radius = 1.5 * R,
this.radius,
Key? key,
}) : super(key: key);

@override
State<LanguageAvatar> createState() => _LanguageAvatarState();
}

class _LanguageAvatarState extends State<LanguageAvatar> {
@override
Widget build(BuildContext context) {
final url = widget.url ?? GlobalStore.languages[widget.language]?.flag;
final url = this.url ?? GlobalStore.languages[language]?.flag;
if (url == null) return const Icon(Icons.flag_outlined);
return Transform.scale(
scale: widget.radius / LanguageAvatar.R,
child: CircleAvatar(
radius: LanguageAvatar.R,
backgroundImage: NetworkImage(url),
backgroundColor: Colors.transparent,
),
return CircleAvatar(
radius: radius,
backgroundImage: NetworkImage(url),
backgroundColor: Colors.transparent,
);
}
}
19 changes: 7 additions & 12 deletions lib/shared/widgets/language_flag.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'dart:math';
import 'package:avzag/store.dart';
import 'package:flutter/material.dart';

class LanguageFlag extends StatefulWidget {
class LanguageFlag extends StatelessWidget {
final String? language;
final String? url;
final double? width;
Expand All @@ -22,27 +22,22 @@ class LanguageFlag extends StatefulWidget {
Key? key,
}) : super(key: key);

@override
State<LanguageFlag> createState() => _LanguageFlagState();
}

class _LanguageFlagState extends State<LanguageFlag> {
@override
Widget build(BuildContext context) {
final url = widget.url ?? GlobalStore.languages[widget.language]?.flag;
final url = this.url ?? GlobalStore.languages[language]?.flag;
if (url == null) return const SizedBox();
return Transform.translate(
offset: widget.offset,
offset: offset,
child: Transform.rotate(
angle: widget.rotation,
angle: rotation,
child: Transform.scale(
scale: widget.scale,
scale: scale,
child: Image.network(
url,
repeat: ImageRepeat.repeatX,
fit: BoxFit.contain,
width: widget.width,
height: widget.height,
width: width,
height: height,
),
),
),
Expand Down

0 comments on commit d9708d8

Please sign in to comment.