This repository has been archived on 2024-06-08. You can view files and clone it, but cannot push or open issues or pull requests.
SolarAgent/lib/widgets/name_card.dart
LittleSheep 8bb9c960c1 💄 Optimized notification page
⬇️ Remove firebase deps
2024-03-23 20:56:32 +08:00

102 lines
2.8 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import '../auth.dart';
class NameCard extends StatelessWidget {
const NameCard({super.key, this.onLogin, this.onCheck});
final void Function()? onLogin;
final void Function()? onCheck;
Future<CircleAvatar> _getAvatar() async {
if (await authClient.isAuthorized()) {
final profiles = await authClient.getProfiles();
return CircleAvatar(backgroundImage: NetworkImage(profiles["picture"]));
} else {
return const CircleAvatar(child: Icon(Icons.account_circle));
}
}
Future<Column> _getDescribe() async {
if (await authClient.isAuthorized()) {
final profiles = await authClient.getProfiles();
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
profiles["nick"],
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
Text(profiles["email"])
],
);
} else {
return const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Unauthorized",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
),
),
Text("Click here to login in.")
],
);
}
}
@override
Widget build(BuildContext context) {
return Card(
child: InkWell(
splashColor: Colors.indigo.withAlpha(30),
onTap: () async {
if (await authClient.isAuthorized() && onCheck != null) {
onCheck!();
} else if (onLogin != null) {
onLogin!();
}
},
child: Padding(
padding: const EdgeInsets.all(20),
child: Row(
children: [
FutureBuilder<CircleAvatar>(
future: _getAvatar(),
builder:
(BuildContext context, AsyncSnapshot<Widget> snapshot) {
if (snapshot.hasData) {
return snapshot.data!;
} else {
return const CircularProgressIndicator();
}
},
),
const SizedBox(width: 20),
FutureBuilder<Column>(
future: _getDescribe(),
builder:
(BuildContext context, AsyncSnapshot<Column> snapshot) {
if (snapshot.hasData) {
return snapshot.data!;
} else {
return const Column();
}
},
)
],
),
),
),
);
}
}