fix: Use animatedswitcher instead of crashing animatedcrossfade
This commit is contained in:
parent
565926809d
commit
85139f533c
2 changed files with 172 additions and 170 deletions
|
|
@ -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,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
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,
|
const SizedBox(height: 8),
|
||||||
clipBehavior: Clip.hardEdge,
|
ListTile(
|
||||||
child: InkWell(
|
leading: CircleAvatar(
|
||||||
borderRadius:
|
backgroundColor:
|
||||||
BorderRadius.circular(AppConfig.borderRadius),
|
theme.colorScheme.secondaryContainer,
|
||||||
onTap: () => showQrCodeViewer(
|
foregroundColor:
|
||||||
context,
|
theme.colorScheme.onSecondaryContainer,
|
||||||
userId,
|
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(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(16.0),
|
padding: const EdgeInsets.symmetric(
|
||||||
child: ConstrainedBox(
|
horizontal: 64.0,
|
||||||
constraints:
|
vertical: 24.0,
|
||||||
const BoxConstraints(maxWidth: 200),
|
),
|
||||||
child: PrettyQrView.data(
|
child: Material(
|
||||||
data: 'https://matrix.to/#/$userId',
|
shape: RoundedRectangleBorder(
|
||||||
decoration: PrettyQrDecoration(
|
borderRadius: BorderRadius.circular(
|
||||||
shape: PrettyQrSmoothSymbol(
|
AppConfig.borderRadius,
|
||||||
roundFactor: 1,
|
),
|
||||||
color: theme.colorScheme.primary,
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
|
)
|
||||||
|
: FutureBuilder(
|
||||||
|
future: searchResponse,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
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,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
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),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
secondChild: FutureBuilder(
|
|
||||||
future: searchResponse,
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
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,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
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…
Add table
Add a link
Reference in a new issue