150 lines
4.8 KiB
Dart
Executable File
150 lines
4.8 KiB
Dart
Executable File
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:trans_lark/generated/assets.dart';
|
|
import 'package:trans_lark/global/translate_language.dart';
|
|
import 'package:trans_lark/widget/language_bottom_sheet.dart';
|
|
|
|
class LanguageBar extends StatelessWidget {
|
|
const LanguageBar({
|
|
super.key,
|
|
this.isSelect = false,
|
|
this.onTapFrom,
|
|
this.onTapTo,
|
|
});
|
|
|
|
final bool isSelect;
|
|
final Function()? onTapFrom;
|
|
final Function()? onTapTo;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Row(
|
|
children: [
|
|
Expanded(
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
onTap: onTapFrom ?? _onTapFrom,
|
|
child: Obx(() {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
const SizedBox(width: 8),
|
|
Flexible(
|
|
child: Text(
|
|
TranslateLanguage().fromLanguageEntity.value.languageName,
|
|
style: TextStyle(
|
|
color: !isSelect || !TranslateLanguage().isSelectFromLanguage.value ? const Color(0xff435561) : const Color(0xff4ECA8C),
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 4),
|
|
Image.asset(
|
|
Assets.imagesToHomeBottom,
|
|
width: 8,
|
|
height: 8,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 20),
|
|
GestureDetector(
|
|
onTap: _exchangeOnTap,
|
|
child: Container(
|
|
width: 26,
|
|
height: 18,
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xffF1F1F1),
|
|
borderRadius: BorderRadius.circular(9),
|
|
),
|
|
child: FittedBox(
|
|
fit: BoxFit.none,
|
|
child: Image.asset(
|
|
Assets.imagesSwitchHomeIcon,
|
|
width: 12,
|
|
height: 12,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 20),
|
|
Expanded(
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
onTap: onTapTo ?? _onTapTo,
|
|
child: Obx(() {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 10),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
children: [
|
|
const SizedBox(width: 8),
|
|
Flexible(
|
|
child: Text(
|
|
TranslateLanguage().toLanguageEntity.value.languageName,
|
|
style: TextStyle(
|
|
color: !isSelect || TranslateLanguage().isSelectFromLanguage.value ? const Color(0xff435561) : const Color(0xff4ECA8C),
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w500,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 4),
|
|
Image.asset(
|
|
Assets.imagesToHomeBottom,
|
|
width: 8,
|
|
height: 8,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
void _exchangeOnTap() {
|
|
var tempLanguageCode = TranslateLanguage().toLanguageEntity.value.languageCode;
|
|
var tempLanguageName = TranslateLanguage().toLanguageEntity.value.languageName;
|
|
|
|
TranslateLanguage().toLanguageEntity.update((fn) {
|
|
fn?.languageCode = TranslateLanguage().fromLanguageEntity.value.languageCode;
|
|
fn?.languageName = TranslateLanguage().fromLanguageEntity.value.languageName;
|
|
});
|
|
TranslateLanguage().fromLanguageEntity.update((fn) {
|
|
fn?.languageCode = tempLanguageCode;
|
|
fn?.languageName = tempLanguageName;
|
|
});
|
|
}
|
|
|
|
void _onTapFrom() {
|
|
TranslateLanguage().isSelectFromLanguage.value = true;
|
|
Get.bottomSheet(
|
|
isScrollControlled: true,
|
|
const LanguageBottomSheet(),
|
|
);
|
|
}
|
|
|
|
void _onTapTo() {
|
|
TranslateLanguage().isSelectFromLanguage.value = false;
|
|
Get.bottomSheet(
|
|
isScrollControlled: true,
|
|
const LanguageBottomSheet(),
|
|
);
|
|
}
|
|
}
|