import 'dart:ui' as ui; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:aslan/app_localizations.dart'; import 'package:aslan/chatvibe_ui/components/appbar/chatvibe_appbar.dart'; import 'package:aslan/chatvibe_ui/components/at_debounce_widget.dart'; import 'package:aslan/chatvibe_ui/components/at_compontent.dart'; import 'package:aslan/chatvibe_ui/components/text/at_text.dart'; import 'package:aslan/chatvibe_ui/components/at_tts.dart'; import 'package:aslan/chatvibe_core/routes/at_fluro_navigator.dart'; import 'package:aslan/chatvibe_core/utilities/at_loading_manager.dart'; import 'package:aslan/chatvibe_data/sources/local/user_manager.dart'; import 'package:provider/provider.dart'; import 'package:aslan/chatvibe_core/constants/at_screen.dart'; import 'package:aslan/chatvibe_core/utilities/at_pick_utils.dart'; import 'package:aslan/chatvibe_data/sources/repositories/family_repository_impl.dart'; import 'package:aslan/chatvibe_managers/user_profile_manager.dart'; import 'package:aslan/chatvibe_features/family/family_route.dart'; import '../../../chatvibe_data/models/enum/at_vip_type.dart'; import '../../../chatvibe_domain/usecases/at_accurate_length_limiting_textInput_formatter.dart'; import '../../../chatvibe_domain/usecases/at_custom_filtering_textinput_formatter.dart'; import '../../../chatvibe_domain/usecases/at_custom_filtering_textinput_formatter2.dart'; class CreateFamilyPage extends StatefulWidget { @override _CreateFamilyPageState createState() => _CreateFamilyPageState(); } class _CreateFamilyPageState extends State { TextEditingController familyNameController = TextEditingController(); TextEditingController familyInfoController = TextEditingController(); final int _familyNameMaxLength = 24; int _familyNameCurrentLength = 0; String familyCover = ""; final int _familyInfoMaxLength = 80; int _familyInfoCurrentLength = 0; bool isFreeCreate = false; @override void initState() { super.initState(); if (AccountStorage().getVIP()?.name == ATVIPType.DUKE.name || AccountStorage().getVIP()?.name == ATVIPType.KING.name || AccountStorage().getVIP()?.name == ATVIPType.EMPEROR.name) { isFreeCreate = true; } familyNameController.addListener(() { setState(() { _familyNameCurrentLength = _getActualCharacterCount( familyNameController.text, ); }); }); familyInfoController.addListener(() { setState(() { _familyInfoCurrentLength = _getActualCharacterCount( familyInfoController.text, ); }); }); } int _getActualCharacterCount(String text) { return text.characters.length; } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.transparent, resizeToAvoidBottomInset: true, body: SafeArea( top: false, child: LayoutBuilder( builder: (context, constraints) { return SingleChildScrollView( padding: EdgeInsets.only( bottom: MediaQuery.of(context).viewInsets.bottom, ), child: Stack( children: [ Image.asset( "atu_images/family/at_icon_family_head_bg.png", fit: BoxFit.fitWidth, ), PositionedDirectional( top: 11.w, child: ChatVibeStandardAppBar( actions: [], title: "", backButtonColor: Colors.white, ), ), Container( margin: EdgeInsets.only(top: 212.w), child: ClipRRect( borderRadius: BorderRadius.only( topLeft: Radius.circular(12.w), topRight: Radius.circular(12.w), ), child: BackdropFilter( filter: ui.ImageFilter.blur(sigmaX: 18, sigmaY: 18), child: Container( alignment: Alignment.center, color: Colors.white10, child: Column( children: [ SizedBox(height: 15.w), Row( mainAxisAlignment: MainAxisAlignment.center, children: [ text( ATAppLocalizations.of(context)!.createFamily, fontSize: 15.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), ], ), SizedBox(height: 20.w), ATDebounceWidget( child: Stack( alignment: Alignment.center, children: [ Image.asset( "atu_images/family/at_icon_create_family_camer.png", height: 85.w, ), familyCover.isNotEmpty ? netImage( url: familyCover, fit: BoxFit.cover, borderRadius: BorderRadius.all( Radius.circular(8.w), ), width: 85.w, height: 85.w, ) : Container(), ], ), onTap: () { ATPickUtils.pickImageProcess(aspectRatio: 1, context, ( bool success, String url, ) { if (success) { setState(() { familyCover = url; }); } }); }, ), SizedBox(height: 10.w), Row( children: [ SizedBox(width: 10.w), text( "*", textColor: Colors.red, fontSize: 13.sp, fontWeight: FontWeight.w600, ), text( "${ATAppLocalizations.of(context)!.familyName}:", textColor: Colors.white, fontSize: 14.sp, fontWeight: FontWeight.w600, ), ], ), SizedBox(height: 8.w), Container( margin: EdgeInsets.symmetric(horizontal: 15.w), // 外部容器用于实现渐变边框 decoration: BoxDecoration( borderRadius: BorderRadius.circular(8.w), // 渐变色边框 gradient: LinearGradient( colors: [ Color(0xffcecece), // 渐变色1 Color(0xff5b5b5b), // 渐变色2 Color(0xffcecece), // 渐变色3 ], begin: Alignment.topCenter, end: Alignment.bottomCenter, ), ), // 内部留白(边框宽度) padding: EdgeInsets.all(1.w), // 边框宽度 child: Container( padding: EdgeInsets.only( left: width(12), right: width(12), ), alignment: AlignmentDirectional.centerStart, height: 45.w, decoration: BoxDecoration( borderRadius: BorderRadius.circular(7.5.w), // 比外圆角小边框宽度 color: Colors.black87, // 背景色 ), child: TextField( controller: familyNameController, onChanged: (text) {}, inputFormatters: [ ATCustomFilteringTextInputFormatter(), ATAccurateLengthLimitingTextInputFormatter( _familyNameMaxLength, ), ], decoration: InputDecoration( hintText: ATAppLocalizations.of( context, )!.enterFamilyName, hintStyle: TextStyle( color: Colors.white, fontSize: 14.sp, ), contentPadding: EdgeInsets.only(top: 0.w), counterText: '', isDense: true, filled: false, focusColor: Colors.transparent, hoverColor: Colors.transparent, border: InputBorder.none, enabledBorder: InputBorder.none, focusedBorder: InputBorder.none, disabledBorder: InputBorder.none, errorBorder: InputBorder.none, focusedErrorBorder: InputBorder.none, suffix: Row( mainAxisSize: MainAxisSize.min, children: [ SizedBox(width: 3.w), text( '$_familyNameCurrentLength/$_familyNameMaxLength', textColor: Colors.white, ), ], ), ), style: TextStyle( fontSize: sp(14), color: Colors.white, textBaseline: TextBaseline.alphabetic, ), ), ), ), SizedBox(height: 10.w), Row( children: [ SizedBox(width: 10.w), text( "${ATAppLocalizations.of(context)!.familyInfo}:", textColor: Colors.white, fontSize: 14.sp, fontWeight: FontWeight.w600, ), ], ), SizedBox(height: 8.w), Container( margin: EdgeInsets.symmetric(horizontal: 15.w), // 外部容器用于实现渐变边框 decoration: BoxDecoration( borderRadius: BorderRadius.circular(8.w), // 渐变色边框 gradient: LinearGradient( colors: [ Color(0xffcecece), // 渐变色1 Color(0xff5b5b5b), // 渐变色2 Color(0xffcecece), // 渐变色3 ], begin: Alignment.topCenter, end: Alignment.bottomCenter, ), ), // 内部留白(边框宽度) padding: EdgeInsets.all(1.w), // 边框宽度 child: Stack( alignment: AlignmentDirectional.bottomEnd, children: [ Container( padding: EdgeInsets.only( top: width(12), left: width(12), right: width(12), ), alignment: AlignmentDirectional.topStart, height: 115.w, decoration: BoxDecoration( borderRadius: BorderRadius.circular( 7.5.w, ), // 比外圆角小边框宽度 color: Colors.black87, // 背景色 ), child: TextField( controller: familyInfoController, onChanged: (text) {}, inputFormatters: [ ATCustomFilteringTextInputFormatter2(), ATAccurateLengthLimitingTextInputFormatter( _familyInfoMaxLength, ), ], maxLines: 5, decoration: InputDecoration( hintText: ATAppLocalizations.of( context, )!.enterFamilyInfo, hintStyle: TextStyle( color: Colors.white, fontSize: 14.sp, ), contentPadding: EdgeInsets.only( top: 0.w, ), counterText: '', isDense: true, filled: false, focusColor: Colors.transparent, hoverColor: Colors.transparent, border: InputBorder.none, enabledBorder: InputBorder.none, focusedBorder: InputBorder.none, disabledBorder: InputBorder.none, errorBorder: InputBorder.none, focusedErrorBorder: InputBorder.none, suffix: Row( mainAxisSize: MainAxisSize.min, children: [SizedBox(width: 3.w)], ), ), style: TextStyle( fontSize: sp(14), color: Colors.white, textBaseline: TextBaseline.alphabetic, ), ), ), Row( mainAxisSize: MainAxisSize.min, children: [ text( '$_familyInfoCurrentLength/$_familyInfoMaxLength', textColor: Colors.white, ), SizedBox(width: 3.w), ], ), ], ), ), SizedBox(height: 15.w), ATDebounceWidget( debounceTime: Duration(milliseconds: 800), child: Container( width: 180.w, padding: EdgeInsets.symmetric(vertical: 12.w), decoration: BoxDecoration( borderRadius: BorderRadius.circular(60.w), gradient: _familyNameCurrentLength > 0 ? LinearGradient( colors: [ Color(0xff0D0022), Color(0xff9F63FF), ], begin: Alignment.topCenter, end: Alignment.bottomCenter, ) : LinearGradient( colors: [ Colors.white24, Colors.white24, ], begin: Alignment.topCenter, end: Alignment.bottomCenter, ), ), child: Column( children: [ text( ATAppLocalizations.of( context, )!.createFamily, fontSize: 15.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ), Row( mainAxisSize: MainAxisSize.min, children: [ Image.asset( "atu_images/general/at_icon_jb.png", width: 18.w, ), SizedBox(width: 2.w), isFreeCreate? text( "0", fontSize: 15.sp, fontWeight: FontWeight.w600, textColor: Colors.white, ):Container(), isFreeCreate? SizedBox(width: 5.w):Container(), text( "100000", fontSize: 15.sp, fontWeight: FontWeight.w600, textColor: Colors.white, decoration: isFreeCreate ? TextDecoration.lineThrough : TextDecoration.none, ), ], ), ], ), ), onTap: () { if (familyNameController.text.isEmpty) { ATTts.show( ATAppLocalizations.of( context, )!.enterFamilyName, ); return; } _submit(); }, ), SizedBox(height: 130.w), ], ), ), ), ), ), ], ), ); }, ), ), ); } void _submit() { if (familyCover.isEmpty) { familyCover = AccountStorage().getCurrentUser()?.userProfile?.userAvatar ?? ""; } ATLoadingManager.exhibitOperation(); GroupRepository() .createFamily( familyCover, familyNameController.text, familyInfoController.text, ) .then((result) { Provider.of( context, listen: false, ).updateFamily("${result}"); ATTts.show(ATAppLocalizations.of(context)!.createFamilySuccess); ATLoadingManager.veilRoutine(); ATNavigatorUtils.push( context, "${FamilyRoute.familyInfo}?familyId=$result", replace: true, ); }) .catchError((_) { ATLoadingManager.veilRoutine(); ATNavigatorUtils.goBack(context); }); } }