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 _getAvatar() async { if (await AuthGuard().isAuthorized()) { final profiles = await AuthGuard().readProfiles(); return CircleAvatar(backgroundImage: NetworkImage(profiles["picture"])); } else { return const CircleAvatar(child: Icon(Icons.account_circle)); } } Future _getDescribe() async { if (await AuthGuard().isAuthorized()) { final profiles = await AuthGuard().readProfiles(); 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 AuthGuard().isAuthorized() && onCheck != null) { onCheck!(); } else if (onLogin != null) { onLogin!(); } }, child: Padding( padding: const EdgeInsets.all(20), child: Row( children: [ FutureBuilder( future: _getAvatar(), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasData) { return snapshot.data!; } else { return const CircularProgressIndicator(); } }, ), const SizedBox(width: 20), FutureBuilder( future: _getDescribe(), builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasData) { return snapshot.data!; } else { return const Column(); } }, ) ], ), ), ), ); } }