You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fluffychat/lib/pangea/pages/connect/p_sso_button.dart

87 lines
2.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:flutter_svg/svg.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pages/homeserver_picker/homeserver_picker.dart';
import 'package:fluffychat/widgets/matrix.dart';
class ButtonInfo {
String iconPath;
String text;
ButtonInfo(this.iconPath, this.text);
}
class PangeaSsoButton extends StatelessWidget {
final IdentityProvider identityProvider;
final void Function()? onPressed;
const PangeaSsoButton({
super.key,
required this.identityProvider,
this.onPressed,
});
ButtonInfo getButtonInfo(BuildContext context) {
switch (identityProvider.id) {
case "oidc-google":
return ButtonInfo(
"assets/pangea/google.svg",
"${L10n.of(context)!.loginOrSignup} Google",
);
case "oidc-apple":
return ButtonInfo(
"assets/pangea/apple.svg",
"${L10n.of(context)!.loginOrSignup} Apple",
);
default:
return ButtonInfo(
"assets/pangea/pangea.svg",
"${L10n.of(context)!.loginOrSignup} Pangea Chat",
);
}
}
@override
Widget build(BuildContext context) {
final ButtonInfo buttonInfo = getButtonInfo(context);
return ElevatedButton(
onPressed: onPressed,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
identityProvider.icon == null
? SvgPicture.asset(
buttonInfo.iconPath,
height: 20,
width: 20,
color: Theme.of(context).brightness == Brightness.light
? AppConfig.primaryColor
: AppConfig.primaryColorLight,
)
: Image.network(
Uri.parse(identityProvider.icon!)
.getDownloadLink(Matrix.of(context).getLoginClient())
.toString(),
width: 32,
height: 32,
),
// #Pangea
Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: Text(
identityProvider.name != null
? buttonInfo.text
: (identityProvider.brand != null
? L10n.of(context)!.loginOrSignup
: L10n.of(context)!.loginOrSignup),
),
),
],
),
);
}
}