import 'dart:async'; import 'package:flutter/material.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:go_router/go_router.dart'; import '/common/constants.dart'; import '/database/hive_database.dart'; import '/models/contact_model.dart'; import '/models/init_get_it.dart'; import '/models/route_state_model.dart'; import '/request/server.dart'; class FriendProfileScreen extends StatefulWidget { const FriendProfileScreen({ super.key, required this.friendId, }); final String friendId; @override State createState() => _FriendProfileScreenState(); } class _FriendProfileScreenState extends State { late final accountProfile = getIt.get().friends[widget.friendId]!.toMapCn(); late final _isOpen = List.generate(accountProfile.length, (index) => false); @override Widget build(BuildContext context) { Timer( const Duration(milliseconds: 300), () => getIt.get().changeRoute('FriendProfile'), ); String avatar = getIt.get().friends[widget.friendId]!.avatar; final List expansionList = []; var index = 0; accountProfile.forEach( (keyK, valueV) { expansionList.add( ExpansionPanel( headerBuilder: (context, isOpen) { return Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0), child: Text( keyK, style: const TextStyle(fontSize: 17), ), ), Expanded( child: Align( alignment: Alignment.centerRight, child: AnimatedSlide( offset: isOpen ? const Offset(0, 4) : Offset.zero, duration: const Duration(milliseconds: 170), child: AnimatedOpacity( opacity: isOpen ? 0 : 1, duration: const Duration(milliseconds: 120), child: Text( valueV, style: const TextStyle( color: kUnActivatedColor, fontSize: 17, overflow: TextOverflow.ellipsis, ), ), ), ), ), ), ], ); }, body: Align( alignment: Alignment.center, child: Padding( padding: const EdgeInsets.fromLTRB(8, 0, 55, 20), child: Text( valueV, textAlign: TextAlign.justify, style: const TextStyle( color: kUnActivatedColor, fontSize: 17, ), ), ), ), isExpanded: _isOpen[index], canTapOnHeader: true, ), ); index++; }, ); return Scaffold( body: Column( children: [ Expanded( child: CustomScrollView( physics: const AlwaysScrollableScrollPhysics(), slivers: [ SliverAppBar( expandedHeight: 240, floating: true, pinned: true, stretch: true, backgroundColor: Colors.orange, flexibleSpace: FlexibleSpaceBar( collapseMode: CollapseMode.pin, centerTitle: true, titlePadding: const EdgeInsets.only(left: 0, bottom: 15), stretchModes: const [ StretchMode.zoomBackground, StretchMode.blurBackground, StretchMode.fadeTitle, ], title: Text(getIt .get() .friends[widget.friendId]! .friendRemark .isEmpty ? accountProfile['名字']! : getIt .get() .friends[widget.friendId]! .friendRemark), background: Center( child: Material( elevation: 10.0, shape: const CircleBorder(), child: GestureDetector( onTap: () { context.pushNamed( 'FriendAvatar', queryParameters: {'avatar': avatar}, ); }, child: CircleAvatar( radius: 60, backgroundImage: CachedNetworkImageProvider( '$userAvatarsUrl/$avatar', ), ), ), ), ), ), ), SliverToBoxAdapter( child: ExpansionPanelList( expansionCallback: (i, isOpen) { setState(() { _isOpen[i] = isOpen; }); }, children: expansionList, ), ), ], ), ), Padding( padding: const EdgeInsets.symmetric(vertical: 8.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ OutlinedButton( onPressed: () { context.pushNamed('EditProfile'); }, style: OutlinedButton.styleFrom( fixedSize: const Size(130, 45), side: const BorderSide(color: kUnAvailableColor), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(6.0), ), ), child: const Text( '语音通话', style: TextStyle(fontSize: 18), ), ), OutlinedButton( onPressed: () { context.pushNamed( 'FriendSetting', queryParameters: {'friendId': widget.friendId}, ); }, style: OutlinedButton.styleFrom( fixedSize: const Size(100, 45), side: const BorderSide(color: kUnAvailableColor), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(6.0), ), ), child: const Text( '设置', style: TextStyle(fontSize: 18), ), ), FilledButton( onPressed: () async { await HiveDatabase.openMessageBox(widget.friendId); context.pushNamed( 'Message', queryParameters: { 'type': '0', 'friendId': widget.friendId, }, ); }, style: FilledButton.styleFrom( fixedSize: const Size(130, 45), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(6))), child: const Text( '发消息', style: TextStyle(fontSize: 18), ), ), ], ), ), ], ), ); } }