From c319bfb4d1ae6cff02e3cc2289f3565c05db3aa3 Mon Sep 17 00:00:00 2001 From: shiki-tak Date: Thu, 18 Jul 2024 18:40:59 +0900 Subject: [PATCH] fix: apply review --- .../controller/authentication_service.dart | 18 ++++--- flutter_bird_app/lib/main.dart | 7 +-- flutter_bird_app/lib/view/main_menu_view.dart | 54 +++++++++---------- 3 files changed, 38 insertions(+), 41 deletions(-) diff --git a/flutter_bird_app/lib/controller/authentication_service.dart b/flutter_bird_app/lib/controller/authentication_service.dart index 5ec98a9..31790c2 100644 --- a/flutter_bird_app/lib/controller/authentication_service.dart +++ b/flutter_bird_app/lib/controller/authentication_service.dart @@ -9,10 +9,12 @@ import 'package:http/http.dart' as http; import 'package:nonce/nonce.dart'; import 'package:url_launcher/url_launcher.dart'; import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; import '../model/account.dart'; import '../model/wallet_provider.dart'; +/// Manages the authentication process and communication with crypto wallets abstract class AuthenticationService { Future initialize(bool isInLiff); @@ -41,7 +43,7 @@ class AuthenticationServiceImpl implements AuthenticationService { final Function() onAuthStatusChanged; WalletProvider? _lastUsedWallet; - static const String projectId = String.fromEnvironment('WALLET_CONNECT_PROJECT_ID'); + String projectId = dotenv.env['WALLET_CONNECT_PROJECT_ID'] ?? ''; AuthenticationServiceImpl({ required this.isInLiff, @@ -69,9 +71,9 @@ class AuthenticationServiceImpl implements AuthenticationService { @override bool get isAuthenticated => isConnected && authenticatedAccount != null; + // The data to display in a QR Code for connections on Desktop / Browser. @override - String? get webQrData => _webQrData; - String? _webQrData; + String? webQrData; WalletProvider? get lastUsedWallet => _lastUsedWallet; @@ -153,7 +155,7 @@ class AuthenticationServiceImpl implements AuthenticationService { if (uri != null) { // Web if (kIsWeb && !isInLiff) { - _webQrData = uri.toString(); + webQrData = uri.toString(); onAuthStatusChanged(); // LIFF } else if(kIsWeb && isInLiff) { @@ -246,7 +248,7 @@ class AuthenticationServiceImpl implements AuthenticationService { } _authenticatedAccount = null; _connector = null; - _webQrData = null; + webQrData = null; } Future _createConnector({WalletProvider? walletProvider}) async { @@ -267,7 +269,7 @@ class AuthenticationServiceImpl implements AuthenticationService { if (!isInLiff) { log('connected: ' + session.toString(), name: 'AuthenticationService'); String? address = session?.session.namespaces['eip155']?.accounts.first.split(':').last; - _webQrData = null; + webQrData = null; final authenticated = await _verifySignature(walletProvider: walletProvider, address: address); if (authenticated) log('authenticated successfully: ' + session.toString(), name: 'AuthenticationService'); onAuthStatusChanged(); @@ -275,12 +277,12 @@ class AuthenticationServiceImpl implements AuthenticationService { }); _connector?.onSessionUpdate.subscribe((SessionUpdate? payload) async { log('session_update: ' + payload.toString(), name: 'AuthenticationService'); - _webQrData = null; + webQrData = null; onAuthStatusChanged(); }); _connector?.onSessionDelete.subscribe((SessionDelete? session) { log('disconnect: ' + session.toString(), name: 'AuthenticationService'); - _webQrData = null; + webQrData = null; _authenticatedAccount = null; onAuthStatusChanged(); }); diff --git a/flutter_bird_app/lib/main.dart b/flutter_bird_app/lib/main.dart index 54ca939..0417545 100644 --- a/flutter_bird_app/lib/main.dart +++ b/flutter_bird_app/lib/main.dart @@ -8,14 +8,9 @@ import 'package:flutter_line_liff/flutter_line_liff.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); - if (const String.fromEnvironment('FLUTTER_ENV') != 'production') { - await dotenv.load(fileName: ".env"); - } + await dotenv.load(fileName: ".env"); print("Starting application..."); - const String liffId = String.fromEnvironment('LIFF_ID'); - - final String? os = FlutterLineLiff().os; final bool isInClient = FlutterLineLiff().isInClient; runApp(MyApp(isInClient: isInClient)); } diff --git a/flutter_bird_app/lib/view/main_menu_view.dart b/flutter_bird_app/lib/view/main_menu_view.dart index 315d1cd..10e6778 100644 --- a/flutter_bird_app/lib/view/main_menu_view.dart +++ b/flutter_bird_app/lib/view/main_menu_view.dart @@ -77,35 +77,35 @@ class _MainMenuViewState extends State with AutomaticKeepAliveClie birdSize = worldDimensions.height / 8; try { - return Scaffold( - body: Consumer(builder: (context, web3Service, child) { - web3Service.authorizeUser(); - if (web3Service.skins != null) { - birds = [ - const Bird(), - ...web3Service.skins!.map((e) => Bird( - skin: e, - )) - ]; - if (web3Service.skins!.length < selectedBird) { - selectedBird = web3Service.skins!.length; + return Scaffold( + body: Consumer(builder: (context, web3Service, child) { + web3Service.authorizeUser(); + if (web3Service.skins != null) { + birds = [ + const Bird(), + ...web3Service.skins!.map((e) => Bird( + skin: e, + )) + ]; + if (web3Service.skins!.length < selectedBird) { + selectedBird = web3Service.skins!.length; + } + } else { + selectedBird = 0; } - } else { - selectedBird = 0; - } - return Center( - child: ConstrainedBox( - constraints: BoxConstraints(maxWidth: maxWidth), - child: Stack(alignment: Alignment.center, children: [ - const Background(), - _buildBirdSelector(web3Service), - _buildMenu(web3Service), - ]), - ), - ); - }), - ); + return Center( + child: ConstrainedBox( + constraints: BoxConstraints(maxWidth: maxWidth), + child: Stack(alignment: Alignment.center, children: [ + const Background(), + _buildBirdSelector(web3Service), + _buildMenu(web3Service), + ]), + ), + ); + }), + ); } catch(e, stackTrace) { print("Error in MainMenuView: $e"); print("StackTrace: $stackTrace");