fix: Use animatedswitcher instead of crashing animatedcrossfade

pull/2139/head
krille-chan 2 months ago
parent 565926809d
commit 85139f533c
No known key found for this signature in database

@ -99,181 +99,189 @@ class NewPrivateChatView extends StatelessWidget {
), ),
), ),
Expanded( Expanded(
child: AnimatedCrossFade( child: AnimatedSwitcher(
duration: FluffyThemes.animationDuration, duration: FluffyThemes.animationDuration,
crossFadeState: searchResponse == null child: searchResponse == null
? CrossFadeState.showFirst ? ListView(
: CrossFadeState.showSecond, children: [
firstChild: ListView( Padding(
children: [ padding:
Padding( const EdgeInsets.symmetric(horizontal: 18.0),
padding: const EdgeInsets.symmetric(horizontal: 18.0), child: SelectableText.rich(
child: SelectableText.rich( TextSpan(
TextSpan( children: [
children: [ TextSpan(
TextSpan( text: L10n.of(context).yourGlobalUserIdIs,
text: L10n.of(context).yourGlobalUserIdIs, ),
), TextSpan(
TextSpan( text: Matrix.of(context).client.userID,
text: Matrix.of(context).client.userID, style: const TextStyle(
style: const TextStyle( fontWeight: FontWeight.w600,
fontWeight: FontWeight.w600,
),
),
],
),
style: TextStyle(
color: theme.colorScheme.onSurface,
fontSize: 12,
),
),
),
const SizedBox(height: 8),
ListTile(
leading: CircleAvatar(
backgroundColor: theme.colorScheme.secondaryContainer,
foregroundColor: theme.colorScheme.onSecondaryContainer,
child: Icon(Icons.adaptive.share_outlined),
),
title: Text(L10n.of(context).shareInviteLink),
onTap: controller.inviteAction,
),
ListTile(
leading: CircleAvatar(
backgroundColor: theme.colorScheme.tertiaryContainer,
foregroundColor: theme.colorScheme.onTertiaryContainer,
child: const Icon(Icons.group_add_outlined),
),
title: Text(L10n.of(context).createGroup),
onTap: () => context.go('/rooms/newgroup'),
),
if (PlatformInfos.isMobile)
ListTile(
leading: CircleAvatar(
backgroundColor: theme.colorScheme.primaryContainer,
foregroundColor: theme.colorScheme.onPrimaryContainer,
child: const Icon(Icons.qr_code_scanner_outlined),
),
title: Text(L10n.of(context).scanQrCode),
onTap: controller.openScannerAction,
),
Center(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 64.0,
vertical: 24.0,
),
child: Material(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(AppConfig.borderRadius),
side: BorderSide(
width: 3,
color: theme.colorScheme.primary,
),
),
color: Colors.transparent,
clipBehavior: Clip.hardEdge,
child: InkWell(
borderRadius:
BorderRadius.circular(AppConfig.borderRadius),
onTap: () => showQrCodeViewer(
context,
userId,
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: ConstrainedBox(
constraints:
const BoxConstraints(maxWidth: 200),
child: PrettyQrView.data(
data: 'https://matrix.to/#/$userId',
decoration: PrettyQrDecoration(
shape: PrettyQrSmoothSymbol(
roundFactor: 1,
color: theme.colorScheme.primary,
), ),
), ),
), ],
),
style: TextStyle(
color: theme.colorScheme.onSurface,
fontSize: 12,
), ),
), ),
), ),
), const SizedBox(height: 8),
), ListTile(
), leading: CircleAvatar(
], backgroundColor:
), theme.colorScheme.secondaryContainer,
secondChild: FutureBuilder( foregroundColor:
future: searchResponse, theme.colorScheme.onSecondaryContainer,
builder: (context, snapshot) { child: Icon(Icons.adaptive.share_outlined),
final result = snapshot.data;
final error = snapshot.error;
if (error != null) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
error.toLocalizedString(context),
textAlign: TextAlign.center,
style: TextStyle(
color: theme.colorScheme.error,
), ),
title: Text(L10n.of(context).shareInviteLink),
onTap: controller.inviteAction,
), ),
const SizedBox(height: 12), ListTile(
OutlinedButton.icon( leading: CircleAvatar(
onPressed: controller.searchUsers, backgroundColor:
icon: const Icon(Icons.refresh_outlined), theme.colorScheme.tertiaryContainer,
label: Text(L10n.of(context).tryAgain), foregroundColor:
theme.colorScheme.onTertiaryContainer,
child: const Icon(Icons.group_add_outlined),
),
title: Text(L10n.of(context).createGroup),
onTap: () => context.go('/rooms/newgroup'),
), ),
], if (PlatformInfos.isMobile)
); ListTile(
} leading: CircleAvatar(
if (result == null) { backgroundColor:
return const Center( theme.colorScheme.primaryContainer,
child: CircularProgressIndicator.adaptive(), foregroundColor:
); theme.colorScheme.onPrimaryContainer,
} child:
if (result.isEmpty) { const Icon(Icons.qr_code_scanner_outlined),
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.search_outlined, size: 86),
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
L10n.of(context).noUsersFoundWithQuery(
controller.controller.text,
), ),
style: TextStyle( title: Text(L10n.of(context).scanQrCode),
color: theme.colorScheme.primary, onTap: controller.openScannerAction,
),
Center(
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 64.0,
vertical: 24.0,
),
child: Material(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(
AppConfig.borderRadius,
),
side: BorderSide(
width: 3,
color: theme.colorScheme.primary,
),
),
color: Colors.transparent,
clipBehavior: Clip.hardEdge,
child: InkWell(
borderRadius: BorderRadius.circular(
AppConfig.borderRadius,
),
onTap: () => showQrCodeViewer(
context,
userId,
),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: ConstrainedBox(
constraints:
const BoxConstraints(maxWidth: 200),
child: PrettyQrView.data(
data: 'https://matrix.to/#/$userId',
decoration: PrettyQrDecoration(
shape: PrettyQrSmoothSymbol(
roundFactor: 1,
color: theme.colorScheme.primary,
),
),
),
),
),
),
), ),
textAlign: TextAlign.center,
), ),
), ),
], ],
); )
} : FutureBuilder(
return ListView.builder( future: searchResponse,
itemCount: result.length, builder: (context, snapshot) {
itemBuilder: (context, i) { final result = snapshot.data;
final contact = result[i]; final error = snapshot.error;
final displayname = contact.displayName ?? if (error != null) {
contact.userId.localpart ?? return Column(
contact.userId; mainAxisAlignment: MainAxisAlignment.center,
return ListTile( children: [
leading: Avatar( Text(
name: displayname, error.toLocalizedString(context),
mxContent: contact.avatarUrl, textAlign: TextAlign.center,
presenceUserId: contact.userId, style: TextStyle(
), color: theme.colorScheme.error,
title: Text(displayname), ),
subtitle: Text(contact.userId), ),
onTap: () => controller.openUserModal(contact), const SizedBox(height: 12),
); OutlinedButton.icon(
}, onPressed: controller.searchUsers,
); icon: const Icon(Icons.refresh_outlined),
}, label: Text(L10n.of(context).tryAgain),
), ),
],
);
}
if (result == null) {
return const Center(
child: CircularProgressIndicator.adaptive(),
);
}
if (result.isEmpty) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.search_outlined, size: 86),
Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
L10n.of(context).noUsersFoundWithQuery(
controller.controller.text,
),
style: TextStyle(
color: theme.colorScheme.primary,
),
textAlign: TextAlign.center,
),
),
],
);
}
return ListView.builder(
itemCount: result.length,
itemBuilder: (context, i) {
final contact = result[i];
final displayname = contact.displayName ??
contact.userId.localpart ??
contact.userId;
return ListTile(
leading: Avatar(
name: displayname,
mxContent: contact.avatarUrl,
presenceUserId: contact.userId,
),
title: Text(displayname),
subtitle: Text(contact.userId),
onTap: () => controller.openUserModal(contact),
);
},
);
},
),
), ),
), ),
], ],

@ -140,12 +140,9 @@ class _MxcImageState extends State<MxcImage> {
final data = _imageData; final data = _imageData;
final hasData = data != null && data.isNotEmpty; final hasData = data != null && data.isNotEmpty;
return AnimatedCrossFade( return AnimatedSwitcher(
crossFadeState:
hasData ? CrossFadeState.showSecond : CrossFadeState.showFirst,
duration: const Duration(milliseconds: 128), duration: const Duration(milliseconds: 128),
firstChild: placeholder(context), child: hasData
secondChild: hasData
? Image.memory( ? Image.memory(
data, data,
width: widget.width, width: widget.width,
@ -169,10 +166,7 @@ class _MxcImageState extends State<MxcImage> {
); );
}, },
) )
: SizedBox( : placeholder(context),
width: widget.width,
height: widget.height,
),
); );
} }
} }

Loading…
Cancel
Save