130 lines
4.0 KiB
Dart
130 lines
4.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:aslan/app_localizations.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:aslan/chatvibe_ui/components/appbar/chatvibe_appbar.dart';
|
|
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
|
|
import 'package:aslan/chatvibe_data/sources/local/data_persistence.dart';
|
|
import 'package:aslan/chatvibe_managers/localization_manager.dart';
|
|
import 'package:aslan/chatvibe_core/constants/at_global_config.dart';
|
|
|
|
///语言选择
|
|
class LanguagePage extends StatefulWidget {
|
|
const LanguagePage({super.key});
|
|
|
|
@override
|
|
State<LanguagePage> createState() => _LanguagePageState();
|
|
}
|
|
|
|
class _LanguagePageState extends State<LanguagePage> {
|
|
static const List<_LanguageOption> _languageOptions = [
|
|
_LanguageOption("English", "en"),
|
|
_LanguageOption("العربية", "ar"),
|
|
_LanguageOption("Türkçe", "tr"),
|
|
_LanguageOption("বাংলা", "bn"),
|
|
_LanguageOption("Bahasa Indonesia", "id"),
|
|
_LanguageOption("Filipino", "fil"),
|
|
_LanguageOption("اردو", "ur"),
|
|
_LanguageOption("हिन्दी", "hi"),
|
|
];
|
|
|
|
String _selectedLanguageCode = "en";
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
String langCode = DataPersistence.getLang();
|
|
if (_languageOptions.any((option) => option.languageCode == langCode)) {
|
|
_selectedLanguageCode = langCode;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
Image.asset(
|
|
ATGlobalConfig.businessLogicStrategy.getLanguagePageBackgroundImage(),
|
|
width: ScreenUtil().screenWidth,
|
|
height: ScreenUtil().screenHeight,
|
|
fit: BoxFit.fill,
|
|
),
|
|
Scaffold(
|
|
backgroundColor:
|
|
ATGlobalConfig.businessLogicStrategy
|
|
.getLanguagePageScaffoldBackgroundColor(),
|
|
resizeToAvoidBottomInset: false,
|
|
appBar: ChatVibeStandardAppBar(
|
|
title: ATAppLocalizations.of(context)!.language,
|
|
actions: [],
|
|
),
|
|
body: Column(
|
|
children: _languageOptions.map(_buildLanguageRow).toList(),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildLanguageRow(_LanguageOption option) {
|
|
return Row(
|
|
children: [
|
|
SizedBox(width: 15.w),
|
|
Expanded(
|
|
child: text(
|
|
option.title,
|
|
textColor:
|
|
ATGlobalConfig.businessLogicStrategy
|
|
.getLanguagePagePrimaryTextColor(),
|
|
fontSize: 15.sp,
|
|
),
|
|
),
|
|
Checkbox(
|
|
value: _selectedLanguageCode == option.languageCode,
|
|
checkColor:
|
|
ATGlobalConfig.businessLogicStrategy.getLanguagePageCheckColor(),
|
|
activeColor:
|
|
ATGlobalConfig.businessLogicStrategy
|
|
.getLanguagePageCheckboxActiveColor(),
|
|
onChanged: (b) {
|
|
if (b != true) {
|
|
return;
|
|
}
|
|
setState(() {
|
|
_selectedLanguageCode = option.languageCode;
|
|
});
|
|
Provider.of<LocalizationManager>(
|
|
context,
|
|
listen: false,
|
|
).setLocale(Locale(option.languageCode, ''));
|
|
},
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(
|
|
ATGlobalConfig.businessLogicStrategy
|
|
.getLanguagePageCheckboxBorderRadius(),
|
|
),
|
|
),
|
|
side: WidgetStateBorderSide.resolveWith((states) {
|
|
return BorderSide(
|
|
color:
|
|
ATGlobalConfig.businessLogicStrategy
|
|
.getLanguagePageCheckboxBorderColor(),
|
|
width:
|
|
ATGlobalConfig.businessLogicStrategy
|
|
.getLanguagePageCheckboxBorderWidth(),
|
|
);
|
|
}),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
class _LanguageOption {
|
|
final String title;
|
|
final String languageCode;
|
|
|
|
const _LanguageOption(this.title, this.languageCode);
|
|
}
|