diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..61b6c4d --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/android/app/build.gradle b/android/app/build.gradle index c892da8..a1989bf 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -66,6 +66,9 @@ android { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug + useProguard true + + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } diff --git a/android/app/proguard-rules.pro b/android/app/proguard-rules.pro new file mode 100644 index 0000000..3df0b1b --- /dev/null +++ b/android/app/proguard-rules.pro @@ -0,0 +1,7 @@ +-ignorewarnings +-keep class * { + public private *; +} +-dontwarn org.xmlpull.v1.XmlPullParser +-dontwarn org.xmlpull.v1.XmlSerializer +-keep class org.xmlpull.v1.* {*;} \ No newline at end of file diff --git a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png index 60901ac..8dae5e0 100644 Binary files a/android/app/src/main/res/mipmap-hdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png index a15ff51..5966d5e 100644 Binary files a/android/app/src/main/res/mipmap-mdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png index 0546f44..a3fc369 100644 Binary files a/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png index 46d85b5..51afdd6 100644 Binary files a/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png index 6620934..4868adc 100644 Binary files a/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png and b/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/assets/avatars/0.png b/assets/avatars/0.png new file mode 100755 index 0000000..452efff Binary files /dev/null and b/assets/avatars/0.png differ diff --git a/assets/avatars/1.png b/assets/avatars/1.png new file mode 100755 index 0000000..26b5786 Binary files /dev/null and b/assets/avatars/1.png differ diff --git a/assets/avatars/2.png b/assets/avatars/2.png new file mode 100755 index 0000000..9271e58 Binary files /dev/null and b/assets/avatars/2.png differ diff --git a/assets/avatars/3.png b/assets/avatars/3.png new file mode 100755 index 0000000..47e563e Binary files /dev/null and b/assets/avatars/3.png differ diff --git a/assets/avatars/trunc/0.png b/assets/avatars/trunc/0.png new file mode 100755 index 0000000..c379552 Binary files /dev/null and b/assets/avatars/trunc/0.png differ diff --git a/assets/avatars/trunc/1.png b/assets/avatars/trunc/1.png new file mode 100755 index 0000000..49023c9 Binary files /dev/null and b/assets/avatars/trunc/1.png differ diff --git a/assets/avatars/trunc/2.png b/assets/avatars/trunc/2.png new file mode 100755 index 0000000..f9546ef Binary files /dev/null and b/assets/avatars/trunc/2.png differ diff --git a/assets/chests/0.png b/assets/chests/0.png new file mode 100755 index 0000000..71dcb9b Binary files /dev/null and b/assets/chests/0.png differ diff --git a/assets/chests/1.png b/assets/chests/1.png new file mode 100644 index 0000000..327ce15 Binary files /dev/null and b/assets/chests/1.png differ diff --git a/assets/chests/2.png b/assets/chests/2.png new file mode 100644 index 0000000..bfb1a08 Binary files /dev/null and b/assets/chests/2.png differ diff --git a/assets/chests/3.png b/assets/chests/3.png new file mode 100644 index 0000000..fb93100 Binary files /dev/null and b/assets/chests/3.png differ diff --git a/assets/chests/4.png b/assets/chests/4.png new file mode 100644 index 0000000..a759503 Binary files /dev/null and b/assets/chests/4.png differ diff --git a/assets/chests/5.png b/assets/chests/5.png new file mode 100644 index 0000000..84d1490 Binary files /dev/null and b/assets/chests/5.png differ diff --git a/assets/chests/6.png b/assets/chests/6.png new file mode 100644 index 0000000..8f1556b Binary files /dev/null and b/assets/chests/6.png differ diff --git a/assets/chests/7.png b/assets/chests/7.png new file mode 100644 index 0000000..c34e084 Binary files /dev/null and b/assets/chests/7.png differ diff --git a/assets/chests/cesium.png b/assets/chests/cesium.png new file mode 100755 index 0000000..f3028ac Binary files /dev/null and b/assets/chests/cesium.png differ diff --git a/assets/chests/config.png b/assets/chests/config.png new file mode 100755 index 0000000..0bc4da7 Binary files /dev/null and b/assets/chests/config.png differ diff --git a/assets/chests/miniChests.png b/assets/chests/miniChests.png new file mode 100755 index 0000000..8d37185 Binary files /dev/null and b/assets/chests/miniChests.png differ diff --git a/assets/chests/secret_code.png b/assets/chests/secret_code.png new file mode 100755 index 0000000..10ef999 Binary files /dev/null and b/assets/chests/secret_code.png differ diff --git a/assets/chests/vector.png b/assets/chests/vector.png new file mode 100755 index 0000000..3fb42db Binary files /dev/null and b/assets/chests/vector.png differ diff --git a/assets/icon/gecko_final.png b/assets/icon/gecko_final.png old mode 100644 new mode 100755 index e76f049..553d314 Binary files a/assets/icon/gecko_final.png and b/assets/icon/gecko_final.png differ diff --git a/assets/icon/gecko_flat.png b/assets/icon/gecko_flat.png new file mode 100755 index 0000000..54804fc Binary files /dev/null and b/assets/icon/gecko_flat.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png index 128044b..a65cade 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-1024x1024@1x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png index c40dfa7..c081abb 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@1x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png index 5c7f3a5..bdb5fed 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@2x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png index 198bcee..9708740 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-20x20@3x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png index d57b328..3b4e54e 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@1x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png index 7f14b93..0506604 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@2x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png index ba72d26..7168d21 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-29x29@3x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png index 5c7f3a5..bdb5fed 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@1x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png index 5b5fe58..475acee 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@2x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png index b05ef17..9ed9156 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-40x40@3x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png index b05ef17..9ed9156 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@2x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png index f13dd04..3f1ee21 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-60x60@3x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png index d0e5fc0..f32e892 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@1x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png index 8ff9644..f6dd010 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-76x76@2x.png differ diff --git a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png index c347088..97d30a6 100644 Binary files a/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png and b/ios/Runner/Assets.xcassets/AppIcon.appiconset/Icon-App-83.5x83.5@2x.png differ diff --git a/lib/globals.dart b/lib/globals.dart index 8953573..115be3d 100644 --- a/lib/globals.dart +++ b/lib/globals.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:flutter/material.dart'; -import 'package:gecko/models/walletData.dart'; +import 'package:gecko/models/chest_data.dart'; +import 'package:gecko/models/wallet_data.dart'; import 'package:hive/hive.dart'; import 'package:logger/logger.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -8,13 +9,12 @@ import 'package:shared_preferences/shared_preferences.dart'; // Files paths Directory appPath; -WalletData defaultWallet; String appVersion; SharedPreferences prefs; String endPointGVA; int ramSys; Box walletBox; -Box chestBox; +Box chestBox; Box configBox; // String cesiumPod = "https://g1.data.le-sou.org"; @@ -28,7 +28,7 @@ double ratio; var log = Logger(); // Colors -Color orangeC = Color(0xffD28928); -Color yellowC = Color(0xffFFD68E); -Color floattingYellow = Color(0xffEFEFBF); -Color backgroundColor = Color(0xFFF5F5F5); +Color orangeC = const Color(0xffd07316); +Color yellowC = const Color(0xffFFD68E); +Color floattingYellow = const Color(0xffEFEFBF); +Color backgroundColor = const Color(0xFFF5F5F5); diff --git a/lib/main.dart b/lib/main.dart index 2af5d1e..d53b367 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -13,21 +13,26 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . +// ignore_for_file: avoid_print + import 'dart:async'; +import 'dart:io'; import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/models/cesiumPlus.dart'; -import 'package:gecko/models/changePin.dart'; -import 'package:gecko/models/generateWallets.dart'; +import 'package:gecko/models/cesium_plus.dart'; +import 'package:gecko/models/change_pin.dart'; +import 'package:gecko/models/chest_data.dart'; +import 'package:gecko/models/chest_provider.dart'; +import 'package:gecko/models/generate_wallets.dart'; import 'package:gecko/models/history.dart'; import 'package:gecko/models/home.dart'; -import 'package:gecko/models/myWallets.dart'; -import 'package:gecko/models/walletData.dart'; -import 'package:gecko/models/walletOptions.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/models/wallet_data.dart'; +import 'package:gecko/models/wallet_options.dart'; import 'package:gecko/screens/home.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:gecko/screens/myWallets/walletsHome.dart'; +import 'package:gecko/screens/myWallets/wallets_home.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:hive_flutter/hive_flutter.dart'; import 'package:path_provider/path_provider.dart'; @@ -36,14 +41,15 @@ import 'package:flutter/foundation.dart'; import 'package:responsive_framework/responsive_framework.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; +import 'package:flutter_driver/driver_extension.dart'; -final bool enableSentry = true; +const bool enableSentry = true; Future main() async { + enableFlutterDriverExtension(); WidgetsFlutterBinding.ensureInitialized(); HomeProvider _homeProvider = HomeProvider(); - MyWalletsProvider _walletsProvider = MyWalletsProvider(); appPath = await getApplicationDocumentsDirectory(); await _homeProvider.createDefaultAvatar(); appVersion = await _homeProvider.getAppVersion(); @@ -52,12 +58,11 @@ Future main() async { // Configure Hive and open boxes await Hive.initFlutter(appPath.path); Hive.registerAdapter(WalletDataAdapter()); + Hive.registerAdapter(ChestDataAdapter()); walletBox = await Hive.openBox("walletBox"); - chestBox = await Hive.openBox("chestBox"); + chestBox = await Hive.openBox("chestBox"); configBox = await Hive.openBox("configBox"); - _walletsProvider.getDefaultWallet(); - // final HiveStore _store = // await HiveStore.open(path: '${appPath.path}/gqlCache'); @@ -102,12 +107,14 @@ Future main() async { } else { print('Debug mode enabled: No sentry alerte'); + HttpOverrides.global = MyHttpOverrides(); + runApp(Gecko(endPointGVA)); } } class Gecko extends StatelessWidget { - Gecko(this.randomEndpoint); + const Gecko(this.randomEndpoint, {Key key}) : super(key: key); final String randomEndpoint; @override @@ -132,6 +139,7 @@ class Gecko extends StatelessWidget { ChangeNotifierProvider(create: (_) => HomeProvider()), ChangeNotifierProvider(create: (_) => HistoryProvider('')), ChangeNotifierProvider(create: (_) => MyWalletsProvider()), + ChangeNotifierProvider(create: (_) => ChestProvider()), ChangeNotifierProvider(create: (_) => GenerateWalletsProvider()), ChangeNotifierProvider(create: (_) => WalletOptionsProvider()), ChangeNotifierProvider(create: (_) => ChangePinProvider()), @@ -146,28 +154,28 @@ class Gecko extends StatelessWidget { minWidth: 480, defaultScale: true, breakpoints: [ - ResponsiveBreakpoint.resize(480, name: MOBILE), - ResponsiveBreakpoint.autoScale(800, name: TABLET), - ResponsiveBreakpoint.resize(1000, name: DESKTOP), + const ResponsiveBreakpoint.resize(480, name: MOBILE), + const ResponsiveBreakpoint.autoScale(800, name: TABLET), + const ResponsiveBreakpoint.resize(1000, name: DESKTOP), ], background: Container(color: backgroundColor)), title: 'Ğecko', theme: ThemeData( - appBarTheme: AppBarTheme( - color: const Color(0xffFFD58D), - foregroundColor: const Color(0xFF000000), + appBarTheme: const AppBarTheme( + color: Color(0xffFFD58D), + foregroundColor: Color(0xFF000000), ), - primaryColor: Color(0xffFFD58D), - textTheme: TextTheme( + primaryColor: const Color(0xffFFD58D), + textTheme: const TextTheme( bodyText1: TextStyle(), bodyText2: TextStyle(), ).apply( - bodyColor: Color(0xff855F2D), + bodyColor: const Color(0xFF000000), ), colorScheme: ColorScheme.fromSwatch() .copyWith(secondary: Colors.grey[850]), ), - home: HomeScreen(), + home: const HomeScreen(), initialRoute: "/", routes: { '/mywallets': (context) => WalletsHome(), @@ -176,3 +184,13 @@ class Gecko extends StatelessWidget { )); } } + +// This http overriding is needed to fix fail certifcat checking for Duniter node on old Android version +class MyHttpOverrides extends HttpOverrides { + @override + HttpClient createHttpClient(SecurityContext context) { + return super.createHttpClient(context) + ..badCertificateCallback = + (X509Certificate cert, String host, int port) => true; + } +} diff --git a/lib/models/cesiumPlus.dart b/lib/models/cesium_plus.dart similarity index 96% rename from lib/models/cesiumPlus.dart rename to lib/models/cesium_plus.dart index 47ebef1..8d73d00 100644 --- a/lib/models/cesiumPlus.dart +++ b/lib/models/cesium_plus.dart @@ -7,10 +7,6 @@ import 'package:http/http.dart' as http; import 'package:path_provider/path_provider.dart'; class CesiumPlusProvider with ChangeNotifier { - // String pubkey = ''; - // CesiumPlusProvider(this.pubkey); - var decodedBytes; - var avatar64; TextEditingController cesiumName = TextEditingController(); int iAvatar = 0; bool isComplete = false; diff --git a/lib/models/changePin.dart b/lib/models/changePin.dart deleted file mode 100644 index 5af359a..0000000 --- a/lib/models/changePin.dart +++ /dev/null @@ -1,38 +0,0 @@ -import 'package:dubp/dubp.dart'; -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'dart:async'; -import 'package:gecko/globals.dart'; - -class ChangePinProvider with ChangeNotifier { - bool ischangedPin = false; - TextEditingController newPin = new TextEditingController(); - - Future get badWallet => null; - - Future changePin(_name, _oldPin) async { - try { - final _dewif = chestBox.get(0); - - NewWallet newWalletFile = await DubpRust.changeDewifPin( - dewif: _dewif, - oldPin: _oldPin, - ); - - newPin.text = newWalletFile.pin; - ischangedPin = true; - notifyListeners(); - return newWalletFile; - } catch (e) { - log.e('Impossible de changer le code PIN.'); - return badWallet; - } - } - - Future storeWallet(context, _name, NewWallet _newWalletFile) async { - chestBox.put(0, _newWalletFile.dewif); - - Navigator.pop(context); - return _name; - } -} diff --git a/lib/models/change_pin.dart b/lib/models/change_pin.dart new file mode 100644 index 0000000..cb31cca --- /dev/null +++ b/lib/models/change_pin.dart @@ -0,0 +1,43 @@ +import 'package:dubp/dubp.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'dart:async'; +import 'package:gecko/globals.dart'; + +class ChangePinProvider with ChangeNotifier { + bool ischangedPin = false; + TextEditingController newPin = TextEditingController(); + String pinToGive; + + Future get badWallet => null; + + Future changePin(String _oldPin) async { + try { + final _dewif = chestBox.get(configBox.get('currentChest')).dewif; + + NewWallet newWalletFile = await DubpRust.changeDewifPin( + dewif: _dewif, + oldPin: _oldPin.toUpperCase(), + ); + + newPin.text = pinToGive = newWalletFile.pin; + ischangedPin = true; + notifyListeners(); + return newWalletFile; + } catch (e) { + log.e('Impossible de changer le code PIN.'); + return badWallet; + } + } + + void storeNewPinChest(context, NewWallet _newWalletFile) { + // ChestData currentChest = chestBox.getAt(configBox.get('currentChest')); + // currentChest.dewif = _newWalletFile.dewif; + // await chestBox.add(currentChest); + + chestBox.get(configBox.get('currentChest')).dewif = _newWalletFile.dewif; + + Navigator.pop(context, pinToGive); + pinToGive = ''; + } +} diff --git a/lib/models/chest_data.dart b/lib/models/chest_data.dart new file mode 100644 index 0000000..9e01d9a --- /dev/null +++ b/lib/models/chest_data.dart @@ -0,0 +1,40 @@ +import 'dart:io'; + +import 'package:hive_flutter/hive_flutter.dart'; + +part 'chest_data.g.dart'; + +@HiveType(typeId: 1) +class ChestData extends HiveObject { + @HiveField(0) + String dewif; + + @HiveField(2) + String name; + + @HiveField(3) + int defaultWallet; + + @HiveField(4) + String imageName; + + @HiveField(5) + File imageFile; + + @HiveField(6) + bool isCesium; + + ChestData({ + this.dewif, + this.name, + this.defaultWallet, + this.imageName, + this.imageFile, + this.isCesium, + }); + + @override + String toString() { + return name; + } +} diff --git a/lib/models/chest_data.g.dart b/lib/models/chest_data.g.dart new file mode 100644 index 0000000..1d0be58 --- /dev/null +++ b/lib/models/chest_data.g.dart @@ -0,0 +1,56 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'chest_data.dart'; + +// ************************************************************************** +// TypeAdapterGenerator +// ************************************************************************** + +class ChestDataAdapter extends TypeAdapter { + @override + final int typeId = 1; + + @override + ChestData read(BinaryReader reader) { + final numOfFields = reader.readByte(); + final fields = { + for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(), + }; + return ChestData( + dewif: fields[0] as String, + name: fields[2] as String, + defaultWallet: fields[3] as int, + imageName: fields[4] as String, + imageFile: fields[5] as File, + isCesium: fields[6] as bool, + ); + } + + @override + void write(BinaryWriter writer, ChestData obj) { + writer + ..writeByte(6) + ..writeByte(0) + ..write(obj.dewif) + ..writeByte(2) + ..write(obj.name) + ..writeByte(3) + ..write(obj.defaultWallet) + ..writeByte(4) + ..write(obj.imageName) + ..writeByte(5) + ..write(obj.imageFile) + ..writeByte(6) + ..write(obj.isCesium); + } + + @override + int get hashCode => typeId.hashCode; + + @override + bool operator ==(Object other) => + identical(this, other) || + other is ChestDataAdapter && + runtimeType == other.runtimeType && + typeId == other.typeId; +} diff --git a/lib/models/chest_provider.dart b/lib/models/chest_provider.dart new file mode 100644 index 0000000..748315b --- /dev/null +++ b/lib/models/chest_provider.dart @@ -0,0 +1,57 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:gecko/globals.dart'; +import 'package:gecko/models/chest_data.dart'; + +class ChestProvider with ChangeNotifier { + void rebuildWidget() { + notifyListeners(); + } + + Future deleteChest(context, ChestData _chest) async { + final bool _answer = await _confirmDeletingChest(context, _chest.name); + + if (_answer) { + await chestBox.delete(_chest.key); + if (chestBox.isEmpty) { + await configBox.put('currentChest', 0); + } else { + int lastChest = chestBox.toMap().keys.first; + await configBox.put('currentChest', lastChest); + } + + Navigator.popUntil( + context, + ModalRoute.withName('/'), + ); + notifyListeners(); + } + } + + Future _confirmDeletingChest(context, String _walletName) async { + return showDialog( + context: context, + barrierDismissible: true, // user must tap button! + builder: (BuildContext context) { + return AlertDialog( + title: Text( + 'Êtes-vous sûr de vouloir supprimer le coffre "$_walletName" ?'), + actions: [ + TextButton( + child: const Text("Non", key: Key('cancelDeleting')), + onPressed: () { + Navigator.pop(context, false); + }, + ), + TextButton( + child: const Text("Oui", key: Key('confirmDeleting')), + onPressed: () { + Navigator.pop(context, true); + }, + ), + ], + ); + }, + ); + } +} diff --git a/lib/models/generateWallets.dart b/lib/models/generate_wallets.dart similarity index 77% rename from lib/models/generateWallets.dart rename to lib/models/generate_wallets.dart index 8899751..1266dfc 100644 --- a/lib/models/generateWallets.dart +++ b/lib/models/generate_wallets.dart @@ -5,7 +5,8 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/models/walletData.dart'; +import 'package:gecko/models/chest_data.dart'; +import 'package:gecko/models/wallet_data.dart'; import 'package:pdf/pdf.dart'; import 'package:pdf/widgets.dart' as pw; import 'package:printing/printing.dart'; @@ -38,14 +39,41 @@ class GenerateWalletsProvider with ChangeNotifier { bool canImport = false; bool isPinChanged = false; - void storeHDWChest( + Future storeHDWChest( NewWallet _wallet, String _name, BuildContext context) async { - WalletData myWallet = - WalletData(chest: 0, number: 0, name: _name, derivation: 3); - walletBox.add(myWallet); - chestBox.put(0, _wallet.dewif); - configBox.put('currentChest', 0); - // walletBox.get(1) + int chestNumber = 0; + chestBox.toMap().forEach((key, value) { + if (!value.isCesium) { + chestNumber++; + } + }); + + String chestName; + if (chestNumber == 0) { + chestName = 'Coffre à Ğecko'; + } else { + chestName = 'Coffre à Ğecko ${chestNumber + 1}'; + } + ChestData thisChest = ChestData( + dewif: _wallet.dewif, + name: chestName, + defaultWallet: 0, + imageName: '${chestNumber % 8}.png', + isCesium: false, + ); + await chestBox.add(thisChest); + int chestKey = chestBox.keys.last; + + WalletData myWallet = WalletData( + chest: chestKey, + number: 0, + name: _name, + derivation: 3, + imageName: '0.png'); + await walletBox.add(myWallet); + + await configBox.put('currentChest', chestKey); + notifyListeners(); } void checkAskedWord(String inputWord, String _mnemo) { @@ -81,7 +109,7 @@ class GenerateWalletsProvider with ChangeNotifier { } int getRandomInt() { - var rng = new Random(); + var rng = Random(); return rng.nextInt(12); } @@ -112,7 +140,7 @@ class GenerateWalletsProvider with ChangeNotifier { Future generateMnemonic() async { try { generatedMnemonic = await DubpRust.genMnemonic(language: Language.french); - this.actualWallet = await generateWallet(this.generatedMnemonic); + actualWallet = await generateWallet(generatedMnemonic); walletIsGenerated = true; } catch (e) { log.e(e); @@ -122,7 +150,7 @@ class GenerateWalletsProvider with ChangeNotifier { Future generateWallet(generatedMnemonic) async { try { - this.actualWallet = await DubpRust.genWalletFromMnemonic( + actualWallet = await DubpRust.genWalletFromMnemonic( language: Language.french, mnemonic: generatedMnemonic, secretCodeType: SecretCodeType.letters, @@ -132,10 +160,10 @@ class GenerateWalletsProvider with ChangeNotifier { } mnemonicController.text = generatedMnemonic; - pin.text = this.actualWallet.pin; + pin.text = actualWallet.pin; // notifyListeners(); - return this.actualWallet; + return actualWallet; } Future changePinCode({bool reload}) async { @@ -158,7 +186,7 @@ class GenerateWalletsProvider with ChangeNotifier { final pw.Font ttf = pw.Font.ttf(fontData.buffer.asByteData()); final pdf = pw.Document(); - const imageProvider = const AssetImage('assets/icon/gecko_final.png'); + const imageProvider = AssetImage('assets/icon/gecko_final.png'); final geckoLogo = await flutterImageProvider(imageProvider); pdf.addPage( @@ -203,13 +231,15 @@ class GenerateWalletsProvider with ChangeNotifier { log.d(_walletPubkey); } - Future importWallet(context, _cesiumID, _cesiumPWD) async { + Future importCesiumWallet() async { // String _walletPubkey = await DubpRust.getLegacyPublicKey( // salt: _cesiumID, password: _cesiumPWD); // String shortPubkey = truncate(_walletPubkey, 9, // omission: "...", position: TruncatePosition.end); // await storeWallet( // actualWallet, 'Portefeuille Cesium - $shortPubkey', context); + // NewWallet myCesiumWallet = await DubpRust.genWalletFromDeprecatedSaltPassword(salt: _cesiumID, password: _cesiumPWD); + cesiumID.text = ''; cesiumPWD.text = ''; cesiumPubkey.text = ''; @@ -218,6 +248,33 @@ class GenerateWalletsProvider with ChangeNotifier { pin.text = ''; isCesiumIDVisible = false; isCesiumPWDVisible = false; + + int chestNumber = 0; + chestBox.toMap().forEach((key, value) { + if (value.isCesium) { + chestNumber++; + } + }); + + String chestName; + if (chestNumber == 0) { + chestName = 'Coffre à Césium'; + } else { + chestName = 'Coffre à Césium ${chestNumber + 1}'; + } + + ChestData cesiumChest = ChestData( + dewif: actualWallet.dewif, + name: chestName, + imageName: 'cesium.png', + defaultWallet: 0, + isCesium: true); + + await chestBox.add(cesiumChest).then((value) => null); + int chestKey = await chestBox.toMap().keys.last; + // chestBox.toMap(). + await configBox.put('currentChest', chestKey); + notifyListeners(); } diff --git a/lib/models/history.dart b/lib/models/history.dart index 9be347c..19a15fa 100644 --- a/lib/models/history.dart +++ b/lib/models/history.dart @@ -3,6 +3,8 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; import 'package:gecko/models/home.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/models/wallet_data.dart'; import 'package:gecko/screens/history.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:jdenticon_dart/jdenticon_dart.dart'; @@ -40,7 +42,7 @@ class HistoryProvider with ChangeNotifier { return 'false'; } if (barcode != null) { - this.outputPubkey.text = barcode; + outputPubkey.text = barcode; isPubkey(context, barcode); } else { return 'false'; @@ -49,8 +51,12 @@ class HistoryProvider with ChangeNotifier { } Future pay(BuildContext context, String pinCode) async { - // MyWalletsProvider _myWalletProvider = MyWalletsProvider(); - String dewif = chestBox.get(0); + MyWalletsProvider _myWalletModel = MyWalletsProvider(); + int currentChest = configBox.get('currentChest'); + WalletData defaultWallet = _myWalletModel.getDefaultWallet(currentChest); + + String dewif = chestBox.get(currentChest).dewif; + try { await DubpRust.simplePaymentFromTransparentAccount( accountIndex: defaultWallet.derivation, @@ -71,7 +77,7 @@ class HistoryProvider with ChangeNotifier { String isPubkey(context, pubkey, {bool goHistory}) { HomeProvider _homeProvider = Provider.of(context, listen: false); - final RegExp regExp = new RegExp( + final RegExp regExp = RegExp( r'^[a-zA-Z0-9]+$', caseSensitive: false, multiLine: false, @@ -85,9 +91,9 @@ class HistoryProvider with ChangeNotifier { this.pubkey = pubkey; getShortPubkey(pubkey); - this.outputPubkey.text = pubkey; + outputPubkey.text = pubkey; - if (goHistory == null) goHistory = false; + goHistory ??= false; if (goHistory) { isHistoryScreen = true; @@ -138,13 +144,13 @@ class HistoryProvider with ChangeNotifier { var transBC = []; int i = 0; - final currentBase = 0; + const currentBase = 0; double currentUD = 10.54; for (final trans in txs) { var direction = trans['direction']; final transaction = trans['node']; - var output; + String output; if (direction == "RECEIVED") { for (String line in transaction['outputs']) { if (line.contains(_pubkey)) { @@ -235,15 +241,15 @@ class HistoryProvider with ChangeNotifier { } else { _message = "Vous êtes connecté au noeud\n${endPointGVA.split('/')[2]}"; } - final snackBar = - SnackBar(content: Text(_message), duration: Duration(seconds: 2)); + final snackBar = SnackBar( + content: Text(_message), duration: const Duration(seconds: 2)); isFirstBuild = false; ScaffoldMessenger.of(context).showSnackBar(snackBar); } } void resetdHistory() { - this.outputPubkey.text = ''; + outputPubkey.text = ''; notifyListeners(); } @@ -253,7 +259,7 @@ class HistoryProvider with ChangeNotifier { } snackCopyKey(context) { - final snackBar = SnackBar( + const snackBar = SnackBar( content: Text("Cette clé publique a été copié dans votre presse-papier."), duration: Duration(seconds: 2)); @@ -273,8 +279,4 @@ class HistoryProvider with ChangeNotifier { String generateIdenticon(String _pubkey) { return Jdenticon.toSvg(_pubkey); } - - // num getBalance(_pubkey) { - // getBalance(_pubkey); - // } } diff --git a/lib/models/home.dart b/lib/models/home.dart index 1b67d41..69fe956 100644 --- a/lib/models/home.dart +++ b/lib/models/home.dart @@ -9,14 +9,14 @@ import 'package:flutter/services.dart'; import 'dart:async'; import 'package:gecko/globals.dart'; import 'package:gecko/screens/history.dart'; -import 'package:gecko/screens/myWallets/walletsHome.dart'; +import 'package:gecko/screens/myWallets/wallets_home.dart'; import 'package:package_info/package_info.dart'; class HomeProvider with ChangeNotifier { int _currentIndex = 0; bool isSearching; - Icon searchIcon = Icon(Icons.search); - final TextEditingController searchQuery = new TextEditingController(); + Icon searchIcon = const Icon(Icons.search); + final TextEditingController searchQuery = TextEditingController(); Widget appBarTitle = Text('Ğecko', style: TextStyle(color: Colors.grey[850])); Widget appBarExplorer = Text('Explorateur', style: TextStyle(color: Colors.grey[850])); @@ -57,7 +57,7 @@ class HomeProvider with ChangeNotifier { String _endpoint; int _statusCode = 0; - final _client = new HttpClient(); + final _client = HttpClient(); _client.connectionTimeout = const Duration(milliseconds: 1000); do { diff --git a/lib/models/myWallets.dart b/lib/models/my_wallets.dart similarity index 75% rename from lib/models/myWallets.dart rename to lib/models/my_wallets.dart index 3cd63c4..6953108 100644 --- a/lib/models/myWallets.dart +++ b/lib/models/my_wallets.dart @@ -2,7 +2,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'dart:async'; import 'package:gecko/globals.dart'; -import 'package:gecko/models/walletData.dart'; +import 'package:gecko/models/wallet_data.dart'; class MyWalletsProvider with ChangeNotifier { List listWallets = []; @@ -18,13 +18,7 @@ class MyWalletsProvider with ChangeNotifier { } bool checkIfWalletExist() { - if (appPath == null) { - return false; - } - - final List _walletList = readAllWallets(0); - - if (_walletList.isEmpty) { + if (chestBox.isEmpty) { log.i('No wallets detected'); return false; } else { @@ -47,27 +41,25 @@ class MyWalletsProvider with ChangeNotifier { if (_id.isEmpty) return WalletData(); int _chest = _id[0]; int _nbr = _id[1]; - var _targetedWallet; + WalletData _targetedWallet; walletBox.toMap().forEach((key, value) { if (value.chest == _chest && value.number == _nbr) { _targetedWallet = value; - return false; + return; } }); return _targetedWallet; } - void getDefaultWallet() { - MyWalletsProvider myWalletsProvider = MyWalletsProvider(); - - if (configBox.get('defaultWallet') == null) { - configBox.put('defaultWallet', [0, 0]); + WalletData getDefaultWallet(int chest) { + if (chestBox.isEmpty) { + return WalletData(chest: 0, number: 0); + } else { + int defaultWalletNumber = chestBox.get(chest).defaultWallet; + return getWalletData([chest, defaultWalletNumber]); } - - defaultWallet = myWalletsProvider - .getWalletData(configBox.get('defaultWallet').cast()); } Future deleteAllWallet(context) async { @@ -94,19 +86,19 @@ class MyWalletsProvider with ChangeNotifier { barrierDismissible: true, // user must tap button! builder: (BuildContext context) { return AlertDialog( - title: - Text('Êtes-vous sûr de vouloir supprimer tous vos trousseaux ?'), - content: SingleChildScrollView(child: Text('')), + title: const Text( + 'Êtes-vous sûr de vouloir supprimer tous vos trousseaux ?'), + content: const SingleChildScrollView(child: Text('')), actions: [ TextButton( - child: Text("Non"), + child: const Text("Non"), onPressed: () { Navigator.pop(context, false); }, ), TextButton( - key: Key('confirmDeletingAllWallets'), - child: Text("Oui"), + key: const Key('confirmDeletingAllWallets'), + child: const Text("Oui"), onPressed: () { Navigator.pop(context, true); }, @@ -120,7 +112,7 @@ class MyWalletsProvider with ChangeNotifier { Future generateNewDerivation(context, String _name) async { int _newDerivationNbr; int _newWalletNbr; - int _chest = 0; + int _chest = getCurrentChest(); List _walletConfig = readAllWallets(_chest); if (_walletConfig.isEmpty) { @@ -135,12 +127,12 @@ class MyWalletsProvider with ChangeNotifier { chest: _chest, number: _newWalletNbr, name: _name, - derivation: _newDerivationNbr); + derivation: _newDerivationNbr, + imageName: '${_newWalletNbr % 4}.png'); await walletBox.add(newWallet); notifyListeners(); - Navigator.pop(context); } void rebuildWidget() { diff --git a/lib/models/walletData.dart b/lib/models/wallet_data.dart similarity index 55% rename from lib/models/walletData.dart rename to lib/models/wallet_data.dart index c1fbdde..20ea9ef 100644 --- a/lib/models/walletData.dart +++ b/lib/models/wallet_data.dart @@ -1,6 +1,8 @@ +import 'dart:io'; + import 'package:hive_flutter/hive_flutter.dart'; -part 'walletData.g.dart'; +part 'wallet_data.g.dart'; @HiveType(typeId: 0) class WalletData extends HiveObject { @@ -16,21 +18,33 @@ class WalletData extends HiveObject { @HiveField(3) int derivation; - WalletData({this.chest, this.number, this.name, this.derivation}); + @HiveField(4) + String imageName; + + @HiveField(5) + File imageFile; + + WalletData( + {this.chest, + this.number, + this.name, + this.derivation, + this.imageName, + this.imageFile}); // representation of WalletData when debugging @override String toString() { - return this.name; + return name; } // creates the ':'-separated string from the WalletData String inLine() { - return "${this.chest}:${this.number}:${this.name}:${this.derivation}"; + return "$chest:$number:$name:$derivation:$imageName"; } // returns only the id part of the ':'-separated string - List id() { - return [this.chest, this.number]; + List id() { + return [chest, number]; } } diff --git a/lib/models/walletData.g.dart b/lib/models/wallet_data.g.dart similarity index 83% rename from lib/models/walletData.g.dart rename to lib/models/wallet_data.g.dart index 3182ec0..3f8ee52 100644 --- a/lib/models/walletData.g.dart +++ b/lib/models/wallet_data.g.dart @@ -1,6 +1,6 @@ // GENERATED CODE - DO NOT MODIFY BY HAND -part of 'walletData.dart'; +part of 'wallet_data.dart'; // ************************************************************************** // TypeAdapterGenerator @@ -21,13 +21,15 @@ class WalletDataAdapter extends TypeAdapter { number: fields[1] as int, name: fields[2] as String, derivation: fields[3] as int, + imageName: fields[4] as String, + imageFile: fields[5] as File, ); } @override void write(BinaryWriter writer, WalletData obj) { writer - ..writeByte(4) + ..writeByte(6) ..writeByte(0) ..write(obj.chest) ..writeByte(1) @@ -35,7 +37,11 @@ class WalletDataAdapter extends TypeAdapter { ..writeByte(2) ..write(obj.name) ..writeByte(3) - ..write(obj.derivation); + ..write(obj.derivation) + ..writeByte(4) + ..write(obj.imageName) + ..writeByte(5) + ..write(obj.imageFile); } @override diff --git a/lib/models/walletOptions.dart b/lib/models/wallet_options.dart similarity index 69% rename from lib/models/walletOptions.dart rename to lib/models/wallet_options.dart index ba3da48..68a55be 100644 --- a/lib/models/walletOptions.dart +++ b/lib/models/wallet_options.dart @@ -8,23 +8,23 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'dart:async'; import 'package:gecko/globals.dart'; -import 'package:gecko/models/myWallets.dart'; -import 'package:gecko/models/walletData.dart'; +import 'package:gecko/models/chest_data.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/models/wallet_data.dart'; import 'package:image_picker/image_picker.dart'; import 'package:truncate/truncate.dart'; import 'package:qrscan/qrscan.dart' as scanner; class WalletOptionsProvider with ChangeNotifier { TextEditingController pubkey = TextEditingController(); - TextEditingController _newWalletName = TextEditingController(); + final TextEditingController _newWalletName = TextEditingController(); bool isWalletUnlock = false; bool ischangedPin = false; - TextEditingController newPin = new TextEditingController(); + TextEditingController newPin = TextEditingController(); bool isEditing = false; bool isBalanceBlur = true; FocusNode walletNameFocus = FocusNode(); TextEditingController nameController = TextEditingController(); - List walletID; bool isDefaultWallet; Future get badWallet => null; @@ -32,7 +32,7 @@ class WalletOptionsProvider with ChangeNotifier { Future _getPubkeyFromDewif( String _dewif, _pin, int _pinLenght, int derivation) async { String _pubkey; - RegExp regExp = new RegExp( + RegExp regExp = RegExp( r'^[A-Z0-9]+$', caseSensitive: false, multiLine: false, @@ -47,7 +47,7 @@ class WalletOptionsProvider with ChangeNotifier { List _pubkeysTmp = await DubpRust.getBip32DewifAccountsPublicKeys( dewif: _dewif, secretCode: _pin, accountsIndex: [derivation]); _pubkey = _pubkeysTmp[0]; - this.pubkey.text = _pubkey; + pubkey.text = _pubkey; notifyListeners(); return _pubkey; @@ -60,7 +60,7 @@ class WalletOptionsProvider with ChangeNotifier { } else { try { _pubkey = await DubpRust.getDewifPublicKey(dewif: _dewif, pin: _pin); - this.pubkey.text = _pubkey; + pubkey.text = _pubkey; notifyListeners(); return _pubkey; } catch (e) { @@ -76,13 +76,13 @@ class WalletOptionsProvider with ChangeNotifier { context, WalletData _wallet, String _pin, int _pinLenght) async { isWalletUnlock = false; try { - String _localDewif = chestBox.get(0); + String _localDewif = chestBox.get(_wallet.chest).dewif; String _localPubkey; if ((_localPubkey = await _getPubkeyFromDewif( _localDewif, _pin, _pinLenght, _wallet.derivation)) != 'false') { - this.pubkey.text = _localPubkey; + pubkey.text = _localPubkey; isWalletUnlock = true; return _localDewif; } else { @@ -91,7 +91,7 @@ class WalletOptionsProvider with ChangeNotifier { } catch (e) { // _homeProvider.playSound('non', 0.6); log.e('ERROR READING FILE: $e'); - this.pubkey.clear(); + pubkey.clear(); return 'bad'; } } @@ -113,8 +113,8 @@ class WalletOptionsProvider with ChangeNotifier { int getPinLenght(_walletNbr) { String _localDewif; - if (_walletNbr is int) { - _localDewif = chestBox.get(0); + if (_walletNbr is int || _walletNbr == null) { + _localDewif = chestBox.get(configBox.get('currentChest')).dewif; } else { _localDewif = _walletNbr; } @@ -125,69 +125,33 @@ class WalletOptionsProvider with ChangeNotifier { return _pinLenght; } - Future _renameWallet(List _walletID, _newName) async { - MyWalletsProvider myWalletClass = MyWalletsProvider(); + void _renameWallet(List _walletID, _newName, {bool isCesium}) async { + if (isCesium) { + ChestData _chestTarget = chestBox.get(_walletID[0]); + _chestTarget.name = _newName; + await chestBox.put(_chestTarget.key, _chestTarget); + } else { + MyWalletsProvider myWalletClass = MyWalletsProvider(); - WalletData _walletTarget = myWalletClass.getWalletData(_walletID); - _walletTarget.name = _newName; - await walletBox.putAt(_walletTarget.key, _walletTarget); + WalletData _walletTarget = myWalletClass.getWalletData(_walletID); + _walletTarget.name = _newName; + await walletBox.put(_walletTarget.key, _walletTarget); + } _newWalletName.text = ''; } - Future renameWalletAlerte( - context, _walletName, _walletNbr, _derivation) async { - return showDialog( - context: context, - barrierDismissible: true, - builder: (BuildContext context) { - return AlertDialog( - title: Text('Choisissez un nouveau nom pour ce portefeuille'), - content: SingleChildScrollView( - child: ListBody( - children: [ - TextField( - controller: this._newWalletName, - maxLines: 1, - textAlign: TextAlign.center, - decoration: InputDecoration(), - style: TextStyle( - fontSize: 14.0, - color: Colors.black, - fontWeight: FontWeight.bold)), - ], - ), - ), - actions: [ - TextButton( - child: Text("Valider"), - onPressed: () { - WidgetsBinding.instance.addPostFrameCallback((_) async { - // await _renameWallet(_walletName, this._newWalletName.text, - // _walletNbr, _derivation); - }); - // notifyListeners(); - Navigator.pop(context, true); - }, - ), - ], - ); - }, - ); - } - - Future editWalletName(List _wID) async { + bool editWalletName(List _wID, {bool isCesium}) { bool nameState; if (isEditing) { if (!nameController.text.contains(':') && nameController.text.length <= 39) { - await _renameWallet(_wID, nameController.text); + _renameWallet(_wID, nameController.text, isCesium: isCesium); nameState = true; } else { nameState = false; } } else { - walletNameFocus.requestFocus(); nameState = true; } @@ -220,20 +184,20 @@ class WalletOptionsProvider with ChangeNotifier { 'Êtes-vous sûr de vouloir supprimer le portefeuille "$_walletName" ?'), content: SingleChildScrollView( child: ListBody( - children: [ + children: const [ Text('Vous pourrez restaurer ce portefeuille plus tard.'), ], ), ), actions: [ TextButton( - child: Text("Non", key: Key('cancelDeleting')), + child: const Text("Non", key: Key('cancelDeleting')), onPressed: () { Navigator.pop(context, false); }, ), TextButton( - child: Text("Oui", key: Key('confirmDeleting')), + child: const Text("Oui", key: Key('confirmDeleting')), onPressed: () { Navigator.pop(context, true); }, @@ -245,7 +209,7 @@ class WalletOptionsProvider with ChangeNotifier { } snackCopyKey(context) { - final snackBar = SnackBar( + const snackBar = SnackBar( content: Text("Cette clé publique a été copié dans votre presse-papier."), duration: Duration(seconds: 2)); @@ -282,10 +246,11 @@ class WalletOptionsProvider with ChangeNotifier { File _image; final picker = ImagePicker(); - final pickedFile = await picker.pickImage(source: ImageSource.gallery); + XFile pickedFile = await picker.pickImage(source: ImageSource.gallery); if (pickedFile != null) { _image = File(pickedFile.path); + log.i(pickedFile.path); return _image; } else { log.w('No image selected.'); diff --git a/lib/screens/commonElements.dart b/lib/screens/common_elements.dart similarity index 90% rename from lib/screens/commonElements.dart rename to lib/screens/common_elements.dart index 78c6621..b9f2654 100644 --- a/lib/screens/commonElements.dart +++ b/lib/screens/common_elements.dart @@ -5,22 +5,22 @@ import 'package:gecko/globals.dart'; class CommonElements { // Exemple de Widget Widget exemple(String data) { - return Text('Coucou'); + return const Text('Coucou'); } Widget bubbleSpeak(String text, {double long, Key textKey}) { return Bubble( padding: long == null - ? BubbleEdges.all(18) + ? const BubbleEdges.all(18) : BubbleEdges.symmetric(horizontal: long, vertical: 30), elevation: 5, color: Colors.white, - margin: BubbleEdges.fromLTRB(10, 0, 20, 10), + margin: const BubbleEdges.fromLTRB(10, 0, 20, 10), // nip: BubbleNip.leftTop, child: Text( text, key: textKey, - style: TextStyle( + style: const TextStyle( color: Colors.black, fontSize: 18, fontWeight: FontWeight.w400), ), ); @@ -28,15 +28,15 @@ class CommonElements { Widget bubbleSpeakRich(List text, {Key textKey}) { return Bubble( - padding: BubbleEdges.all(18), + padding: const BubbleEdges.all(18), elevation: 5, color: Colors.white, - margin: BubbleEdges.fromLTRB(10, 0, 20, 10), + margin: const BubbleEdges.fromLTRB(10, 0, 20, 10), // nip: BubbleNip.leftTop, child: RichText( key: textKey, text: TextSpan( - style: TextStyle( + style: const TextStyle( fontSize: 18.0, color: Colors.black, ), @@ -87,7 +87,7 @@ class CommonElements { top: 70, right: 90, child: Text(progress == 12 ? '11/11' : '$progress/11', - style: TextStyle(fontSize: 12, color: Colors.black)), + style: const TextStyle(fontSize: 12, color: Colors.black)), ), ]); } @@ -102,7 +102,7 @@ class CommonElements { return Container( child: ClipOval( child: Material( - color: Color(0xffFFD58D), // button color + color: const Color(0xffFFD58D), // button color child: InkWell( splashColor: orangeC, // inkwell color child: Padding( @@ -113,7 +113,7 @@ class CommonElements { }), ), ), - decoration: BoxDecoration( + decoration: const BoxDecoration( shape: BoxShape.circle, color: Colors.white, boxShadow: [ @@ -207,14 +207,15 @@ class GeckoSpeechAppBar extends StatelessWidget with PreferredSizeWidget { GeckoSpeechAppBar( this.title, { Key key, - }) : preferredSize = Size.fromHeight(105.4), + }) : preferredSize = const Size.fromHeight(105.4), super(key: key); @override Widget build(BuildContext context) { return AppBar( + toolbarHeight: 60 * ratio, leading: IconButton( - icon: Container( + icon: SizedBox( height: 30, child: Image.asset('assets/onBoarding/gecko_bar.png')), onPressed: () => Navigator.popUntil( diff --git a/lib/screens/history.dart b/lib/screens/history.dart index 7948006..7701a56 100644 --- a/lib/screens/history.dart +++ b/lib/screens/history.dart @@ -1,13 +1,15 @@ import 'dart:io'; import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/models/cesiumPlus.dart'; +import 'package:gecko/models/cesium_plus.dart'; import 'package:gecko/models/home.dart'; +import 'package:gecko/models/my_wallets.dart'; import 'package:gecko/models/queries.dart'; import 'package:gecko/models/history.dart'; import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; -import 'package:gecko/screens/myWallets/unlockingWallet.dart'; +import 'package:gecko/models/wallet_data.dart'; +import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; import 'dart:ui'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:provider/provider.dart'; @@ -20,7 +22,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { final nRepositories = 20; // HistoryProvider _historyProvider; final _formKey = GlobalKey(); - FocusNode _pubkeyFocus = FocusNode(); + final FocusNode _pubkeyFocus = FocusNode(); List cesiumData; final double avatarsSize = 80; @@ -28,22 +30,25 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { FetchMoreOptions opts; final GlobalKey _scaffoldKey = GlobalKey(); + HistoryScreen({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); HistoryProvider _historyProvider = Provider.of(context); HomeProvider _homeProvider = Provider.of(context); - this._outputPubkey.text = _historyProvider.pubkey; + _outputPubkey.text = _historyProvider.pubkey; log.i('Build pubkey : ' + _historyProvider.pubkey); WidgetsBinding.instance.addPostFrameCallback((_) {}); return Scaffold( key: _scaffoldKey, appBar: AppBar( + toolbarHeight: 60 * ratio, title: _homeProvider.appBarExplorer, actions: [ Padding( - padding: EdgeInsets.symmetric(horizontal: 16), + padding: const EdgeInsets.symmetric(horizontal: 16), child: IconButton( icon: _homeProvider.searchIcon, color: Colors.grey[850], @@ -79,9 +84,9 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { } })) ], - backgroundColor: Color(0xffFFD58D), + backgroundColor: const Color(0xffFFD58D), ), - floatingActionButton: Container( + floatingActionButton: SizedBox( height: 80.0, width: 80.0, child: FittedBox( @@ -90,11 +95,11 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { onPressed: () async { await _historyProvider.scan(context); }, - child: Container( + child: SizedBox( height: 40.0, width: 40.0, child: Padding( - padding: EdgeInsets.symmetric(horizontal: 3), + padding: const EdgeInsets.symmetric(horizontal: 3), child: Image.asset('assets/qrcode-scan.png'))), backgroundColor: floattingYellow, //smoothYellow, //Color.fromARGB(500, 204, 255, 255), @@ -102,7 +107,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ), ), body: Column(children: [ - SizedBox(height: 0), + const SizedBox(height: 0), if (_historyProvider.pubkey != '') historyQuery(context, _historyProvider), ])); @@ -137,7 +142,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { if (result.hasException) { log.e('Error GVA: ' + result.exception.toString()); - return Column(children: [ + return Column(children: const [ SizedBox(height: 50), Text( "Aucun noeud GVA valide n'a pu être trouvé.\nVeuillez réessayer ultérieurement.", @@ -169,10 +174,10 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { child: Builder( builder: (context) => Expanded( child: ListView( - key: Key('listTransactions'), + key: const Key('listTransactions'), controller: scrollController, children: [ - SizedBox(height: 20), + const SizedBox(height: 20), if (_historyProvider.pubkey != '') Row( mainAxisAlignment: @@ -212,7 +217,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { if (_avatar.hasData) { return SingleChildScrollView( padding: - EdgeInsets.all(0.0), + const EdgeInsets.all( + 0.0), child: Image.file( _avatar.data[0], height: avatarsSize)); @@ -223,7 +229,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { height: avatarsSize); })), GestureDetector( - key: Key('copyPubkey'), + key: const Key('copyPubkey'), onTap: () { Clipboard.setData(ClipboardData( text: _historyProvider.pubkey)); @@ -232,7 +238,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { child: Text( _historyProvider.getShortPubkey( _historyProvider.pubkey), - style: TextStyle( + style: const TextStyle( fontSize: 22, fontWeight: FontWeight.w800, fontFamily: 'Monospace')), @@ -255,7 +261,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ], ), )), - SizedBox(width: 0) + const SizedBox(width: 0) ]), if (_isFirstExec) Row( @@ -272,25 +278,22 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { _historyProvider.pubkey), initialData: '...', builder: (context, snapshot) { - return Text( - snapshot.data != null - ? snapshot.data - : '-', - style: - TextStyle(fontSize: 20)); + return Text(snapshot.data ?? '-', + style: const TextStyle( + fontSize: 20)); })) ]), - SizedBox(height: 18), + const SizedBox(height: 18), if (_isFirstExec) Container( padding: const EdgeInsets.fromLTRB(0, 0, 0, 0), child: Text(balance.toString() + ' Ğ1', textAlign: TextAlign.center, - style: TextStyle(fontSize: 18.0))), - SizedBox(height: 20), + style: const TextStyle(fontSize: 18.0))), + const SizedBox(height: 20), ElevatedButton( - key: Key('switchPayHistory'), + key: const Key('switchPayHistory'), style: ElevatedButton.styleFrom( elevation: 1, primary: Colors.grey[50], // background @@ -330,6 +333,10 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { } Widget payView(context, HistoryProvider _historyProvider) { + MyWalletsProvider _myWalletProvider = MyWalletsProvider(); + WalletData defaultWallet = + _myWalletProvider.getDefaultWallet(configBox.get('currentChest')); + return Stack( clipBehavior: Clip.hardEdge, children: [ @@ -338,32 +345,32 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { child: Column( mainAxisSize: MainAxisSize.min, children: [ - SizedBox(height: 20), - Text('Commentaire:', style: TextStyle(fontSize: 20.0)), + const SizedBox(height: 20), + const Text('Commentaire:', style: TextStyle(fontSize: 20.0)), Padding( - padding: EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), child: TextField( controller: _historyProvider.payComment, maxLines: 2, textAlign: TextAlign.center, - decoration: InputDecoration(), - style: TextStyle( + decoration: const InputDecoration(), + style: const TextStyle( fontSize: 22, color: Colors.black, fontWeight: FontWeight.bold))), - SizedBox(height: 20), - Text('Montant (DU/Ğ1):', style: TextStyle(fontSize: 20.0)), + const SizedBox(height: 20), + const Text('Montant (DU/Ğ1):', style: TextStyle(fontSize: 20.0)), Padding( - padding: EdgeInsets.all(8.0), + padding: const EdgeInsets.all(8.0), child: TextFormField( - style: TextStyle(fontSize: 22), + style: const TextStyle(fontSize: 22), controller: _historyProvider.payAmount, textAlign: TextAlign.center, maxLines: 1, keyboardType: TextInputType.number, decoration: InputDecoration( - contentPadding: - EdgeInsets.symmetric(vertical: 25.0, horizontal: 10.0), + contentPadding: const EdgeInsets.symmetric( + vertical: 25.0, horizontal: 10.0), border: OutlineInputBorder( borderRadius: BorderRadius.circular(10.0)), ), @@ -406,7 +413,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { int keyID = 0; return _historyProvider.transBC == null - ? Text('Aucune transaction à afficher.') + ? const Text('Aucune transaction à afficher.') : Column(children: [ for (var repository in _historyProvider.transBC) Padding( @@ -421,14 +428,14 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { fontWeight: FontWeight.w700), textAlign: TextAlign.center), title: Text(repository[3], - style: TextStyle( + style: const TextStyle( fontSize: 15.0, fontFamily: 'Monospace'), textAlign: TextAlign.center), subtitle: Text(repository[6] != '' ? repository[6] : '-', - style: TextStyle(fontSize: 12.0), + style: const TextStyle(fontSize: 12.0), textAlign: TextAlign.center), trailing: Text("${repository[4]} Ğ1", - style: TextStyle(fontSize: 14.0), + style: const TextStyle(fontSize: 14.0), textAlign: TextAlign.justify), dense: true, isThreeLine: false, @@ -439,14 +446,14 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { if (result.isLoading) Row( mainAxisAlignment: MainAxisAlignment.center, - children: [ + children: const [ CircularProgressIndicator(), ], ), // if (_historyProvider.isTheEnd) // What I did before ... if (!_historyProvider.pageInfo['hasPreviousPage']) Column( - children: [ + children: const [ SizedBox(height: 15), Text("Début de l'historique.", textAlign: TextAlign.center, diff --git a/lib/screens/home.dart b/lib/screens/home.dart index 3c37a15..f305064 100644 --- a/lib/screens/home.dart +++ b/lib/screens/home.dart @@ -1,17 +1,21 @@ import 'package:dubp/dubp.dart'; import 'package:gecko/globals.dart'; +import 'package:gecko/models/chest_provider.dart'; import 'package:gecko/models/history.dart'; import 'package:gecko/models/home.dart'; import 'package:flutter/material.dart'; -import 'package:gecko/models/myWallets.dart'; -import 'package:gecko/screens/myWallets/unlockingWallet.dart'; -import 'package:gecko/screens/onBoarding/0_noKeychainFound.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/models/wallet_data.dart'; +import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; +import 'package:gecko/screens/onBoarding/0_no_keychain_found.dart'; import 'dart:ui'; import 'package:gecko/screens/settings.dart'; import 'package:flutter/services.dart'; import 'package:provider/provider.dart'; class HomeScreen extends StatelessWidget { + const HomeScreen({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -20,6 +24,8 @@ class HomeScreen extends StatelessWidget { HistoryProvider _historyStatic = HistoryProvider(''); MyWalletsProvider _myWalletProvider = Provider.of(context); + Provider.of(context); + final bool isWalletsExists = _myWalletProvider.checkIfWalletExist(); // walletBox.toMap().forEach((key, value) { @@ -35,319 +41,321 @@ class HomeScreen extends StatelessWidget { ratio = 1.125; } return Scaffold( - resizeToAvoidBottomInset: false, - drawer: Drawer( - child: Column( - children: [ - Expanded( - child: ListView(padding: EdgeInsets.zero, children: [ - DrawerHeader( - child: Column(children: [ - SizedBox(height: 0), + resizeToAvoidBottomInset: false, + drawer: Drawer( + child: Column( + children: [ + Expanded( + child: ListView(padding: EdgeInsets.zero, children: [ + DrawerHeader( + child: Column(children: const [ + SizedBox(height: 0), + Image( + image: AssetImage('assets/icon/gecko_final.png'), + height: 130), + ]), + decoration: BoxDecoration( + color: orangeC, + ), + ), + ListTile( + key: const Key('parameters'), + title: const Text('Paramètres'), + onTap: () { + Navigator.pop(context); + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return SettingsScreen(); + }), + ); + }, + ), + ListTile( + title: const Text('A propos'), + onTap: () { + // Update the state of the app. + // ... + }, + ), + ])), + Align( + alignment: FractionalOffset.bottomCenter, + child: Text('Ğecko v$appVersion')), + const SizedBox(height: 20) + ], + ), + ), + appBar: AppBar( + toolbarHeight: 60 * ratio, + leading: Builder( + builder: (context) => IconButton( + key: const Key('drawerMenu'), + icon: Icon(Icons.menu, color: Colors.grey[850]), + onPressed: () => Scaffold.of(context).openDrawer(), + )), + title: _homeProvider.appBarTitle, + actions: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: IconButton( + key: const Key('searchIcon'), + icon: _homeProvider.searchIcon, + color: Colors.grey[850], + onPressed: () { + if (_homeProvider.searchIcon.icon == Icons.search) { + _homeProvider.searchIcon = Icon( + Icons.close, + color: Colors.grey[850], + ); + _homeProvider.appBarTitle = TextField( + key: const Key('searchInput'), + autofocus: true, + controller: _homeProvider.searchQuery, + onChanged: (text) { + log.d("Clé tappé: $text"); + final String searchResult = + _historyProvider.isPubkey(context, text); + if (searchResult != '') { + _homeProvider.currentIndex = 0; + } + }, + style: TextStyle( + color: Colors.grey[850], + ), + decoration: InputDecoration( + prefixIcon: + Icon(Icons.search, color: Colors.grey[850]), + hintText: "Rechercher ...", + hintStyle: TextStyle(color: Colors.grey[850])), + ); + _homeProvider.handleSearchStart(); + } else { + _homeProvider.handleSearchEnd(); + } + })) + ], + backgroundColor: const Color(0xffFFD58D), + ), + backgroundColor: const Color(0xffF9F9F1), + body: Builder( + builder: (ctx) => StatefulWrapper( + onInit: () { + WidgetsBinding.instance.addPostFrameCallback((_) { + DubpRust.setup(); + _historyStatic.snackNode(ctx); + }); + }, + child: Column(children: [ + Padding( + padding: const EdgeInsets.only(top: 20), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + SizedBox(width: 7), Image( image: AssetImage('assets/icon/gecko_final.png'), - height: 130), + height: 180), ]), - decoration: BoxDecoration( - color: orangeC, - ), - ), - ListTile( - key: Key('parameters'), - title: Text('Paramètres'), - onTap: () { - Navigator.pop(context); - Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return SettingsScreen(); - }), - ); - }, - ), - ListTile( - title: Text('A propos'), - onTap: () { - // Update the state of the app. - // ... - }, - ), - ])), - Container( - child: Align( - alignment: FractionalOffset.bottomCenter, - child: Text('Ğecko v$appVersion'))), - SizedBox(height: 20) - ], - ), - ), - appBar: AppBar( - leading: Builder( - builder: (context) => IconButton( - key: Key('drawerMenu'), - icon: new Icon(Icons.menu, color: Colors.grey[850]), - onPressed: () => Scaffold.of(context).openDrawer(), - )), - title: _homeProvider.appBarTitle, - actions: [ + ), Padding( - padding: EdgeInsets.symmetric(horizontal: 16), - child: IconButton( - key: Key('searchIcon'), - icon: _homeProvider.searchIcon, - color: Colors.grey[850], - onPressed: () { - if (_homeProvider.searchIcon.icon == Icons.search) { - _homeProvider.searchIcon = Icon( - Icons.close, - color: Colors.grey[850], - ); - _homeProvider.appBarTitle = TextField( - key: Key('searchInput'), - autofocus: true, - controller: _homeProvider.searchQuery, - onChanged: (text) { - log.d("Clé tappé: $text"); - final String searchResult = - _historyProvider.isPubkey(context, text); - if (searchResult != '') { - _homeProvider.currentIndex = 0; - } - }, - style: TextStyle( - color: Colors.grey[850], - ), - decoration: InputDecoration( - prefixIcon: - Icon(Icons.search, color: Colors.grey[850]), - hintText: "Rechercher ...", - hintStyle: TextStyle(color: Colors.grey[850])), - ); - _homeProvider.handleSearchStart(); - } else { - _homeProvider.handleSearchEnd(); - } - })) - ], - backgroundColor: Color(0xffFFD58D), - ), - backgroundColor: Color(0xffF9F9F1), - body: Builder( - builder: (ctx) => StatefulWrapper( - onInit: () { - WidgetsBinding.instance.addPostFrameCallback((_) { - DubpRust.setup(); - _historyStatic.snackNode(ctx); - }); - }, - child: Column(children: [ - Padding( - padding: EdgeInsets.only(top: 20), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - SizedBox(width: 7), - Image( - image: - AssetImage('assets/icon/gecko_final.png'), - height: 180), - ])), - Padding( - padding: EdgeInsets.only(top: 15), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - "y'a pas de lézard !", - textAlign: TextAlign.center, - style: TextStyle( - color: Colors.black, - fontSize: 17, - fontStyle: FontStyle.italic), - ) - ])), - Padding( - padding: EdgeInsets.only(top: 60), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Column(children: [ - Container( - child: ClipOval( - child: Material( - color: Color(0xffFFD58D), // button color - child: InkWell( - splashColor: orangeC, // inkwell color - child: Padding( - padding: EdgeInsets.all(22), - child: Image( - image: AssetImage( - 'assets/qrcode-scan.png'), - height: 60)), - onTap: () async { - await _historyProvider - .scan(context); - }), - ), - ), - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Colors.grey, - blurRadius: 4.0, - offset: Offset(2.0, 2.5), - spreadRadius: 0.5) - ], - ), - ), - SizedBox(height: 12), - Text( - "Payer par QR-Code", - textAlign: TextAlign.center, - style: TextStyle( - color: Colors.black, fontSize: 16), - ) - ]) - ])), - Padding( - padding: EdgeInsets.only(top: 50), - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Column(children: [ - Container( - child: ClipOval( - child: Material( - color: Color(0xffFFD58D), // button color - child: InkWell( - splashColor: orangeC, // inkwell color - child: Padding( - padding: EdgeInsets.symmetric( - horizontal: 20, vertical: 16), - child: Image( - image: AssetImage( - 'assets/blockchain.png'), - height: 70)), - onTap: () { - // Navigator.push( - // context, - // MaterialPageRoute( - // builder: (context) { - // return TemplateScreen(); - // }), - // ); - }), - ), - ), - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Colors.grey, - blurRadius: 4.0, - offset: Offset(2.0, 2.5), - spreadRadius: 0.5) - ], - ), - ), - SizedBox(height: 12), - Text( - "Explorer\n", - textAlign: TextAlign.center, - style: TextStyle( - color: Colors.black, fontSize: 16), - ) - ]), - SizedBox(width: 140), - Column(children: [ - Container( - child: ClipOval( - key: Key('manageWallets'), - child: Material( - color: Color(0xffFFD58D), // button color - child: InkWell( - splashColor: orangeC, // inkwell color - child: Padding( - padding: EdgeInsets.all(23), - child: Image( - image: AssetImage( - 'assets/lock.png'), - height: 57)), - onTap: () { - isWalletsExists - ? Navigator.push(context, - MaterialPageRoute( - builder: (context) { - return UnlockingWallet( - wallet: defaultWallet, - action: "mywallets", - ); - })) - - // Navigator.pushNamed( - // context, '/mywallets') - : Navigator.push(context, - MaterialPageRoute( - builder: (context) { - return NoKeyChainScreen(); - })); - }), - ), - ), - decoration: BoxDecoration( - shape: BoxShape.circle, - color: Colors.white, - boxShadow: [ - BoxShadow( - color: Colors.grey, - blurRadius: 4.0, - offset: Offset(2.0, 2.5), - spreadRadius: 0.5) - ], - ), - ), - SizedBox(height: 12), - Text( - "Gérer mes\nportefeuilles", - textAlign: TextAlign.center, - style: TextStyle( - color: Colors.black, fontSize: 16), - ) - ]) - ])) + padding: const EdgeInsets.only(top: 15), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: const [ + Text( + "y'a pas de lézard !", + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.black, + fontSize: 17, + fontStyle: FontStyle.italic), + ) ]), - // bottomNavigationBar: BottomNavigationBar( - // backgroundColor: Color(0xffFFD58D), - // fixedColor: Colors.grey[850], - // unselectedItemColor: Color(0xffBD935C), - // type: BottomNavigationBarType.fixed, - // onTap: (index) { - // _homeProvider.currentIndex = index; - // }, - // currentIndex: _homeProvider.currentIndex, - // items: [ - // BottomNavigationBarItem( - // icon: Image.asset('assets/block-space-disabled.png', height: 26), - // activeIcon: Image.asset('assets/blockchain.png', height: 26), - // label: 'Explorateur', - // ), - // BottomNavigationBarItem( - // icon: Icon(Icons.lock), - // label: 'Mes portefeuilles', - // ), - // ], - // ), - ))); + ), + Padding( + padding: EdgeInsets.only(top: isTall ? 100 : 60), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Column(children: [ + Container( + child: ClipOval( + child: Material( + color: const Color(0xffFFD58D), // button color + child: InkWell( + splashColor: orangeC, // inkwell color + child: const Padding( + padding: EdgeInsets.all(22), + child: Image( + image: AssetImage( + 'assets/qrcode-scan.png'), + height: 60)), + onTap: () async { + await _historyProvider.scan(context); + }), + ), + ), + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Colors.grey, + blurRadius: 4.0, + offset: Offset(2.0, 2.5), + spreadRadius: 0.5) + ], + ), + ), + const SizedBox(height: 12), + const Text( + "Payer par QR-Code", + textAlign: TextAlign.center, + style: TextStyle(color: Colors.black, fontSize: 16), + ) + ]) + ]), + ), + Padding( + padding: const EdgeInsets.only(top: 50), + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Column(children: [ + Container( + child: ClipOval( + child: Material( + color: const Color(0xffFFD58D), // button color + child: InkWell( + splashColor: orangeC, // inkwell color + child: const Padding( + padding: EdgeInsets.symmetric( + horizontal: 20, vertical: 16), + child: Image( + image: + AssetImage('assets/blockchain.png'), + height: 70)), + onTap: () { + // Navigator.push( + // context, + // MaterialPageRoute( + // builder: (context) { + // return TemplateScreen(); + // }), + // ); + }), + ), + ), + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Colors.grey, + blurRadius: 4.0, + offset: Offset(2.0, 2.5), + spreadRadius: 0.5) + ], + ), + ), + const SizedBox(height: 12), + const Text( + "Explorer\n", + textAlign: TextAlign.center, + style: TextStyle(color: Colors.black, fontSize: 16), + ) + ]), + const SizedBox(width: 140), + Column(children: [ + Container( + child: ClipOval( + key: const Key('manageWallets'), + child: Material( + color: const Color(0xffFFD58D), // button color + child: InkWell( + splashColor: orangeC, // inkwell color + child: const Padding( + padding: EdgeInsets.all(23), + child: Image( + image: AssetImage('assets/lock.png'), + height: 57)), + onTap: () { + WalletData defaultWallet = + _myWalletProvider.getDefaultWallet( + configBox.get('currentChest')); + isWalletsExists + ? Navigator.push(context, + MaterialPageRoute(builder: (context) { + return UnlockingWallet( + wallet: defaultWallet, + action: "mywallets", + ); + })) + + // Navigator.pushNamed( + // context, '/mywallets') + : Navigator.push(context, + MaterialPageRoute(builder: (context) { + return const NoKeyChainScreen(); + })); + }), + ), + ), + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: Colors.white, + boxShadow: [ + BoxShadow( + color: Colors.grey, + blurRadius: 4.0, + offset: Offset(2.0, 2.5), + spreadRadius: 0.5) + ], + ), + ), + const SizedBox(height: 12), + const Text( + "Gérer mes\nportefeuilles", + textAlign: TextAlign.center, + style: TextStyle(color: Colors.black, fontSize: 16), + ) + ]) + ]), + ) + ]), + // bottomNavigationBar: BottomNavigationBar( + // backgroundColor: Color(0xffFFD58D), + // fixedColor: Colors.grey[850], + // unselectedItemColor: Color(0xffBD935C), + // type: BottomNavigationBarType.fixed, + // onTap: (index) { + // _homeProvider.currentIndex = index; + // }, + // currentIndex: _homeProvider.currentIndex, + // items: [ + // BottomNavigationBarItem( + // icon: Image.asset('assets/block-space-disabled.png', height: 26), + // activeIcon: Image.asset('assets/blockchain.png', height: 26), + // label: 'Explorateur', + // ), + // BottomNavigationBarItem( + // icon: Icon(Icons.lock), + // label: 'Mes portefeuilles', + // ), + // ], + // ), + ), + ), + ); } } class StatefulWrapper extends StatefulWidget { final Function onInit; final Widget child; - const StatefulWrapper({@required this.onInit, @required this.child}); + const StatefulWrapper({Key key, @required this.onInit, @required this.child}) + : super(key: key); @override _StatefulWrapperState createState() => _StatefulWrapperState(); } diff --git a/lib/screens/myWallets/cesium_wallet_options.dart b/lib/screens/myWallets/cesium_wallet_options.dart new file mode 100644 index 0000000..1d8854d --- /dev/null +++ b/lib/screens/myWallets/cesium_wallet_options.dart @@ -0,0 +1,352 @@ +import 'dart:io'; +import 'dart:ui'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:gecko/globals.dart'; +import 'package:gecko/models/chest_data.dart'; +import 'package:gecko/models/chest_provider.dart'; +import 'package:gecko/models/history.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/models/queries.dart'; +import 'package:gecko/models/wallet_options.dart'; +import 'package:gecko/screens/myWallets/change_pin.dart'; +import 'package:graphql_flutter/graphql_flutter.dart'; +import 'package:provider/provider.dart'; +import 'package:flutter/services.dart'; + +int _nbrLinesName = 1; +bool _isNewNameValid = false; + +Widget cesiumWalletOptions(BuildContext context, ChestData cesiumWallet, + MyWalletsProvider _myWalletProvider) { + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); + WalletOptionsProvider _walletOptions = + Provider.of(context); + ChestProvider _chestProvider = + Provider.of(context, listen: false); + HistoryProvider _historyProvider = Provider.of(context); + + final String shortPubkey = + _walletOptions.getShortPubkey(_walletOptions.pubkey.text); + + if (_walletOptions.nameController.text == null || _isNewNameValid == false) { + _walletOptions.nameController.text = cesiumWallet.name; + } else { + cesiumWallet.name = _walletOptions.nameController.text; + } + + _walletOptions.nameController.text.length >= 15 + ? _nbrLinesName = 2 + : _nbrLinesName = 1; + if (_walletOptions.nameController.text.length >= 26 && isTall) { + _nbrLinesName = 3; + } + + return Scaffold( + resizeToAvoidBottomInset: false, + body: Builder( + builder: (ctx) => SafeArea( + child: Column(children: [ + Container( + height: isTall ? 30 : 15, + color: yellowC, + ), + Container( + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.topCenter, + end: Alignment.bottomCenter, + colors: [ + yellowC, + const Color(0xfffafafa), + ], + )), + child: Row(children: [ + const SizedBox(width: 25), + InkWell( + onTap: () async { + File newAvatar = await _walletOptions.changeAvatar(); + if (newAvatar != null) { + cesiumWallet.imageFile = newAvatar; + } + _walletOptions.reloadBuild(); + }, + child: cesiumWallet.imageFile == null + ? Image.asset( + 'assets/chests/${cesiumWallet.imageName}', + width: 110, + ) + : Image.file(cesiumWallet.imageFile, width: 110), + ), + InkWell( + onTap: () async { + File newAvatar = await _walletOptions.changeAvatar(); + if (newAvatar != null) { + cesiumWallet.imageFile = newAvatar; + } + _walletOptions.reloadBuild(); + }, + child: Column(children: [ + Image.asset( + 'assets/walletOptions/camera.png', + ), + const SizedBox(height: 100) + ])), + Column(children: [ + Row(children: [ + Column(children: [ + SizedBox( + width: 260, + child: TextField( + key: const Key('walletName'), + autofocus: false, + focusNode: _walletOptions.walletNameFocus, + enabled: _walletOptions.isEditing, + controller: _walletOptions.nameController, + maxLines: _nbrLinesName, + textAlign: TextAlign.center, + decoration: const InputDecoration( + border: InputBorder.none, + focusedBorder: InputBorder.none, + enabledBorder: InputBorder.none, + disabledBorder: InputBorder.none, + contentPadding: EdgeInsets.all(15.0), + ), + style: TextStyle( + fontSize: isTall ? 27 : 23, + color: Colors.black, + fontWeight: FontWeight.w400, + fontFamily: 'Monospace')), + ), + SizedBox(height: isTall ? 5 : 0), + Query( + options: QueryOptions( + document: gql(getBalance), + variables: { + 'pubkey': _walletOptions.pubkey.text, + }, + // pollInterval: Duration(seconds: 1), + ), + builder: (QueryResult result, + {VoidCallback refetch, FetchMore fetchMore}) { + if (result.hasException) { + return Text(result.exception.toString()); + } + + if (result.isLoading) { + return const Text('Loading'); + } + + // List repositories = result.data['viewer']['repositories']['nodes']; + String wBalanceUD; + if (result.data['balance'] == null) { + wBalanceUD = '0.0'; + } else { + int wBalanceG1 = result.data['balance']['amount']; + int currentUD = result.data['currentUd']['amount']; + double wBalanceUDBrut = + wBalanceG1 / currentUD; // .toString(); + wBalanceUD = double.parse( + (wBalanceUDBrut).toStringAsFixed(2)) + .toString(); + } + return Row(children: [ + ImageFiltered( + imageFilter: ImageFilter.blur( + sigmaX: _walletOptions.isBalanceBlur ? 6 : 0, + sigmaY: _walletOptions.isBalanceBlur ? 5 : 0), + child: Text(wBalanceUD, + style: TextStyle( + fontSize: isTall ? 20 : 18, + color: Colors.black)), + ), + Text(' DU', + style: TextStyle( + fontSize: isTall ? 20 : 18, + color: Colors.black)) + ]); + + // Text( + // '$wBalanceUD DU', + // style: TextStyle( + // fontSize: 20, color: Colors.black), + // ); + }, + ), + const SizedBox(height: 5), + InkWell( + key: const Key('displayBalance'), + onTap: () { + _walletOptions.bluringBalance(); + }, + child: Image.asset( + _walletOptions.isBalanceBlur + ? 'assets/walletOptions/icon_oeuil.png' + : 'assets/walletOptions/icon_oeuil_close.png', + )), + ]), + const SizedBox(width: 0), + Column(children: [ + InkWell( + key: const Key('renameWallet'), + onTap: () async { + _isNewNameValid = _walletOptions.editWalletName( + [cesiumWallet.key, 0], + isCesium: cesiumWallet.isCesium); + await Future.delayed( + const Duration(milliseconds: 30)); + _walletOptions.walletNameFocus.requestFocus(); + }, + child: ClipRRect( + child: Image.asset( + _walletOptions.isEditing + ? 'assets/walletOptions/android-checkmark.png' + : 'assets/walletOptions/edit.png', + width: 20, + height: 20), + )), + const SizedBox( + height: 60, + ) + ]) + ]), + ]), + ])), + SizedBox(height: 4 * ratio), + FutureBuilder( + future: _walletOptions.generateQRcode(_walletOptions.pubkey.text), + builder: (context, snapshot) { + return snapshot.data != null + ? Image.memory(snapshot.data, height: isTall ? 300 : 270) + : const Text('-', style: TextStyle(fontSize: 20)); + }), + SizedBox(height: 15 * ratio), + GestureDetector( + key: const Key('copyPubkey'), + onTap: () { + Clipboard.setData( + ClipboardData(text: _walletOptions.pubkey.text)); + _walletOptions.snackCopyKey(ctx); + }, + child: SizedBox( + height: 50, + child: Row(children: [ + const SizedBox(width: 30), + Image.asset( + 'assets/walletOptions/key.png', + ), + const SizedBox(width: 20), + Text("${shortPubkey.split(':')[0]}:", + style: const TextStyle( + fontSize: 22, + fontWeight: FontWeight.w800, + fontFamily: 'Monospace', + color: Colors.black)), + Text(shortPubkey.split(':')[1], + style: const TextStyle( + fontSize: 22, + fontWeight: FontWeight.w800, + fontFamily: 'Monospace')), + const SizedBox(width: 15), + SizedBox( + height: 40, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + ), + elevation: 1, + primary: orangeC, // background + onPrimary: Colors.black, // foreground + ), + onPressed: () { + Clipboard.setData(ClipboardData( + text: _walletOptions.pubkey.text)); + _walletOptions.snackCopyKey(ctx); + }, + child: Row(children: [ + Image.asset( + 'assets/walletOptions/copy-white.png', + ), + const SizedBox(width: 7), + Text('Copier', + style: TextStyle( + fontSize: 15, color: Colors.grey[50])) + ]))), + ]))), + SizedBox(height: 10 * ratio), + InkWell( + key: const Key('displayHistory'), + onTap: () { + _historyProvider.isPubkey(ctx, _walletOptions.pubkey.text, + goHistory: true); + }, + child: SizedBox( + height: 50, + child: Row(children: [ + const SizedBox(width: 30), + Image.asset( + 'assets/walletOptions/clock.png', + ), + const SizedBox(width: 22), + const Text('Historique des transactions', + style: TextStyle(fontSize: 20, color: Colors.black)), + ]))), + SizedBox(height: 7 * ratio), + InkWell( + key: const Key('changePin'), + onTap: () async { + // await _chestProvider.changePin(context, cesiumWallet); + _myWalletProvider.pinCode = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return ChangePinScreen( + walletName: cesiumWallet.name, + walletProvider: _myWalletProvider, + ); + }, + ), + ); + }, + child: SizedBox( + height: 50, + child: Row(children: [ + const SizedBox(width: 28), + Image.asset( + 'assets/chests/secret_code.png', + ), + const SizedBox(width: 18), + const Text('Changer mon code secret', + style: TextStyle(fontSize: 20, color: Colors.black)), + ])), + ), + SizedBox(height: 7 * ratio), + InkWell( + key: const Key('deleteWallet'), + onTap: () async { + await _chestProvider.deleteChest(context, cesiumWallet); + }, + child: SizedBox( + height: 50, + child: Row(children: [ + const SizedBox(width: 33), + Image.asset( + 'assets/walletOptions/trash.png', + ), + const SizedBox(width: 25), + const Text( + 'Supprimer ce coffre', + style: TextStyle( + fontSize: 20, + color: Color(0xffD80000), + ), + ), + ]), + ), + ), + ]), + ), + ), + ); +} diff --git a/lib/screens/myWallets/changePin.dart b/lib/screens/myWallets/changePin.dart deleted file mode 100644 index 19a87f0..0000000 --- a/lib/screens/myWallets/changePin.dart +++ /dev/null @@ -1,103 +0,0 @@ -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; -import 'package:dubp/dubp.dart'; -import 'package:flutter/services.dart'; -import 'package:gecko/globals.dart'; -import 'package:gecko/models/changePin.dart'; -import 'dart:io'; -import 'package:provider/provider.dart'; - -// ignore: must_be_immutable -class ChangePinScreen extends StatelessWidget with ChangeNotifier { - ChangePinScreen( - {Key keyMyWallets, @required this.walletName, @required this.oldPin}) - : super(key: keyMyWallets); - final String walletName; - final oldPin; - Directory appPath; - NewWallet _newWalletFile; - - @override - Widget build(BuildContext context) { - SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - ChangePinProvider _changePin = Provider.of(context); - // _walletOptions.changePin(walletName, oldPin); - // _walletOptions.newPin.text = _tmpPin; - return WillPopScope( - onWillPop: () { - _changePin.newPin.text = ''; - return Future.value(true); - }, - child: Scaffold( - resizeToAvoidBottomInset: false, - appBar: AppBar( - leading: IconButton( - icon: Icon(Icons.arrow_back, color: Colors.black), - onPressed: () { - _changePin.newPin.text = ''; - Navigator.of(context).pop(); - }), - title: SizedBox( - height: 22, - child: Text(walletName), - )), - body: Center( - child: SafeArea( - child: Column(children: [ - SizedBox(height: 80), - Text( - 'Choisissez un code secret autogénéré :', - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 17.0, - color: Colors.grey[600], - fontWeight: FontWeight.w400), - ), - SizedBox(height: 30), - Container( - child: Stack( - alignment: Alignment.centerRight, - children: [ - TextField( - enabled: true, - controller: _changePin.newPin, - maxLines: 1, - textAlign: TextAlign.center, - decoration: InputDecoration(), - style: TextStyle( - fontSize: 30.0, - color: Colors.black, - fontWeight: FontWeight.bold)), - IconButton( - icon: Icon(Icons.replay), - color: orangeC, - onPressed: () async { - _newWalletFile = - await _changePin.changePin(walletName, oldPin); - }, - ), - ], - ), - ), - SizedBox(height: 30), - SizedBox( - width: 200, - height: 50, - child: ElevatedButton( - style: ElevatedButton.styleFrom( - elevation: 12, - primary: Colors.green[400], //smoothYellow, // background - onPrimary: Colors.black, // foreground - ), - onPressed: _changePin.newPin.text != '' - ? () { - _changePin.newPin.text = ''; - _changePin.storeWallet( - context, walletName, _newWalletFile); - } - : null, - child: Text('Confirmer', style: TextStyle(fontSize: 28))), - ) - ]))))); - } -} diff --git a/lib/screens/myWallets/change_pin.dart b/lib/screens/myWallets/change_pin.dart new file mode 100644 index 0000000..25ba873 --- /dev/null +++ b/lib/screens/myWallets/change_pin.dart @@ -0,0 +1,113 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:dubp/dubp.dart'; +import 'package:flutter/services.dart'; +import 'package:gecko/globals.dart'; +import 'package:gecko/models/change_pin.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'dart:io'; +import 'package:provider/provider.dart'; + +// ignore: must_be_immutable +class ChangePinScreen extends StatelessWidget with ChangeNotifier { + ChangePinScreen( + {Key keyMyWallets, + @required this.walletName, + @required this.walletProvider}) + : super(key: keyMyWallets); + final String walletName; + final MyWalletsProvider walletProvider; + Directory appPath; + NewWallet _newWalletFile; + + @override + Widget build(BuildContext context) { + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); + ChangePinProvider _changePin = Provider.of(context); + // _walletOptions.changePin(walletName, oldPin); + // _walletOptions.newPin.text = _tmpPin; + return WillPopScope( + onWillPop: () { + _changePin.newPin.text = ''; + return Future.value(true); + }, + child: Scaffold( + resizeToAvoidBottomInset: false, + appBar: AppBar( + toolbarHeight: 60 * ratio, + leading: IconButton( + icon: const Icon(Icons.arrow_back, color: Colors.black), + onPressed: () { + _changePin.newPin.text = ''; + Navigator.of(context).pop(); + }), + title: SizedBox( + height: 22, + child: Text(walletName), + )), + body: Center( + child: SafeArea( + child: Column(children: [ + const SizedBox(height: 80), + Text( + 'Choisissez un code secret autogénéré :', + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 17.0, + color: Colors.grey[600], + fontWeight: FontWeight.w400), + ), + const SizedBox(height: 30), + Stack( + alignment: Alignment.centerRight, + children: [ + TextField( + enabled: false, + controller: _changePin.newPin, + maxLines: 1, + textAlign: TextAlign.center, + decoration: const InputDecoration(), + style: const TextStyle( + fontSize: 30.0, + color: Colors.black, + fontWeight: FontWeight.bold)), + IconButton( + icon: const Icon(Icons.replay), + color: orangeC, + onPressed: () async { + _newWalletFile = + await _changePin.changePin(walletProvider.pinCode); + }, + ), + ], + ), + const SizedBox(height: 30), + SizedBox( + width: 200, + height: 50, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + elevation: 12, + primary: Colors.green[400], //smoothYellow, // background + onPrimary: Colors.black, // foreground + ), + onPressed: _changePin.newPin.text != '' + ? () { + _changePin.newPin.text = ''; + _changePin.storeNewPinChest(context, _newWalletFile); + walletProvider.pinCode = _changePin.newPin.text; + } + : null, + child: const Text( + 'Confirmer', + style: TextStyle(fontSize: 28), + ), + ), + ) + ]), + ), + ), + ), + ); + } +} diff --git a/lib/screens/myWallets/chest_options.dart b/lib/screens/myWallets/chest_options.dart new file mode 100644 index 0000000..dfae9b7 --- /dev/null +++ b/lib/screens/myWallets/chest_options.dart @@ -0,0 +1,102 @@ +import 'dart:ui'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; +import 'package:gecko/globals.dart'; +import 'package:gecko/models/chest_data.dart'; +import 'package:flutter/services.dart'; +import 'package:gecko/models/chest_provider.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/screens/myWallets/change_pin.dart'; +import 'package:provider/provider.dart'; + +class ChestOptions extends StatelessWidget { + const ChestOptions({Key keyMyWallets, @required this.walletProvider}) + : super(key: keyMyWallets); + final MyWalletsProvider walletProvider; + + @override + Widget build(BuildContext context) { + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); + ChestProvider _chestProvider = + Provider.of(context, listen: false); + + ChestData currentChest = chestBox.get(configBox.get('currentChest')); + + return Scaffold( + resizeToAvoidBottomInset: false, + appBar: AppBar( + toolbarHeight: 60 * ratio, + leading: IconButton( + icon: const Icon(Icons.arrow_back, color: Colors.black), + onPressed: () { + Navigator.popUntil( + context, + ModalRoute.withName('/mywallets'), + ); + }), + title: SizedBox( + height: 22, + child: Text(currentChest.name), + )), + body: Builder( + builder: (ctx) => SafeArea( + child: Column(children: [ + SizedBox(height: 30 * ratio), + InkWell( + key: const Key('changePin'), + onTap: () async { + // await _chestProvider.changePin(context, cesiumWallet); + walletProvider.pinCode = await Navigator.push( + context, + MaterialPageRoute( + builder: (context) { + return ChangePinScreen( + walletName: currentChest.name, + walletProvider: walletProvider, + ); + }, + ), + ); + }, + child: SizedBox( + height: 50, + child: Row(children: [ + const SizedBox(width: 28), + Image.asset( + 'assets/chests/secret_code.png', + ), + const SizedBox(width: 18), + const Text('Changer mon code secret', + style: TextStyle(fontSize: 20, color: Colors.black)), + ])), + ), + SizedBox(height: 10 * ratio), + InkWell( + key: const Key('deleteChest'), + onTap: () async { + await _chestProvider.deleteChest(context, currentChest); + }, + child: SizedBox( + height: 50, + child: Row(children: [ + const SizedBox(width: 33), + Image.asset( + 'assets/walletOptions/trash.png', + ), + const SizedBox(width: 24), + const Text( + 'Supprimer ce coffre', + style: TextStyle( + fontSize: 20, + color: Color(0xffD80000), + ), + ), + ]), + ), + ), + ]), + ), + ), + ); + } +} diff --git a/lib/screens/myWallets/choose_chest.dart b/lib/screens/myWallets/choose_chest.dart new file mode 100644 index 0000000..6377d2e --- /dev/null +++ b/lib/screens/myWallets/choose_chest.dart @@ -0,0 +1,158 @@ +import 'package:flutter/services.dart'; +import 'package:gecko/globals.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/models/wallet_data.dart'; +import 'package:flutter/material.dart'; +import 'package:gecko/screens/myWallets/generate_wallets.dart'; +import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; +import 'package:carousel_slider/carousel_slider.dart'; +import 'package:provider/provider.dart'; + +class ChooseChest extends StatefulWidget { + const ChooseChest({Key key}) : super(key: key); + + @override + State createState() { + return _ChooseChestState(); + } +} + +// ignore: must_be_immutable +class _ChooseChestState extends State { + TextEditingController tplController = TextEditingController(); + CarouselController buttonCarouselController = CarouselController(); + int currentChest = configBox.get('currentChest'); + + @override + Widget build(BuildContext context) { + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); + MyWalletsProvider _myWalletProvider = + Provider.of(context); + + return Scaffold( + appBar: AppBar( + toolbarHeight: 60 * ratio, + title: const SizedBox( + height: 22, + child: Text('Sélectionner mon coffre'), + )), + body: SafeArea( + child: Column(children: [ + SizedBox(height: 160 * ratio), + CarouselSlider( + carouselController: buttonCarouselController, + options: CarouselOptions( + height: 210, + onPageChanged: (index, reason) { + currentChest = chestBox.toMap().keys.toList()[index]; + setState(() {}); + }, + enableInfiniteScroll: false, + initialPage: currentChest, + enlargeCenterPage: true, + viewportFraction: 0.6, + ), + items: chestBox.toMap().entries.map((i) { + return Builder( + builder: (BuildContext context) { + return Column(children: [ + i.value.imageFile == null + ? Image.asset( + 'assets/chests/${i.value.imageName}', + height: 150, + ) + : Image.file( + i.value.imageFile, + height: 150, + ), + const SizedBox(height: 30), + Text( + i.value.name, + style: const TextStyle(fontSize: 21), + ), + ]); + }, + ); + }).toList(), + ), + if (chestBox.values.toList().length > 1) + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: chestBox.toMap().entries.map((entry) { + return GestureDetector( + onTap: () => + buttonCarouselController.animateToPage(entry.key), + child: Container( + width: 12.0, + height: 12.0, + margin: const EdgeInsets.symmetric( + vertical: 8.0, horizontal: 4.0), + decoration: BoxDecoration( + shape: BoxShape.circle, + color: + (Theme.of(context).brightness == Brightness.dark + ? Colors.white + : Colors.black) + .withOpacity( + currentChest == entry.key ? 0.9 : 0.4)), + ), + ); + }).toList(), + ), + SizedBox(height: 80 * ratio), + SizedBox( + width: 400, + height: 70, + child: ElevatedButton( + style: ElevatedButton.styleFrom( + primary: orangeC, // background + onPrimary: Colors.black, // foreground + ), + onPressed: () { + configBox.put('currentChest', currentChest); + WalletData defaultWallet = + _myWalletProvider.getDefaultWallet(currentChest); + _myWalletProvider.rebuildWidget(); + Navigator.pushAndRemoveUntil(context, + MaterialPageRoute(builder: (context) { + return UnlockingWallet( + wallet: defaultWallet, + action: "mywallets", + ); + }), ModalRoute.withName('/')); + }, + child: Text( + 'Ouvrir ce coffre', + style: TextStyle( + fontSize: 22, + color: backgroundColor, + fontWeight: FontWeight.w600), + ), + ), + ), + const SizedBox(height: 20), + InkWell( + key: const Key('createNewChest'), + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return GenerateFastChestScreen(); + }), + ); + }, + child: SizedBox( + width: 400, + height: 70, + child: Center( + child: Text('Créer un nouveau coffre', + style: TextStyle( + fontSize: 22, + color: orangeC, + fontWeight: FontWeight.w600))), + )), + const SizedBox(height: 10), + ]), + )); + } +} diff --git a/lib/screens/myWallets/confirmWalletStorage.dart b/lib/screens/myWallets/confirm_wallet_storage.dart similarity index 81% rename from lib/screens/myWallets/confirmWalletStorage.dart rename to lib/screens/myWallets/confirm_wallet_storage.dart index 0125c55..e822f19 100644 --- a/lib/screens/myWallets/confirmWalletStorage.dart +++ b/lib/screens/myWallets/confirm_wallet_storage.dart @@ -3,9 +3,10 @@ import 'dart:async'; import 'package:dubp/dubp.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:gecko/models/generateWallets.dart'; -import 'package:gecko/models/myWallets.dart'; -import 'package:gecko/models/walletOptions.dart'; +import 'package:gecko/globals.dart'; +import 'package:gecko/models/generate_wallets.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/models/wallet_options.dart'; import 'package:provider/provider.dart'; // ignore: must_be_immutable @@ -19,10 +20,10 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { String generatedMnemonic; NewWallet generatedWallet; - TextEditingController _mnemonicController = TextEditingController(); - TextEditingController _inputRestoreWord = TextEditingController(); + final TextEditingController _mnemonicController = TextEditingController(); + final TextEditingController _inputRestoreWord = TextEditingController(); TextEditingController walletName = TextEditingController(); - FocusNode _wordFocus = FocusNode(); + final FocusNode _wordFocus = FocusNode(); @override Widget build(BuildContext context) { @@ -35,7 +36,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { Provider.of(context); final int _currentChest = _myWalletProvider.getCurrentChest(); - this._mnemonicController.text = generatedMnemonic; + _mnemonicController.text = generatedMnemonic; return WillPopScope( onWillPop: () { _generateWalletProvider.isAskedWordValid = false; @@ -45,21 +46,22 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { child: Scaffold( resizeToAvoidBottomInset: false, appBar: AppBar( + toolbarHeight: 60 * ratio, leading: IconButton( - icon: Icon(Icons.arrow_back, color: Colors.black), + icon: const Icon(Icons.arrow_back, color: Colors.black), onPressed: () { Navigator.of(context).pop(); _generateWalletProvider.isAskedWordValid = false; _generateWalletProvider.askedWordColor = Colors.black; }), - title: SizedBox( + title: const SizedBox( height: 22, child: Text('Enregistrer ce trousseau'), )), body: Center( child: Column(children: [ - SizedBox(height: 15), - Container( + const SizedBox(height: 15), + SizedBox( width: 360, child: Text( 'Quel est le ${_generateWalletProvider.nbrWord + 1}ème mot de votre phrase de restauration ?', @@ -70,11 +72,11 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { fontWeight: FontWeight.w400), )), TextFormField( - key: Key('askedWord'), + key: const Key('askedWord'), focusNode: _wordFocus, autofocus: true, enabled: !_generateWalletProvider.isAskedWordValid, - controller: this._inputRestoreWord, + controller: _inputRestoreWord, textInputAction: TextInputAction.next, onChanged: (value) { _generateWalletProvider.checkAskedWord( @@ -82,13 +84,13 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { }, maxLines: 1, textAlign: TextAlign.center, - decoration: InputDecoration(), + decoration: const InputDecoration(), style: TextStyle( fontSize: 30.0, color: _generateWalletProvider.askedWordColor, fontWeight: FontWeight.w500)), - SizedBox(height: 12), - Container( + const SizedBox(height: 12), + SizedBox( width: 360, child: Text( 'Choisissez un nom pour votre premier portefeuille :', @@ -99,21 +101,21 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { fontWeight: FontWeight.w400), )), TextFormField( - key: Key('walletName'), + key: const Key('walletName'), focusNode: _generateWalletProvider.walletNameFocus, inputFormatters: [ FilteringTextInputFormatter.allow( RegExp('[A-Za-z|0-9|\\-|_| ]')), ], - controller: this.walletName, + controller: walletName, textInputAction: TextInputAction.next, onChanged: (v) { _generateWalletProvider.nameChanged(); }, maxLines: 1, textAlign: TextAlign.center, - decoration: InputDecoration(), - style: TextStyle( + decoration: const InputDecoration(), + style: const TextStyle( fontSize: 30.0, color: Colors.black, fontWeight: FontWeight.w500)), @@ -124,7 +126,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { width: 200, height: 50, child: ElevatedButton( - key: Key('confirmStorage'), + key: const Key('confirmStorage'), style: ElevatedButton.styleFrom( elevation: 12, primary: Colors @@ -133,7 +135,7 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { ), onPressed: (_generateWalletProvider .isAskedWordValid && - this.walletName.text != '') + walletName.text != '') ? () { _generateWalletProvider.storeHDWChest( generatedWallet, @@ -146,7 +148,6 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { _myWalletProvider.listWallets = _myWalletProvider .readAllWallets(_currentChest); - _myWalletProvider.getDefaultWallet(); scheduleMicrotask(() { _walletOptions.reloadBuild(); _myWalletProvider.rebuildWidget(); @@ -155,12 +156,12 @@ class ConfirmStoreWallet extends StatelessWidget with ChangeNotifier { context, ModalRoute.withName('/')); } : null, - child: Text('Confirmer', + child: const Text('Confirmer', style: TextStyle(fontSize: 28))), ))), - SizedBox(height: 70), - Text('TRICHE PENDANT ALPHA: ' + this._mnemonicController.text, - style: TextStyle( + const SizedBox(height: 70), + Text('TRICHE PENDANT ALPHA: ' + _mnemonicController.text, + style: const TextStyle( fontSize: 10.0, color: Colors.black, fontWeight: FontWeight.normal)), diff --git a/lib/screens/myWallets/generateWallets.dart b/lib/screens/myWallets/generate_wallets.dart similarity index 60% rename from lib/screens/myWallets/generateWallets.dart rename to lib/screens/myWallets/generate_wallets.dart index b1d623e..b85fdba 100644 --- a/lib/screens/myWallets/generateWallets.dart +++ b/lib/screens/myWallets/generate_wallets.dart @@ -1,22 +1,26 @@ import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/models/generateWallets.dart'; -import 'package:gecko/screens/myWallets/confirmWalletStorage.dart'; +import 'package:gecko/models/generate_wallets.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/screens/myWallets/confirm_wallet_storage.dart'; import 'package:flutter/material.dart'; +import 'package:gecko/screens/myWallets/unlocking_wallet.dart'; import 'package:printing/printing.dart'; import 'package:provider/provider.dart'; import 'package:super_tooltip/super_tooltip.dart'; // ignore: must_be_immutable -class GenerateWalletsScreen extends StatelessWidget { +class GenerateFastChestScreen extends StatelessWidget { SuperTooltip tooltip; bool hasError = false; String validPin = 'NO PIN'; String currentText = ""; var pinColor = Colors.grey[300]; - GlobalKey _toolTipSentence = GlobalKey(); - GlobalKey _toolTipSecret = GlobalKey(); + final GlobalKey _toolTipSentence = GlobalKey(); + final GlobalKey _toolTipSecret = GlobalKey(); + + GenerateFastChestScreen({Key key}) : super(key: key); @override Widget build(BuildContext context) { @@ -25,20 +29,23 @@ class GenerateWalletsScreen extends StatelessWidget { Provider.of(context); _generateWalletProvider.generateMnemonic(); + MyWalletsProvider _myWalletClass = MyWalletsProvider(); + return Scaffold( appBar: AppBar( - title: SizedBox( - height: 22, - child: Text('Générer un trousseau'), - )), - floatingActionButton: Container( + toolbarHeight: 60 * ratio, + title: const SizedBox( + height: 22, + child: Text('Générer un trousseau'), + )), + floatingActionButton: SizedBox( height: 80.0, width: 80.0, child: FittedBox( child: FloatingActionButton( heroTag: "buttonGenerateWallet", onPressed: () => _generateWalletProvider.generateMnemonic(), - child: Container( + child: SizedBox( height: 40.0, width: 40.0, child: Icon(Icons.replay, color: Colors.grey[850]), @@ -49,7 +56,7 @@ class GenerateWalletsScreen extends StatelessWidget { body: Builder( builder: (ctx) => SafeArea( child: Column(children: [ - SizedBox(height: 20), + const SizedBox(height: 20), toolTips(_toolTipSentence, 'Phrase de restauration:', "Notez et gardez cette phrase précieusement sur un papier, elle vous servira à restaurer votre portefeuille sur un autre appareil"), TextField( @@ -57,54 +64,52 @@ class GenerateWalletsScreen extends StatelessWidget { controller: _generateWalletProvider.mnemonicController, maxLines: 3, textAlign: TextAlign.center, - decoration: InputDecoration( + decoration: const InputDecoration( contentPadding: EdgeInsets.all(15.0), ), - style: TextStyle( + style: const TextStyle( fontSize: 22.0, color: Colors.black, fontWeight: FontWeight.w400)), - SizedBox(height: 8), + const SizedBox(height: 8), toolTips(_toolTipSecret, 'Code secret:', "Retenez bien votre code secret, il vous sera demandé à chaque paiement, ainsi que pour configurer votre portefeuille"), - Container( - child: Stack( - alignment: Alignment.centerRight, - children: [ - TextField( - key: Key('generatedPin'), - enabled: false, - controller: _generateWalletProvider.pin, - maxLines: 1, - textAlign: TextAlign.center, - decoration: InputDecoration(), - style: TextStyle( - fontSize: 30.0, - color: Colors.black, - fontWeight: FontWeight.bold)), - IconButton( - icon: Icon(Icons.replay), - color: orangeC, - onPressed: () { - _generateWalletProvider.changePinCode( - reload: false); - }, - ), - ], - ), + Stack( + alignment: Alignment.centerRight, + children: [ + TextField( + key: const Key('generatedPin'), + enabled: false, + controller: _generateWalletProvider.pin, + maxLines: 1, + textAlign: TextAlign.center, + decoration: const InputDecoration(), + style: const TextStyle( + fontSize: 30.0, + color: Colors.black, + fontWeight: FontWeight.bold)), + IconButton( + icon: const Icon(Icons.replay), + color: orangeC, + onPressed: () { + _generateWalletProvider.changePinCode( + reload: false); + }, + ), + ], ), - SizedBox(height: 20), + const SizedBox(height: 20), ElevatedButton( - key: Key('storeKeychain'), + key: const Key('storeKeychain'), style: ElevatedButton.styleFrom( primary: yellowC, // background onPrimary: Colors.black, // foreground ), onPressed: _generateWalletProvider.walletIsGenerated - ? () { + ? () async { _generateWalletProvider.nbrWord = _generateWalletProvider.getRandomInt(); - Navigator.push( + await Navigator.push( context, MaterialPageRoute(builder: (context) { return ConfirmStoreWallet( @@ -115,11 +120,21 @@ class GenerateWalletsScreen extends StatelessWidget { .actualWallet); }), ); + await Future.delayed( + const Duration(milliseconds: 20)); + await Navigator.pushAndRemoveUntil(context, + MaterialPageRoute(builder: (context) { + return UnlockingWallet( + wallet: _myWalletClass.getDefaultWallet( + configBox.get('currentChest')), + action: "mywallets", + ); + }), ModalRoute.withName('/')); } : null, - child: Text('Enregistrer ce trousseau', + child: const Text('Enregistrer ce trousseau', style: TextStyle(fontSize: 20))), - SizedBox(height: 20), + const SizedBox(height: 20), GestureDetector( onTap: () { Navigator.push( @@ -130,7 +145,7 @@ class GenerateWalletsScreen extends StatelessWidget { }), ); }, - child: Icon(Icons.print)) + child: const Icon(Icons.print)) ]), ))); } @@ -142,21 +157,21 @@ class GenerateWalletsScreen extends StatelessWidget { _toolTip.ensureTooltipVisible(); }, child: Tooltip( - padding: EdgeInsets.all(10), + padding: const EdgeInsets.all(10), key: _key, - showDuration: Duration(seconds: 5), + showDuration: const Duration(seconds: 5), message: _message, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - SizedBox(width: 20), + const SizedBox(width: 20), Column(children: [ SizedBox( width: 30, height: 25, child: Icon(Icons.info_outline, size: 22, color: orangeC)), - SizedBox(height: 1) + const SizedBox(height: 1) ]), Text( _text, @@ -165,14 +180,14 @@ class GenerateWalletsScreen extends StatelessWidget { color: Colors.grey[600], fontWeight: FontWeight.w400), ), - SizedBox(width: 45) + const SizedBox(width: 45) ]))); } } // ignore: must_be_immutable class PrintWallet extends StatelessWidget { - PrintWallet(this.sentence); + const PrintWallet(this.sentence, {Key key}) : super(key: key); final String sentence; @@ -182,7 +197,9 @@ class PrintWallet extends StatelessWidget { Provider.of(context); return MaterialApp( home: Scaffold( - appBar: AppBar(title: Text('Imprimer ce trousseau')), + appBar: AppBar( + toolbarHeight: 60 * ratio, + title: const Text('Imprimer ce trousseau')), body: PdfPreview( build: (format) => _generateWalletProvider.printWallet(sentence), ), diff --git a/lib/screens/myWallets/importWallet.dart b/lib/screens/myWallets/import_wallet.dart similarity index 73% rename from lib/screens/myWallets/importWallet.dart rename to lib/screens/myWallets/import_wallet.dart index c825d74..5a86fc8 100644 --- a/lib/screens/myWallets/importWallet.dart +++ b/lib/screens/myWallets/import_wallet.dart @@ -1,13 +1,15 @@ import 'dart:async'; import 'package:flutter/services.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/models/generateWallets.dart'; +import 'package:gecko/models/generate_wallets.dart'; import 'package:flutter/material.dart'; -import 'package:gecko/models/myWallets.dart'; -import 'package:gecko/models/walletOptions.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/models/wallet_options.dart'; import 'package:provider/provider.dart'; class ImportWalletScreen extends StatelessWidget { + const ImportWalletScreen({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -27,26 +29,26 @@ class ImportWalletScreen extends StatelessWidget { }, child: Scaffold( appBar: AppBar( + toolbarHeight: 60 * ratio, leading: IconButton( - icon: Icon(Icons.arrow_back, color: Colors.black), + icon: const Icon(Icons.arrow_back, color: Colors.black), onPressed: () { _generateWalletProvider.resetImportView(); Navigator.of(context).pop(); }), - title: SizedBox( + title: const SizedBox( height: 22, child: Text('Importer un portefeuille'), )), body: Builder( builder: (ctx) => SafeArea( child: Column(children: [ - SizedBox(height: 20), + const SizedBox(height: 20), TextFormField( onChanged: (text) { - if (_debounce?.isActive ?? false) - // _generateWalletProvider.canImport = false; - // _generateWalletProvider.reloadBuild(); + if (_debounce?.isActive ?? false) { _debounce.cancel(); + } _debounce = Timer(const Duration(milliseconds: 200), () { _generateWalletProvider @@ -77,13 +79,12 @@ class ImportWalletScreen extends StatelessWidget { ), ), ), - SizedBox(height: 15), + const SizedBox(height: 15), TextFormField( onChanged: (text) { - if (_debounce?.isActive ?? false) - // _generateWalletProvider.canImport = false; - // _generateWalletProvider.reloadBuild(); + if (_debounce?.isActive ?? false) { _debounce.cancel(); + } _debounce = Timer(const Duration(milliseconds: 200), () { _generateWalletProvider @@ -115,7 +116,7 @@ class ImportWalletScreen extends StatelessWidget { ), ), ), - SizedBox(height: 15), + const SizedBox(height: 15), GestureDetector( onTap: () { Clipboard.setData(ClipboardData( @@ -125,41 +126,39 @@ class ImportWalletScreen extends StatelessWidget { }, child: Text( _generateWalletProvider.cesiumPubkey.text, - style: TextStyle( + style: const TextStyle( fontSize: 14.0, color: Colors.black, fontWeight: FontWeight.bold, fontFamily: 'Monospace'), )), - SizedBox(height: 20), + const SizedBox(height: 20), toolTips(_toolTipSecret, 'Code secret:', "Retenez bien votre code secret, il vous sera demandé à chaque paiement, ainsi que pour configurer votre portefeuille"), - Container( - child: Stack( - alignment: Alignment.centerRight, - children: [ - TextField( - enabled: false, - controller: _generateWalletProvider.pin, - maxLines: 1, - textAlign: TextAlign.center, - decoration: InputDecoration(), - style: TextStyle( - fontSize: 30.0, - color: Colors.black, - fontWeight: FontWeight.bold)), - IconButton( - icon: Icon(Icons.replay), - color: orangeC, - onPressed: () { - _generateWalletProvider.changePinCode( - reload: true); - }, - ), - ], - ), + Stack( + alignment: Alignment.centerRight, + children: [ + TextField( + enabled: false, + controller: _generateWalletProvider.pin, + maxLines: 1, + textAlign: TextAlign.center, + decoration: const InputDecoration(), + style: const TextStyle( + fontSize: 30.0, + color: Colors.black, + fontWeight: FontWeight.bold)), + IconButton( + icon: const Icon(Icons.replay), + color: orangeC, + onPressed: () { + _generateWalletProvider.changePinCode( + reload: true); + }, + ), + ], ), - SizedBox(height: 30), + const SizedBox(height: 30), ElevatedButton( style: ElevatedButton.styleFrom( primary: yellowC, // background @@ -169,19 +168,18 @@ class ImportWalletScreen extends StatelessWidget { _generateWalletProvider.isPinChanged ? () { _generateWalletProvider - .importWallet( - context, - _generateWalletProvider - .cesiumID.text, - _generateWalletProvider - .cesiumPWD.text) + .importCesiumWallet() .then((value) { _myWalletProvider.rebuildWidget(); _generateWalletProvider.resetImportView(); + Navigator.popUntil( + context, + ModalRoute.withName('/'), + ); }); } : null, - child: Text('Importer ce portefeuille Cesium', + child: const Text('Importer ce portefeuille Cesium', style: TextStyle(fontSize: 20))), ]), )))); @@ -194,21 +192,21 @@ class ImportWalletScreen extends StatelessWidget { _toolTip.ensureTooltipVisible(); }, child: Tooltip( - padding: EdgeInsets.all(10), + padding: const EdgeInsets.all(10), key: _key, - showDuration: Duration(seconds: 5), + showDuration: const Duration(seconds: 5), message: _message, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - SizedBox(width: 20), + const SizedBox(width: 20), Column(children: [ SizedBox( width: 30, height: 25, child: Icon(Icons.info_outline, size: 22, color: orangeC)), - SizedBox(height: 1) + const SizedBox(height: 1) ]), Text( _text, @@ -217,7 +215,7 @@ class ImportWalletScreen extends StatelessWidget { color: Colors.grey[600], fontWeight: FontWeight.w400), ), - SizedBox(width: 45) + const SizedBox(width: 45) ]))); } } diff --git a/lib/screens/myWallets/unlockingWallet.dart b/lib/screens/myWallets/unlocking_wallet.dart similarity index 56% rename from lib/screens/myWallets/unlockingWallet.dart rename to lib/screens/myWallets/unlocking_wallet.dart index 610edc2..65c1b5f 100644 --- a/lib/screens/myWallets/unlockingWallet.dart +++ b/lib/screens/myWallets/unlocking_wallet.dart @@ -1,11 +1,13 @@ import 'dart:async'; import 'package:dubp/dubp.dart'; import 'package:flutter/services.dart'; +import 'package:gecko/models/chest_data.dart'; import 'package:gecko/models/history.dart'; -import 'package:gecko/models/myWallets.dart'; -import 'package:gecko/models/walletData.dart'; -import 'package:gecko/models/walletOptions.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/models/wallet_data.dart'; +import 'package:gecko/models/wallet_options.dart'; import 'package:flutter/material.dart'; +import 'package:gecko/screens/myWallets/choose_chest.dart'; import 'package:pin_code_fields/pin_code_fields.dart'; import 'package:provider/provider.dart'; import 'package:gecko/globals.dart'; @@ -21,8 +23,7 @@ class UnlockingWallet extends StatelessWidget { // ignore: close_sinks StreamController errorController; final formKey = GlobalKey(); - bool hasError = false; - var pinColor = Color(0xffF9F9F1); + var pinColor = const Color(0xffF9F9F1); var walletPin = ''; String resultPay; @@ -34,43 +35,87 @@ class UnlockingWallet extends StatelessWidget { WalletOptionsProvider _walletOptions = Provider.of(context); - // log.d("defaultWallet: " + defaultWallet.toString()); - final int _pinLenght = _walletOptions.getPinLenght(wallet.number); + int _pinLenght; + + ChestData currentChest = chestBox.get(configBox.get('currentChest')); + + if (currentChest.isCesium) { + _pinLenght = _walletOptions.getPinLenght(currentChest.dewif); + wallet = WalletData(derivation: -1, chest: currentChest.key); + } else { + _pinLenght = _walletOptions.getPinLenght(wallet.number); + } errorController = StreamController(); return Scaffold( // backgroundColor: Colors.brown[600], body: SafeArea( child: Column(children: [ - SizedBox(height: 20), Expanded( child: Column(children: [ - SizedBox(height: 150), - Text( - 'Veuillez tapper votre code secret pour dévérouiller votre portefeuille.', - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 15.0, - color: Colors.black, - fontWeight: FontWeight.w400), - ), - SizedBox(height: 50), - pinForm(context, _pinLenght, wallet.number, wallet.derivation), + SizedBox(height: isTall ? 80 : 20), + Row(mainAxisAlignment: MainAxisAlignment.center, children: [ + currentChest.imageFile == null + ? Image.asset( + 'assets/chests/${currentChest.imageName}', + width: isTall ? 130 : 100, + ) + : Image.file( + currentChest.imageFile, + width: isTall ? 130 : 100, + ), + const SizedBox(width: 5), + SizedBox( + width: 250, + child: Text( + currentChest.name, + textAlign: TextAlign.center, + style: const TextStyle( + fontSize: 25, + color: Colors.black, + fontWeight: FontWeight.w700), + )), + ]), + SizedBox(height: 30 * ratio), + const SizedBox( + width: 400, + child: Text( + 'Pour déverrouiller votre coffre, composez votre code secret à l’abri des lézards indiscrets :', + style: TextStyle( + fontSize: 19, + color: Colors.black, + fontWeight: FontWeight.w400), + )), + SizedBox(height: 40 * ratio), + pinForm(context, _pinLenght), + SizedBox(height: 3 * ratio), + InkWell( + key: const Key('chooseChest'), + onTap: () { + Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return const ChooseChest(); + }), + ); + }, + child: SizedBox( + width: 400, + height: 70, + child: Center( + child: Text('Changer de coffre', + style: TextStyle( + fontSize: 22, + color: orangeC, + fontWeight: FontWeight.w600))), + )), ]), ), - GestureDetector( - onTap: () { - Navigator.popUntil( - context, - ModalRoute.withName('/'), - ); - }, - child: Icon(Icons.home)) ]), )); } - Widget pinForm(context, _pinLenght, int _walletNbr, int _derivation) { + Widget pinForm(context, _pinLenght) { // var _walletPin = ''; // ignore: close_sinks StreamController errorController = @@ -82,11 +127,14 @@ class UnlockingWallet extends StatelessWidget { Provider.of(context); HistoryProvider _historyProvider = Provider.of(context); + FocusNode pinFocus = FocusNode(); + return Form( key: formKey, child: Padding( - padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 30), + padding: EdgeInsets.symmetric(vertical: 5 * ratio, horizontal: 30), child: PinCodeTextField( + focusNode: pinFocus, autoFocus: true, appContext: context, pastedTextStyle: TextStyle( @@ -109,19 +157,19 @@ class UnlockingWallet extends StatelessWidget { borderWidth: 4, shape: PinCodeFieldShape.box, borderRadius: BorderRadius.circular(5), - fieldHeight: 60, + fieldHeight: 50 * ratio, fieldWidth: 50, - activeFillColor: hasError ? Colors.blueAccent : Colors.black, + activeFillColor: Colors.black, ), cursorColor: Colors.black, - animationDuration: Duration(milliseconds: 300), - textStyle: TextStyle(fontSize: 20, height: 1.6), - backgroundColor: Color(0xffF9F9F1), + animationDuration: const Duration(milliseconds: 300), + textStyle: const TextStyle(fontSize: 20, height: 1.6), + backgroundColor: const Color(0xffF9F9F1), enableActiveFill: false, errorAnimationController: errorController, controller: _enterPin, keyboardType: TextInputType.text, - boxShadows: [ + boxShadows: const [ BoxShadow( offset: Offset(0, 1), color: Colors.black12, @@ -131,24 +179,23 @@ class UnlockingWallet extends StatelessWidget { onCompleted: (_pin) async { log.d("Completed"); _myWalletProvider.pinCode = _pin; - final resultWallet = await _walletOptions.readLocalWallet( - context, this.wallet, _pin.toUpperCase(), _pinLenght); + final String resultWallet = await _walletOptions.readLocalWallet( + context, wallet, _pin.toUpperCase(), _pinLenght); // _myWalletProvider.pinCode = _pin.toUpperCase(); _myWalletProvider.pinLenght = _pinLenght; if (resultWallet == 'bad') { errorController.add(ErrorAnimationType .shake); // Triggering error shake animation - hasError = true; pinColor = Colors.red[600]; _walletOptions.reloadBuild(); + pinFocus.requestFocus(); } else { pinColor = Colors.green[400]; // await Future.delayed(Duration(milliseconds: 50)); if (action == "mywallets") { Navigator.pushNamed(formKey.currentContext, '/mywallets'); } else if (action == "pay") { - print("Go payments"); resultPay = await _historyProvider.pay(context, _pin.toUpperCase()); await _paymentsResult(context); @@ -156,8 +203,8 @@ class UnlockingWallet extends StatelessWidget { } }, onChanged: (value) { - if (pinColor != Color(0xFFA4B600)) { - pinColor = Color(0xFFA4B600); + if (pinColor != const Color(0xFFA4B600)) { + pinColor = const Color(0xFFA4B600); } }, )), @@ -173,10 +220,10 @@ class UnlockingWallet extends StatelessWidget { title: Text(resultPay == "Success" ? 'Paiement effecuté avec succès !' : "Une erreur s'est produite lors du paiement"), - content: SingleChildScrollView(child: Text('')), + content: const SingleChildScrollView(child: Text('')), actions: [ TextButton( - child: Text("OK"), + child: const Text("OK"), onPressed: () { Navigator.popUntil( context, diff --git a/lib/screens/myWallets/walletOptions.dart b/lib/screens/myWallets/wallet_options.dart similarity index 78% rename from lib/screens/myWallets/walletOptions.dart rename to lib/screens/myWallets/wallet_options.dart index fdc633a..1e0ca91 100644 --- a/lib/screens/myWallets/walletOptions.dart +++ b/lib/screens/myWallets/wallet_options.dart @@ -1,12 +1,13 @@ +import 'dart:io'; import 'dart:ui'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; import 'package:gecko/models/history.dart'; -import 'package:gecko/models/myWallets.dart'; +import 'package:gecko/models/my_wallets.dart'; import 'package:gecko/models/queries.dart'; -import 'package:gecko/models/walletData.dart'; -import 'package:gecko/models/walletOptions.dart'; +import 'package:gecko/models/wallet_data.dart'; +import 'package:gecko/models/wallet_options.dart'; import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:provider/provider.dart'; import 'package:flutter/services.dart'; @@ -42,15 +43,14 @@ class WalletOptions extends StatelessWidget { _walletOptions.nameController.text.length >= 15 ? _nbrLinesName = 2 : _nbrLinesName = 1; - if (_walletOptions.nameController.text.length >= 26 && isTall) + if (_walletOptions.nameController.text.length >= 26 && isTall) { _nbrLinesName = 3; + } - _walletOptions.walletID = [0, wallet.number]; + WalletData defaultWallet = + _myWalletProvider.getDefaultWallet(_currentChest); - _myWalletProvider.getDefaultWallet(); - - _walletOptions.isDefaultWallet = - (defaultWallet.id()[1] == _walletOptions.walletID[1]); + _walletOptions.isDefaultWallet = (defaultWallet.number == wallet.id()[1]); int currentChest = _myWalletProvider.getCurrentChest(); @@ -69,8 +69,9 @@ class WalletOptions extends StatelessWidget { child: Scaffold( resizeToAvoidBottomInset: false, appBar: AppBar( + toolbarHeight: 60 * ratio, leading: IconButton( - icon: Icon(Icons.arrow_back, color: Colors.black), + icon: const Icon(Icons.arrow_back, color: Colors.black), onPressed: () { _walletOptions.isEditing = false; _walletOptions.isBalanceBlur = true; @@ -97,27 +98,43 @@ class WalletOptions extends StatelessWidget { end: Alignment.bottomCenter, colors: [ yellowC, - Color(0xfffafafa), + const Color(0xfffafafa), ], )), child: Row(children: [ - SizedBox(width: 25), + const SizedBox(width: 25), InkWell( onTap: () async { - await _walletOptions.changeAvatar(); + File newAvatar = + await _walletOptions.changeAvatar(); + if (newAvatar != null) { + wallet.imageFile = newAvatar; + } + _walletOptions.reloadBuild(); }, - child: Image.asset( - 'assets/chopp-gecko2.png', - )), + child: wallet.imageFile == null + ? Image.asset( + 'assets/avatars/${wallet.imageName}', + width: 110, + ) + : Image.file( + wallet.imageFile, + width: 110, + )), InkWell( onTap: () async { - await _walletOptions.changeAvatar(); + File newAvatar = + await _walletOptions.changeAvatar(); + if (newAvatar != null) { + wallet.imageFile = newAvatar; + } + _walletOptions.reloadBuild(); }, child: Column(children: [ Image.asset( 'assets/walletOptions/camera.png', ), - SizedBox(height: 100) + const SizedBox(height: 100) ])), Column(children: [ Row(children: [ @@ -125,13 +142,14 @@ class WalletOptions extends StatelessWidget { SizedBox( width: 260, child: TextField( - key: Key('walletName'), + key: const Key('walletName'), + autofocus: false, focusNode: _walletOptions.walletNameFocus, enabled: _walletOptions.isEditing, controller: _walletOptions.nameController, maxLines: _nbrLinesName, textAlign: TextAlign.center, - decoration: InputDecoration( + decoration: const InputDecoration( border: InputBorder.none, focusedBorder: InputBorder.none, enabledBorder: InputBorder.none, @@ -160,7 +178,7 @@ class WalletOptions extends StatelessWidget { } if (result.isLoading) { - return Text('Loading'); + return const Text('Loading'); } // List repositories = result.data['viewer']['repositories']['nodes']; @@ -187,7 +205,7 @@ class WalletOptions extends StatelessWidget { sigmaY: _walletOptions.isBalanceBlur ? 5 : 0), - child: Text('$wBalanceUD', + child: Text(wBalanceUD, style: TextStyle( fontSize: isTall ? 20 : 18, color: Colors.black)), @@ -205,9 +223,9 @@ class WalletOptions extends StatelessWidget { // ); }, ), - SizedBox(height: 5), + const SizedBox(height: 5), InkWell( - key: Key('displayBalance'), + key: const Key('displayBalance'), onTap: () { _walletOptions.bluringBalance(); }, @@ -217,41 +235,17 @@ class WalletOptions extends StatelessWidget { : 'assets/walletOptions/icon_oeuil_close.png', )), ]), - SizedBox(width: 0), + const SizedBox(width: 0), Column(children: [ InkWell( - key: Key('renameWallet'), + key: const Key('renameWallet'), onTap: () async { - // _walletOptions.isEditing = true; - // _walletOptions.reloadBuild(); - // _walletOptions.walletNameFocus - // .requestFocus(); - _isNewNameValid = await _walletOptions - .editWalletName(_walletOptions.walletID); - // .then((_) { - // _walletOptions.walletNameFocus - // .requestFocus(); - // _walletOptions.reloadBuild(); - // }); - - // .then( - // (_result) { - // if (_result == true) { - // WidgetsBinding.instance - // .addPostFrameCallback((_) { - // _myWalletProvider.listWallets = - // _myWalletProvider - // .readAllWallets( - // _currentChest); - // _myWalletProvider.rebuildWidget(); - // }); - // Navigator.popUntil( - // context, - // ModalRoute.withName('/mywallets'), - // ); - // } - // }, - // ); + _isNewNameValid = + _walletOptions.editWalletName(wallet.id(), + isCesium: false); + await Future.delayed( + const Duration(milliseconds: 30)); + _walletOptions.walletNameFocus.requestFocus(); }, child: ClipRRect( child: Image.asset( @@ -261,10 +255,7 @@ class WalletOptions extends StatelessWidget { width: 20, height: 20), )), - // Image.asset( - // 'assets/walletOptions/edit.png', - // ), - SizedBox( + const SizedBox( height: 60, ) ]) @@ -279,11 +270,11 @@ class WalletOptions extends StatelessWidget { return snapshot.data != null ? Image.memory(snapshot.data, height: isTall ? 300 : 270) - : Text('-', style: TextStyle(fontSize: 20)); + : const Text('-', style: TextStyle(fontSize: 20)); }), SizedBox(height: 15 * ratio), GestureDetector( - key: Key('copyPubkey'), + key: const Key('copyPubkey'), onTap: () { Clipboard.setData( ClipboardData(text: _walletOptions.pubkey.text)); @@ -292,30 +283,29 @@ class WalletOptions extends StatelessWidget { child: SizedBox( height: 50, child: Row(children: [ - SizedBox(width: 30), + const SizedBox(width: 30), Image.asset( 'assets/walletOptions/key.png', ), - SizedBox(width: 10), + const SizedBox(width: 20), Text("${shortPubkey.split(':')[0]}:", - style: TextStyle( + style: const TextStyle( fontSize: 22, fontWeight: FontWeight.w800, fontFamily: 'Monospace', color: Colors.black)), Text(shortPubkey.split(':')[1], - style: TextStyle( + style: const TextStyle( fontSize: 22, fontWeight: FontWeight.w800, fontFamily: 'Monospace')), - SizedBox(width: 15), + const SizedBox(width: 15), SizedBox( height: 40, child: ElevatedButton( style: ElevatedButton.styleFrom( shape: RoundedRectangleBorder( - borderRadius: - new BorderRadius.circular(8), + borderRadius: BorderRadius.circular(8), ), elevation: 1, primary: orangeC, // background @@ -330,7 +320,7 @@ class WalletOptions extends StatelessWidget { Image.asset( 'assets/walletOptions/copy-white.png', ), - SizedBox(width: 7), + const SizedBox(width: 7), Text('Copier', style: TextStyle( fontSize: 15, @@ -339,7 +329,7 @@ class WalletOptions extends StatelessWidget { ]))), SizedBox(height: 10 * ratio), InkWell( - key: Key('displayHistory'), + key: const Key('displayHistory'), onTap: () { _historyProvider.isPubkey(ctx, _walletOptions.pubkey.text, goHistory: true); @@ -347,22 +337,23 @@ class WalletOptions extends StatelessWidget { child: SizedBox( height: 50, child: Row(children: [ - SizedBox(width: 30), + const SizedBox(width: 30), Image.asset( 'assets/walletOptions/clock.png', ), - SizedBox(width: 12), - Text('Historique des transactions', + const SizedBox(width: 22), + const Text('Historique des transactions', style: TextStyle(fontSize: 20, color: Colors.black)), ]))), SizedBox(height: 12 * ratio), InkWell( - key: Key('setDefaultWallet'), + key: const Key('setDefaultWallet'), onTap: !_walletOptions.isDefaultWallet ? () { defaultWallet = wallet; - configBox.put('defaultWallet', wallet.id()); + chestBox.get(currentChest).defaultWallet = + wallet.number; _myWalletProvider.readAllWallets(_currentChest); _myWalletProvider.rebuildWidget(); } @@ -370,14 +361,14 @@ class WalletOptions extends StatelessWidget { child: SizedBox( height: 50, child: Row(children: [ - SizedBox(width: 31), + const SizedBox(width: 31), CircleAvatar( backgroundColor: Colors.grey[ _walletOptions.isDefaultWallet ? 300 : 500], child: Image.asset( 'assets/walletOptions/android-checkmark.png', )), - SizedBox(width: 12), + const SizedBox(width: 22), Text( _walletOptions.isDefaultWallet ? 'Ce portefeuille est celui par defaut' @@ -391,7 +382,7 @@ class WalletOptions extends StatelessWidget { SizedBox(height: 17 * ratio), if (!_walletOptions.isDefaultWallet) InkWell( - key: Key('deleteWallet'), + key: const Key('deleteWallet'), onTap: !_walletOptions.isDefaultWallet ? () async { await _walletOptions.deleteWallet( @@ -405,12 +396,12 @@ class WalletOptions extends StatelessWidget { } : null, child: Row(children: [ - SizedBox(width: 33), + const SizedBox(width: 33), Image.asset( 'assets/walletOptions/trash.png', ), - SizedBox(width: 14), - Text('Supprimer ce portefeuille', + const SizedBox(width: 24), + const Text('Supprimer ce portefeuille', style: TextStyle( fontSize: 20, color: Color(0xffD80000))), ])), diff --git a/lib/screens/myWallets/walletsHome.dart b/lib/screens/myWallets/walletsHome.dart deleted file mode 100644 index 0f0b441..0000000 --- a/lib/screens/myWallets/walletsHome.dart +++ /dev/null @@ -1,252 +0,0 @@ -import 'package:flutter/services.dart'; -import 'package:gecko/globals.dart'; -import 'package:gecko/models/myWallets.dart'; -import 'package:gecko/models/walletData.dart'; -import 'package:gecko/models/walletOptions.dart'; -import 'package:flutter/material.dart'; -import 'package:gecko/screens/commonElements.dart'; -import 'package:gecko/screens/myWallets/walletOptions.dart'; -import 'package:gecko/screens/onBoarding/0_noKeychainFound.dart'; -import 'package:provider/provider.dart'; - -// ignore: must_be_immutable -class WalletsHome extends StatelessWidget { - final _derivationKey = GlobalKey(); - int firstWalletDerivation; - - @override - Widget build(BuildContext context) { - SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); - MyWalletsProvider myWalletProvider = - Provider.of(context); - - final int _currentChest = myWalletProvider.getCurrentChest(); - - myWalletProvider.listWallets = - myWalletProvider.readAllWallets(_currentChest); - final bool isWalletsExists = myWalletProvider.checkIfWalletExist(); - - if (myWalletProvider.listWallets.isEmpty) { - firstWalletDerivation = myWalletProvider.listWallets[0].derivation; - - myWalletProvider.getDefaultWallet(); - } - - log.d("${myWalletProvider.pinCode},${myWalletProvider.pinLenght}"); - - return WillPopScope( - onWillPop: () { - Navigator.popUntil( - context, - ModalRoute.withName('/'), - ); - return Future.value(true); - }, - child: Scaffold( - appBar: AppBar( - leading: IconButton( - icon: Icon(Icons.arrow_back, color: Colors.black), - onPressed: () { - Navigator.popUntil( - context, - ModalRoute.withName('/'), - ); - }), - title: Text('Mes portefeuilles', - key: Key('myWallets'), - style: TextStyle(color: Colors.grey[850])), - backgroundColor: Color(0xffFFD58D), - ), - floatingActionButton: Visibility( - visible: (isWalletsExists && firstWalletDerivation != -1), - child: Container( - height: 80.0, - width: 80.0, - child: FittedBox( - child: FloatingActionButton( - key: Key('addDerivation'), - heroTag: "buttonGenerateWallet", - onPressed: () { - showDialog( - context: context, - builder: (BuildContext context) { - return addNewDerivation(context, 1); - }); - }, - child: Container( - height: 40, - width: 40, - child: Icon(Icons.person_add_alt_1_rounded, - color: Colors.grey[850])), - backgroundColor: floattingYellow)))), - body: SafeArea( - child: !isWalletsExists - ? NoKeyChainScreen() - : myWalletsTiles(context)))); - } - - Widget myWalletsTiles(BuildContext context) { - MyWalletsProvider _myWalletProvider = - Provider.of(context); - WalletOptionsProvider _walletOptions = - Provider.of(context); - - final bool isWalletsExists = _myWalletProvider.checkIfWalletExist(); - - if (!isWalletsExists) { - return Text(''); - } - - if (_myWalletProvider.listWallets.isEmpty) { - return Expanded( - child: Column(children: [ - Center( - child: Text( - 'Veuillez générer votre premier portefeuille', - style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500), - )), - ])); - } - - List _listWallets = _myWalletProvider.listWallets; - - return GridView.count( - key: Key('listWallets'), - crossAxisCount: 2, - childAspectRatio: 1, - crossAxisSpacing: 0, - mainAxisSpacing: 0, - children: [ - for (WalletData _repository in _listWallets) - Padding( - padding: EdgeInsets.all(16), - child: GestureDetector( - onTap: () async { - await _walletOptions.readLocalWallet( - context, - _repository, - _myWalletProvider.pinCode, - _myWalletProvider.pinLenght); - Navigator.push( - context, - SmoothTransition( - page: WalletOptions( - wallet: _repository, - ))); - - // Navigator.push(context, - // MaterialPageRoute(builder: (context) { - // return UnlockingWallet(wallet: _repository); - // })); - }, - child: ClipRRect( - borderRadius: BorderRadius.all(Radius.circular(12)), - child: Column(children: [ - Expanded( - child: Container( - width: double.infinity, - height: double.infinity, - decoration: BoxDecoration( - gradient: RadialGradient( - radius: 1, - colors: [ - Colors.green[100], - Colors.green[500], - ], - )), - child: - // SvgPicture.asset('assets/chopp-gecko2.png', - // semanticsLabel: 'Gecko', height: 48), - Image.asset( - 'assets/chopp-gecko2.png', - ), - )), - ListTile( - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.vertical( - bottom: Radius.circular(12))), - // contentPadding: const EdgeInsets.only(left: 7.0), - tileColor: - _repository.id()[1] == defaultWallet.id()[1] - ? orangeC - : Color(0xffFFD58D), - // leading: Text('IMAGE'), - - // subtitle: Text(_repository.split(':')[3], - // style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')), - title: Center( - child: Padding( - padding: - EdgeInsets.symmetric(horizontal: 5), - child: Text(_repository.name, - textAlign: TextAlign.center, - style: TextStyle( - fontSize: 16.0, - color: _repository.id()[1] == - defaultWallet.id()[1] - ? Color(0xffF9F9F1) - : Colors.black)))), - // dense: true, - onTap: () { - Navigator.push( - context, - SmoothTransition( - page: WalletOptions( - wallet: _repository, - ))); - }, - ) - ])))) - ]); - } - - Widget addNewDerivation(context, int _walletNbr) { - final TextEditingController _newDerivationName = TextEditingController(); - MyWalletsProvider _myWalletProvider = - Provider.of(context); - - return AlertDialog( - content: Stack( - clipBehavior: Clip.hardEdge, - children: [ - Form( - key: _derivationKey, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Text('Nom du portefeuille:'), - Padding( - padding: EdgeInsets.all(8.0), - child: TextFormField( - key: Key('DerivationNameKey'), - controller: _newDerivationName, - textAlign: TextAlign.center, - autofocus: true, - ), - ), - SizedBox(height: 20), - Padding( - padding: const EdgeInsets.all(8.0), - child: ElevatedButton( - key: Key('validDerivation'), - style: ElevatedButton.styleFrom( - elevation: 1, - primary: yellowC, // background - onPrimary: Colors.black, // foreground - ), - onPressed: () async { - await _myWalletProvider - .generateNewDerivation( - context, _newDerivationName.text) - .then((_) => _newDerivationName.text == ''); - }, - child: Text("Créer")), - ) - ], - ), - ), - ], - ), - ); - } -} diff --git a/lib/screens/myWallets/wallets_home.dart b/lib/screens/myWallets/wallets_home.dart new file mode 100644 index 0000000..c323c1e --- /dev/null +++ b/lib/screens/myWallets/wallets_home.dart @@ -0,0 +1,479 @@ +import 'package:flutter/services.dart'; +import 'package:gecko/globals.dart'; +import 'package:gecko/models/chest_data.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/models/queries.dart'; +import 'package:gecko/models/wallet_data.dart'; +import 'package:gecko/models/wallet_options.dart'; +import 'package:flutter/material.dart'; +import 'package:gecko/screens/common_elements.dart'; +import 'package:gecko/screens/myWallets/cesium_wallet_options.dart'; +import 'package:gecko/screens/myWallets/chest_options.dart'; +import 'package:gecko/screens/myWallets/choose_chest.dart'; +import 'package:gecko/screens/myWallets/wallet_options.dart'; +import 'package:gecko/screens/onBoarding/0_no_keychain_found.dart'; +import 'package:graphql_flutter/graphql_flutter.dart'; +import 'package:provider/provider.dart'; + +class WalletsHome extends StatelessWidget { + final _derivationKey = GlobalKey(); + + WalletsHome({Key key}) : super(key: key); + + @override + Widget build(BuildContext context) { + SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); + MyWalletsProvider myWalletProvider = + Provider.of(context); + + final int _currentChestNumber = myWalletProvider.getCurrentChest(); + final ChestData _currentChest = chestBox.get(_currentChestNumber); + bool isWalletsExists; + + if (!_currentChest.isCesium) { + myWalletProvider.listWallets = + myWalletProvider.readAllWallets(_currentChestNumber); + } + isWalletsExists = myWalletProvider.checkIfWalletExist(); + + return WillPopScope( + onWillPop: () { + Navigator.popUntil( + context, + ModalRoute.withName('/'), + ); + return Future.value(true); + }, + child: Scaffold( + appBar: AppBar( + toolbarHeight: 60 * ratio, + leading: IconButton( + icon: const Icon(Icons.arrow_back, color: Colors.black), + onPressed: () { + Navigator.popUntil( + context, + ModalRoute.withName('/'), + ); + }), + title: Text(_currentChest.name, + key: const Key('myWallets'), + style: TextStyle(color: Colors.grey[850])), + backgroundColor: const Color(0xffFFD58D), + ), + body: SafeArea( + child: !isWalletsExists + ? const NoKeyChainScreen() + : _currentChest.isCesium + ? cesiumWalletOptions( + context, _currentChest, myWalletProvider) + : myWalletsTiles(context), + ), + ), + ); + } + + // Widget cesiumWalletOptions(BuildContext context) { + // return Column(children: const [ + // Center(child: Text('This is a Cesium wallet')), + // ]); + // } + + Widget chestOptions( + BuildContext context, MyWalletsProvider _myWalletProvider) { + return Column(children: [ + const SizedBox(height: 50), + SizedBox( + height: 120, + width: 445, + child: ElevatedButton.icon( + icon: Image.asset( + 'assets/chests/config.png', + ), + style: ElevatedButton.styleFrom( + elevation: 2, + primary: floattingYellow, // background + onPrimary: Colors.black, // foreground + ), + onPressed: () => Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return ChestOptions(walletProvider: _myWalletProvider); + }), + ), + label: const Text( + " Paramétrer ce coffre", + style: TextStyle( + fontSize: 25, + fontWeight: FontWeight.w700, + color: Color(0xff8a3c0f), + ), + ), + )), + const SizedBox(height: 30), + SizedBox( + height: 120, + width: 445, + child: ElevatedButton.icon( + icon: Image.asset('assets/chests/miniChests.png'), + style: ElevatedButton.styleFrom( + elevation: 2, + primary: floattingYellow, // background + onPrimary: Colors.black, // foreground + ), + onPressed: () => Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return const ChooseChest(); + }), + ), + label: const Text( + " Changer de coffre", + style: TextStyle( + fontSize: 25, + fontWeight: FontWeight.w700, + color: Color(0xff8a3c0f), + ), + ), + )), + const SizedBox(height: 30) + ]); + } + + Widget myWalletsTiles(BuildContext context) { + MyWalletsProvider _myWalletProvider = + Provider.of(context); + WalletOptionsProvider _walletOptions = + Provider.of(context); + + final bool isWalletsExists = _myWalletProvider.checkIfWalletExist(); + + if (!isWalletsExists) { + return const Text(''); + } + + if (_myWalletProvider.listWallets.isEmpty) { + return Expanded( + child: Column(children: const [ + Center( + child: Text( + 'Veuillez générer votre premier portefeuille', + style: TextStyle(fontSize: 17, fontWeight: FontWeight.w500), + )), + ])); + } + + List _listWallets = _myWalletProvider.listWallets; + WalletData defaultWallet = + _myWalletProvider.getDefaultWallet(configBox.get('currentChest')); + + return CustomScrollView(slivers: [ + const SliverToBoxAdapter(child: SizedBox(height: 20)), + SliverGrid.count( + key: const Key('listWallets'), + crossAxisCount: 2, + childAspectRatio: 1, + crossAxisSpacing: 0, + mainAxisSpacing: 0, + children: [ + for (WalletData _repository in _listWallets) + Padding( + padding: const EdgeInsets.all(16), + child: GestureDetector( + onTap: () async { + await _walletOptions.readLocalWallet( + context, + _repository, + _myWalletProvider.pinCode, + _myWalletProvider.pinLenght); + Navigator.push( + context, + SmoothTransition( + page: WalletOptions( + wallet: _repository, + ))); + + // Navigator.push(context, + // MaterialPageRoute(builder: (context) { + // return UnlockingWallet(wallet: _repository); + // })); + }, + child: ClipOvalShadow( + shadow: const Shadow( + color: Colors.transparent, + offset: Offset(0, 0), + blurRadius: 5, + ), + clipper: CustomClipperOval(), + child: ClipRRect( + borderRadius: + const BorderRadius.all(Radius.circular(12)), + child: Column(children: [ + Expanded( + child: Container( + width: double.infinity, + height: double.infinity, + decoration: BoxDecoration( + gradient: RadialGradient( + radius: 0.6, + colors: [ + Colors.green[400], + const Color(0xFFE7E7A6), + ], + )), + child: + // SvgPicture.asset('assets/chopp-gecko2.png', + // semanticsLabel: 'Gecko', height: 48), + _repository.imageFile == null + ? Image.asset( + 'assets/avatars/${_repository.imageName}', + alignment: Alignment.bottomCenter, + scale: 0.5, + ) + : Image.file( + _repository.imageFile, + alignment: Alignment.bottomCenter, + scale: 0.5, + ), + )), + // balanceBuilder(context, _walletOptions.pubkey.text), + ListTile( + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical( + bottom: Radius.circular(12))), + // contentPadding: const EdgeInsets.only(left: 7.0), + tileColor: + _repository.id()[1] == defaultWallet.id()[1] + ? orangeC + : const Color(0xffFFD58D), + // leading: Text('IMAGE'), + + // subtitle: Text(_repository.split(':')[3], + // style: TextStyle(fontSize: 12.0, fontFamily: 'Monospace')), + title: Center( + child: Padding( + padding: + const EdgeInsets.symmetric(horizontal: 5), + child: Text( + _repository.name, + textAlign: TextAlign.center, + style: TextStyle( + fontSize: 17.0, + color: _repository.id()[1] == + defaultWallet.id()[1] + ? const Color(0xffF9F9F1) + : Colors.black, + fontStyle: FontStyle.italic), + ), + ), + ), + // dense: true, + onTap: () { + Navigator.push( + context, + SmoothTransition( + page: WalletOptions( + wallet: _repository, + ), + ), + ); + }, + ) + ]), + ), + ), + )), + addNewDerivation(context), + // SizedBox(height: 1), + // Padding( + // padding: EdgeInsets.symmetric(horizontal: 35), + // child: Text( + // 'Ajouter un portefeuille', + // textAlign: TextAlign.center, + // style: TextStyle(fontSize: 18), + // )) + ]), + // SliverToBoxAdapter(child: Spacer()), + SliverToBoxAdapter(child: chestOptions(context, _myWalletProvider)), + ]); + } + + Widget balanceBuilder(context, String _pubkey) { + return Query( + options: QueryOptions( + document: gql(getBalance), + variables: { + 'pubkey': _pubkey, + }, + // pollInterval: Duration(seconds: 1), + ), + builder: (QueryResult result, + {VoidCallback refetch, FetchMore fetchMore}) { + if (result.hasException) { + return Text(result.exception.toString()); + } + + if (result.isLoading) { + return const Text('Loading'); + } + String wBalanceUD; + if (result.data['balance'] == null) { + wBalanceUD = '0.0'; + } else { + int wBalanceG1 = result.data['balance']['amount']; + int currentUD = result.data['currentUd']['amount']; + double wBalanceUDBrut = wBalanceG1 / currentUD; // .toString(); + wBalanceUD = + double.parse((wBalanceUDBrut).toStringAsFixed(2)).toString(); + } + return Text(wBalanceUD); + }); + } + + Widget addNewDerivation(context) { + MyWalletsProvider _myWalletProvider = + Provider.of(context); + + String _newDerivationName = + 'Portefeuille ${_myWalletProvider.listWallets.last.number + 2}'; + return Padding( + padding: const EdgeInsets.all(16), + child: ClipRRect( + borderRadius: const BorderRadius.all(Radius.circular(12)), + child: Column(children: [ + Expanded( + child: InkWell( + key: const Key('addDerivation'), + onTap: () async { + await _myWalletProvider.generateNewDerivation( + context, _newDerivationName); + }, + child: Container( + width: double.infinity, + height: double.infinity, + decoration: BoxDecoration(color: floattingYellow), + child: const Center( + child: Text( + '+', + style: TextStyle( + fontSize: 150, + fontWeight: FontWeight.w700, + color: Color(0xFFFCB437)), + )), + )), + ), + ]))); + } + + Widget addNewDerivationPopup(context) { + final TextEditingController _newDerivationName = TextEditingController(); + MyWalletsProvider _myWalletProvider = + Provider.of(context); + + return AlertDialog( + content: Stack( + clipBehavior: Clip.hardEdge, + children: [ + Form( + key: _derivationKey, + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + const Text('Nom du portefeuille:'), + Padding( + padding: const EdgeInsets.all(8.0), + child: TextFormField( + key: const Key('DerivationNameKey'), + controller: _newDerivationName, + textAlign: TextAlign.center, + autofocus: true, + ), + ), + const SizedBox(height: 20), + Padding( + padding: const EdgeInsets.all(8.0), + child: ElevatedButton( + key: const Key('validDerivation'), + style: ElevatedButton.styleFrom( + elevation: 1, + primary: yellowC, // background + onPrimary: Colors.black, // foreground + ), + onPressed: () async { + await _myWalletProvider + .generateNewDerivation( + context, _newDerivationName.text) + .then((_) => _newDerivationName.text == ''); + }, + child: const Text("Créer")), + ) + ], + ), + ), + ], + ), + ); + } +} + +// extension Range on num { +// bool isBetween(num from, num to) { +// return from < this && this < to; +// } +// } + +class CustomClipperOval extends CustomClipper { + @override + Rect getClip(Size size) { + return Rect.fromCircle( + center: Offset(size.width / 2, size.width / 2), + radius: size.width / 2 + 3); + } + + @override + bool shouldReclip(CustomClipper oldClipper) { + return false; + } +} + +class ClipOvalShadow extends StatelessWidget { + final Shadow shadow; + final CustomClipper clipper; + final Widget child; + + const ClipOvalShadow({ + Key key, + @required this.shadow, + @required this.clipper, + @required this.child, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return CustomPaint( + painter: _ClipOvalShadowPainter( + clipper: clipper, + shadow: shadow, + ), + child: ClipRect(child: child, clipper: clipper), + ); + } +} + +class _ClipOvalShadowPainter extends CustomPainter { + final Shadow shadow; + final CustomClipper clipper; + + _ClipOvalShadowPainter({@required this.shadow, @required this.clipper}); + + @override + void paint(Canvas canvas, Size size) { + var paint = shadow.toPaint(); + var clipRect = clipper.getClip(size).shift(const Offset(0, 0)); + canvas.drawOval(clipRect, paint); + } + + @override + bool shouldRepaint(CustomPainter oldDelegate) { + return true; + } +} diff --git a/lib/screens/onBoarding/0_noKeychainFound.dart b/lib/screens/onBoarding/0_no_keychain_found.dart similarity index 79% rename from lib/screens/onBoarding/0_noKeychainFound.dart rename to lib/screens/onBoarding/0_no_keychain_found.dart index c69d4d6..31745a7 100644 --- a/lib/screens/onBoarding/0_noKeychainFound.dart +++ b/lib/screens/onBoarding/0_no_keychain_found.dart @@ -1,16 +1,14 @@ +// ignore_for_file: file_names import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/screens/commonElements.dart'; -import 'package:gecko/screens/myWallets/importWallet.dart'; +import 'package:gecko/screens/common_elements.dart'; +import 'package:gecko/screens/myWallets/import_wallet.dart'; import 'package:gecko/screens/onBoarding/1.dart'; -// import 'package:gecko/models/home.dart'; -// import 'package:provider/provider.dart'; -// ignore: must_be_immutable class NoKeyChainScreen extends StatelessWidget { - TextEditingController tplController = TextEditingController(); + const NoKeyChainScreen({Key key}) : super(key: key); @override Widget build(BuildContext context) { @@ -25,16 +23,16 @@ class NoKeyChainScreen extends StatelessWidget { common.onboardingProgressBar(context, 'Mes portefeuilles', 0), common.bubbleSpeak( "Je ne connais pour l’instant aucun de vos portefeuilles.\n\nVous pouvez en créer un nouveau, ou bien importer un portefeuille Cesium existant.", - textKey: Key('textOnboarding')), - SizedBox(height: 90), + textKey: const Key('textOnboarding')), + const SizedBox(height: 90), Container( child: ClipOval( child: Material( - color: Color(0xffFFD58D), // button color + color: const Color(0xffFFD58D), // button color child: InkWell( - key: Key('goStep1'), + key: const Key('goStep1'), splashColor: orangeC, // inkwell color - child: Padding( + child: const Padding( padding: EdgeInsets.all(8), child: Image( image: AssetImage('assets/onBoarding/wallet.png'), @@ -47,7 +45,7 @@ class NoKeyChainScreen extends StatelessWidget { }), ), ), - decoration: BoxDecoration( + decoration: const BoxDecoration( shape: BoxShape.circle, color: Colors.white, boxShadow: [ @@ -59,8 +57,8 @@ class NoKeyChainScreen extends StatelessWidget { ], ), ), - SizedBox(height: 15), - Text( + const SizedBox(height: 15), + const Text( "Créer un nouveau\nportefeuille", textAlign: TextAlign.center, style: TextStyle( @@ -68,15 +66,15 @@ class NoKeyChainScreen extends StatelessWidget { fontSize: 16, fontWeight: FontWeight.w500), ), - SizedBox(height: 70), + const SizedBox(height: 70), Container( child: ClipOval( child: Material( - color: Color(0xffFFD58D), // button color + color: const Color(0xffFFD58D), // button color child: InkWell( splashColor: orangeC, // inkwell color child: Padding( - padding: EdgeInsets.all(12), + padding: const EdgeInsets.all(12), child: // Image( // image: AssetImage('assets/cesium_bw3.png'), @@ -86,11 +84,11 @@ class NoKeyChainScreen extends StatelessWidget { ), onTap: () { Navigator.push(context, - SlideLeftRoute(page: ImportWalletScreen())); + SlideLeftRoute(page: const ImportWalletScreen())); }), ), ), - decoration: BoxDecoration( + decoration: const BoxDecoration( shape: BoxShape.circle, color: Colors.white, boxShadow: [ @@ -102,8 +100,8 @@ class NoKeyChainScreen extends StatelessWidget { ], ), ), - SizedBox(height: 10), - Text( + const SizedBox(height: 10), + const Text( "Importer un\nportefeuille Cesium", textAlign: TextAlign.center, style: TextStyle(color: Colors.black, fontSize: 13), diff --git a/lib/screens/onBoarding/1.dart b/lib/screens/onBoarding/1.dart index d58c8a3..6cbd97c 100644 --- a/lib/screens/onBoarding/1.dart +++ b/lib/screens/onBoarding/1.dart @@ -1,7 +1,9 @@ +// ignore_for_file: file_names + import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/2.dart'; // import 'package:gecko/models/home.dart'; // import 'package:provider/provider.dart'; @@ -11,6 +13,8 @@ class OnboardingStepOne extends StatelessWidget { TextEditingController tplController = TextEditingController(); final int progress = 1; + OnboardingStepOne({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -24,8 +28,8 @@ class OnboardingStepOne extends StatelessWidget { context, 'Nouveau portefeuilles', progress), common.bubbleSpeak( "Il semblerait que vous n’ayez pas encore de trousseau.\n\nUn trousseau vous permet de gérer un ou plusieurs portefeuilles.", - textKey: Key('step1')), - SizedBox(height: 90), + textKey: const Key('step1')), + const SizedBox(height: 90), Image.asset( 'assets/onBoarding/keys-and-wallets-horizontal.png', height: 200, @@ -37,7 +41,7 @@ class OnboardingStepOne extends StatelessWidget { width: 400, height: 62, child: ElevatedButton( - key: Key('goStep2'), + key: const Key('goStep2'), style: ElevatedButton.styleFrom( elevation: 5, primary: orangeC, @@ -49,10 +53,10 @@ class OnboardingStepOne extends StatelessWidget { FaderTransition( page: OnboardingStepTwo(), isFast: true)); }, - child: Text('Créer mon trousseau', + child: const Text('Créer mon trousseau', style: TextStyle(fontSize: 20))), ))), - SizedBox(height: 80), + const SizedBox(height: 80), ]), )); } diff --git a/lib/screens/onBoarding/10.dart b/lib/screens/onBoarding/10.dart index 12c8211..8a92869 100644 --- a/lib/screens/onBoarding/10.dart +++ b/lib/screens/onBoarding/10.dart @@ -1,7 +1,9 @@ +// ignore_for_file: file_names + import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/11.dart'; // ignore: must_be_immutable @@ -9,6 +11,8 @@ class OnboardingStepTwelve extends StatelessWidget { TextEditingController tplController = TextEditingController(); final int progress = 9; + OnboardingStepTwelve({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -22,9 +26,9 @@ class OnboardingStepTwelve extends StatelessWidget { context, 'Ma phrase de restauration', progress), common.bubbleSpeak( "Si un jour vous changez de téléphone, votre code secret sera différent, mais il vous suffira de me redonner votre phrase de restauration pour recréer votre trousseau.", - textKey: Key('step10'), + textKey: const Key('step10'), ), - SizedBox(height: 10), + const SizedBox(height: 10), Image.asset( 'assets/onBoarding/plusieurs-codes-secrets-un-trousseau.png', height: 410 * ratio, @@ -36,7 +40,7 @@ class OnboardingStepTwelve extends StatelessWidget { width: 400, height: 62, child: ElevatedButton( - key: Key('goStep11'), + key: const Key('goStep11'), style: ElevatedButton.styleFrom( elevation: 5, primary: orangeC, @@ -49,7 +53,7 @@ class OnboardingStepTwelve extends StatelessWidget { page: OnboardingStepThirteen(), isFast: true), ); }, - child: Text("Générer le code secret", + child: const Text("Générer le code secret", style: TextStyle(fontSize: 20))), ))), SizedBox(height: isTall ? 80 : 40), diff --git a/lib/screens/onBoarding/11.dart b/lib/screens/onBoarding/11.dart index d0173cc..38cc330 100644 --- a/lib/screens/onBoarding/11.dart +++ b/lib/screens/onBoarding/11.dart @@ -1,10 +1,12 @@ +// ignore_for_file: file_names + import 'dart:ui'; import 'package:dubp/dubp.dart'; import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/models/generateWallets.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/models/generate_wallets.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/12.dart'; import 'package:provider/provider.dart'; @@ -13,6 +15,8 @@ class OnboardingStepThirteen extends StatelessWidget { NewWallet generatedWallet; final int progress = 10; + OnboardingStepThirteen({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -32,51 +36,49 @@ class OnboardingStepThirteen extends StatelessWidget { // initialData: '...', builder: (context, snapshot) { generatedWallet = snapshot.data; - return Visibility(visible: false, child: Text('')); + return const Visibility(visible: false, child: Text('')); }), common.onboardingProgressBar( context, 'Ma phrase de restauration', progress), common.bubbleSpeakRich( [ - TextSpan( + const TextSpan( text: "Et voilà votre code secret !\n\nMémorisez-le ou notez-le, car il vous sera demandé "), - TextSpan( + const TextSpan( text: 'à chaque fois', style: TextStyle(fontWeight: FontWeight.bold)), - TextSpan( + const TextSpan( text: " que vous voudrez effectuer un paiement sur cet appareil."), ], - textKey: Key('step11'), + textKey: const Key('step11'), ), - SizedBox(height: 100), - Container( - child: Stack( - alignment: Alignment.centerRight, - children: [ - TextField( - key: Key('generatedPin'), - enabled: false, - controller: _generateWalletProvider.pin, - maxLines: 1, - textAlign: TextAlign.center, - decoration: InputDecoration(), - style: TextStyle( - letterSpacing: 5, - fontSize: 35.0, - color: Colors.black, - fontWeight: FontWeight.bold)), - IconButton( - icon: Icon(Icons.replay), - color: orangeC, - onPressed: () async { - generatedWallet = await _generateWalletProvider - .changePinCode(reload: false); - }, - ), - ], - ), + const SizedBox(height: 100), + Stack( + alignment: Alignment.centerRight, + children: [ + TextField( + key: const Key('generatedPin'), + enabled: false, + controller: _generateWalletProvider.pin, + maxLines: 1, + textAlign: TextAlign.center, + decoration: const InputDecoration(), + style: const TextStyle( + letterSpacing: 5, + fontSize: 35.0, + color: Colors.black, + fontWeight: FontWeight.bold)), + IconButton( + icon: const Icon(Icons.replay), + color: orangeC, + onPressed: () async { + generatedWallet = await _generateWalletProvider + .changePinCode(reload: false); + }, + ), + ], ), Expanded( child: Align( @@ -85,25 +87,25 @@ class OnboardingStepThirteen extends StatelessWidget { width: 400, height: 62, child: ElevatedButton( - key: Key('changeSecretCode'), + key: const Key('changeSecretCode'), style: ElevatedButton.styleFrom( elevation: 5, - primary: Color(0xffFFD58D), + primary: const Color(0xffFFD58D), onPrimary: Colors.black, // foreground ), onPressed: () async { generatedWallet = await _generateWalletProvider .changePinCode(reload: false); }, - child: Text("Choisir un autre code secret", + child: const Text("Choisir un autre code secret", style: TextStyle(fontSize: 20))), ))), - SizedBox(height: 25), + const SizedBox(height: 25), SizedBox( width: 400, height: 62, child: ElevatedButton( - key: Key('goStep12'), + key: const Key('goStep12'), style: ElevatedButton.styleFrom( elevation: 5, primary: orangeC, @@ -120,10 +122,10 @@ class OnboardingStepThirteen extends StatelessWidget { isFast: true), ); }, - child: Text("J'ai noté mon code secret", + child: const Text("J'ai noté mon code secret", style: TextStyle(fontSize: 20))), ), - SizedBox(height: 80), + const SizedBox(height: 80), ]), )); } diff --git a/lib/screens/onBoarding/12.dart b/lib/screens/onBoarding/12.dart index 732b22a..d715a47 100644 --- a/lib/screens/onBoarding/12.dart +++ b/lib/screens/onBoarding/12.dart @@ -1,13 +1,15 @@ +// ignore_for_file: file_names + import 'dart:async'; import 'dart:ui'; import 'package:dubp/dubp.dart'; import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/models/generateWallets.dart'; -import 'package:gecko/models/myWallets.dart'; -import 'package:gecko/models/walletOptions.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/models/generate_wallets.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/models/wallet_options.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/13_congratulations.dart'; import 'package:pin_code_fields/pin_code_fields.dart'; import 'package:provider/provider.dart'; @@ -22,7 +24,7 @@ class OnboardingStepFourteen extends StatelessWidget { NewWallet generatedWallet; final int progress = 11; final formKey = GlobalKey(); - var pinColor = Color(0xFFA4B600); + var pinColor = const Color(0xFFA4B600); bool hasError = false; @override @@ -43,7 +45,7 @@ class OnboardingStepFourteen extends StatelessWidget { context, 'Ma phrase de restauration', progress), common.bubbleSpeak( "Avez-vous bien mémorisé votre code secret ?\n\nVérifions ça ensemble !\n\nTapez votre code secret dans le champ ci-dessous (après c’est fini, promis-juré-gecko).", - textKey: Key('step12'), + textKey: const Key('step12'), ), SizedBox(height: isTall ? 80 : 10), pinForm(context, _walletOptions, _pinLenght, 1, 3) @@ -70,7 +72,7 @@ class OnboardingStepFourteen extends StatelessWidget { child: Padding( padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 30), child: PinCodeTextField( - key: Key('formKey2'), + key: const Key('formKey2'), autoFocus: true, appContext: context, pastedTextStyle: TextStyle( @@ -98,14 +100,14 @@ class OnboardingStepFourteen extends StatelessWidget { activeFillColor: hasError ? Colors.blueAccent : Colors.black, ), cursorColor: Colors.black, - animationDuration: Duration(milliseconds: 300), - textStyle: TextStyle(fontSize: 20, height: 1.6), - backgroundColor: Color(0xffF9F9F1), + animationDuration: const Duration(milliseconds: 300), + textStyle: const TextStyle(fontSize: 20, height: 1.6), + backgroundColor: const Color(0xffF9F9F1), enableActiveFill: false, errorAnimationController: errorController, controller: _enterPin, keyboardType: TextInputType.text, - boxShadows: [ + boxShadows: const [ BoxShadow( offset: Offset(0, 1), color: Colors.black12, @@ -122,7 +124,6 @@ class OnboardingStepFourteen extends StatelessWidget { _generateWalletProvider.storeHDWChest( generatedWallet, 'Mon portefeuille courant', context); _myWalletProvider.readAllWallets(_currentChest); - _myWalletProvider.getDefaultWallet(); scheduleMicrotask(() { _walletOptions.reloadBuild(); _myWalletProvider.rebuildWidget(); @@ -141,8 +142,8 @@ class OnboardingStepFourteen extends StatelessWidget { } }, onChanged: (value) { - if (pinColor != Color(0xFFA4B600)) { - pinColor = Color(0xFFA4B600); + if (pinColor != const Color(0xFFA4B600)) { + pinColor = const Color(0xFFA4B600); } }, )), diff --git a/lib/screens/onBoarding/13_congratulations.dart b/lib/screens/onBoarding/13_congratulations.dart index 58ad16a..ac73743 100644 --- a/lib/screens/onBoarding/13_congratulations.dart +++ b/lib/screens/onBoarding/13_congratulations.dart @@ -1,13 +1,17 @@ +// ignore_for_file: file_names + import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/screens/common_elements.dart'; // ignore: must_be_immutable class OnboardingStepFiveteen extends StatelessWidget { TextEditingController tplController = TextEditingController(); final int progress = 12; + OnboardingStepFiveteen({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -21,7 +25,7 @@ class OnboardingStepFiveteen extends StatelessWidget { context, 'Ma phrase de restauration', progress), common.bubbleSpeak( "Top !\n\nVotre trousseau de clef et votre portefeuille ont été créés avec un immense succès.\n\nFélicitations !", - textKey: Key('step13'), + textKey: const Key('step13'), ), SizedBox(height: isTall ? 20 : 10), Image.asset( @@ -35,7 +39,7 @@ class OnboardingStepFiveteen extends StatelessWidget { width: 400, height: 62, child: ElevatedButton( - key: Key('goWalletHome'), + key: const Key('goWalletHome'), style: ElevatedButton.styleFrom( elevation: 5, primary: orangeC, @@ -51,10 +55,10 @@ class OnboardingStepFiveteen extends StatelessWidget { '/mywallets', ); }, - child: Text("Accéder à mes portefeuilles", + child: const Text("Accéder à mes portefeuilles", style: TextStyle(fontSize: 20))), ))), - SizedBox(height: 80), + const SizedBox(height: 80), ]), )); } diff --git a/lib/screens/onBoarding/2.dart b/lib/screens/onBoarding/2.dart index 0d7a3f9..19e2cbf 100644 --- a/lib/screens/onBoarding/2.dart +++ b/lib/screens/onBoarding/2.dart @@ -1,7 +1,9 @@ +// ignore_for_file: file_names + import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/3.dart'; // import 'package:gecko/screens/commonElements.dart'; // import 'package:gecko/models/home.dart'; @@ -12,6 +14,8 @@ class OnboardingStepTwo extends StatelessWidget { TextEditingController tplController = TextEditingController(); final int progress = 2; + OnboardingStepTwo({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -25,9 +29,9 @@ class OnboardingStepTwo extends StatelessWidget { context, 'Nouveau portefeuilles', progress), common.bubbleSpeak( "Un trousseau est créé à partir d’une phrase de restauration.", - textKey: Key('step2'), + textKey: const Key('step2'), ), - SizedBox(height: 70), + const SizedBox(height: 70), Image.asset( 'assets/onBoarding/keys-and-wallets-horizontal-plus-phrase.png'), Expanded( @@ -37,7 +41,7 @@ class OnboardingStepTwo extends StatelessWidget { width: 400, height: 62, child: ElevatedButton( - key: Key('goStep3'), + key: const Key('goStep3'), style: ElevatedButton.styleFrom( elevation: 5, primary: orangeC, @@ -50,10 +54,11 @@ class OnboardingStepTwo extends StatelessWidget { page: OnboardingStepFor(), isFast: true), ); }, - child: Text("D'accord", style: TextStyle(fontSize: 20)), + child: const Text("D'accord", + style: TextStyle(fontSize: 20)), ), ))), - SizedBox(height: 80), + const SizedBox(height: 80), ]), )); } diff --git a/lib/screens/onBoarding/3.dart b/lib/screens/onBoarding/3.dart index 6d589cc..815741b 100644 --- a/lib/screens/onBoarding/3.dart +++ b/lib/screens/onBoarding/3.dart @@ -1,7 +1,9 @@ +// ignore_for_file: file_names + import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/4.dart'; // ignore: must_be_immutable @@ -9,6 +11,8 @@ class OnboardingStepFor extends StatelessWidget { TextEditingController tplController = TextEditingController(); final int progress = 3; + OnboardingStepFor({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -22,7 +26,7 @@ class OnboardingStepFor extends StatelessWidget { context, 'Ma phrase de restauration', progress), common.bubbleSpeak( "Si un jour vous changez de téléphone, il vous suffira de me redonner votre phrase de restauration pour recréer votre trousseau.", - textKey: Key('step3'), + textKey: const Key('step3'), ), SizedBox(height: isTall ? 15 : 0), // Row(children: [ @@ -41,7 +45,7 @@ class OnboardingStepFor extends StatelessWidget { width: 400, height: 62, child: ElevatedButton( - key: Key('goStep4'), + key: const Key('goStep4'), style: ElevatedButton.styleFrom( elevation: 5, primary: orangeC, @@ -54,10 +58,10 @@ class OnboardingStepFor extends StatelessWidget { page: OnboardingStepFive(), isFast: true), ); }, - child: Text("J'ai compris", + child: const Text("J'ai compris", style: TextStyle(fontSize: 20))), ))), - SizedBox(height: 80), + const SizedBox(height: 80), ]), )); } diff --git a/lib/screens/onBoarding/4.dart b/lib/screens/onBoarding/4.dart index 8d1feec..bd0317b 100644 --- a/lib/screens/onBoarding/4.dart +++ b/lib/screens/onBoarding/4.dart @@ -1,7 +1,9 @@ +// ignore_for_file: file_names + import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/5.dart'; // ignore: must_be_immutable @@ -9,6 +11,8 @@ class OnboardingStepFive extends StatelessWidget { TextEditingController tplController = TextEditingController(); final int progress = 4; + OnboardingStepFive({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -22,7 +26,7 @@ class OnboardingStepFive extends StatelessWidget { context, 'Ma phrase de restauration', progress), common.bubbleSpeak( "Par contre, attention :\n\nDans une blockchain, il n’y a pas de procédure de récupération de trousseau.\n\nSi vous perdez votre phrase de restauration, je ne pourrai pas vous la communiquer, et vous ne pourrez donc plus jamais accéder à votre compte.", - textKey: Key('step4'), + textKey: const Key('step4'), ), SizedBox(height: isTall ? 30 : 10), Image.asset( @@ -36,7 +40,7 @@ class OnboardingStepFive extends StatelessWidget { width: 400, height: 62, child: ElevatedButton( - key: Key('goStep5'), + key: const Key('goStep5'), style: ElevatedButton.styleFrom( elevation: 5, primary: orangeC, @@ -49,10 +53,10 @@ class OnboardingStepFive extends StatelessWidget { page: OnboardingStepSeven(), isFast: true), ); }, - child: Text("J'ai compris", + child: const Text("J'ai compris", style: TextStyle(fontSize: 20))), ))), - SizedBox(height: 80), + const SizedBox(height: 80), ]), )); } diff --git a/lib/screens/onBoarding/5.dart b/lib/screens/onBoarding/5.dart index 426770f..dbe5ee7 100644 --- a/lib/screens/onBoarding/5.dart +++ b/lib/screens/onBoarding/5.dart @@ -1,7 +1,9 @@ +// ignore_for_file: file_names + import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/6.dart'; // ignore: must_be_immutable @@ -9,6 +11,8 @@ class OnboardingStepSeven extends StatelessWidget { TextEditingController tplController = TextEditingController(); final int progress = 5; + OnboardingStepSeven({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -22,15 +26,15 @@ class OnboardingStepSeven extends StatelessWidget { context, 'Ma phrase de restauration', progress), common.bubbleSpeakRich( [ - TextSpan(text: "Munissez-vous d'"), - TextSpan( + const TextSpan(text: "Munissez-vous d'"), + const TextSpan( text: 'un papier et d’un crayon\n', style: TextStyle(fontWeight: FontWeight.bold)), - TextSpan( + const TextSpan( text: "afin de pouvoir noter votre phrase de restauration."), ], - textKey: Key('step5'), + textKey: const Key('step5'), ), Expanded( child: Align( @@ -53,7 +57,7 @@ class OnboardingStepSeven extends StatelessWidget { width: 400, height: 62, child: ElevatedButton( - key: Key('goStep6'), + key: const Key('goStep6'), style: ElevatedButton.styleFrom( elevation: 5, primary: orangeC, @@ -66,10 +70,10 @@ class OnboardingStepSeven extends StatelessWidget { page: OnboardingStepEight(), isFast: true), ); }, - child: Text("J'ai de quoi noter", + child: const Text("J'ai de quoi noter", style: TextStyle(fontSize: 20))), ), - SizedBox(height: 80), + const SizedBox(height: 80), ]), )); } diff --git a/lib/screens/onBoarding/6.dart b/lib/screens/onBoarding/6.dart index 54155cf..741947d 100644 --- a/lib/screens/onBoarding/6.dart +++ b/lib/screens/onBoarding/6.dart @@ -1,8 +1,10 @@ +// ignore_for_file: file_names + import 'dart:ui'; import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/7.dart'; // ignore: must_be_immutable @@ -10,6 +12,8 @@ class OnboardingStepEight extends StatelessWidget { TextEditingController tplController = TextEditingController(); final int progress = 6; + OnboardingStepEight({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -23,7 +27,7 @@ class OnboardingStepEight extends StatelessWidget { context, 'Ma phrase de restauration', progress), common.bubbleSpeak( "J’ai généré votre phrase de restauration !\nTâchez de la garder bien secrète, car elle permet à quiconque la connaît d’accéder à tous vos portefeuilles.", - textKey: Key('step6'), + textKey: const Key('step6'), ), SizedBox(height: isTall ? 61 : 31), // SizedBox(height: 30), @@ -36,7 +40,7 @@ class OnboardingStepEight extends StatelessWidget { width: 400, height: 62, child: ElevatedButton( - key: Key('goStep7'), + key: const Key('goStep7'), style: ElevatedButton.styleFrom( elevation: 5, primary: orangeC, @@ -49,10 +53,10 @@ class OnboardingStepEight extends StatelessWidget { page: OnboardingStepNine(), isFast: false), ); }, - child: Text("Afficher ma phrase", + child: const Text("Afficher ma phrase", style: TextStyle(fontSize: 20))), ))), - SizedBox(height: 80), + const SizedBox(height: 80), ]), )); } @@ -60,16 +64,16 @@ class OnboardingStepEight extends StatelessWidget { Widget sentanceArray(BuildContext context) { return Container( - padding: EdgeInsets.symmetric(horizontal: 12), + padding: const EdgeInsets.symmetric(horizontal: 12), child: Container( decoration: BoxDecoration( border: Border.all(color: Colors.black), color: Colors.grey[300], - borderRadius: BorderRadius.all( - const Radius.circular(10), + borderRadius: const BorderRadius.all( + Radius.circular(10), )), // color: Colors.grey[300], - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.max, @@ -81,14 +85,14 @@ Widget sentanceArray(BuildContext context) { arrayCell("3:curseur"), arrayCell("4:relatif"), ]), - SizedBox(height: 15), + const SizedBox(height: 15), Row(children: [ arrayCell("5:embellir"), arrayCell("6:cultiver"), arrayCell("7:bureau"), arrayCell("8:ossature"), ]), - SizedBox(height: 15), + const SizedBox(height: 15), Row(children: [ arrayCell("9:labial"), arrayCell("10:science"), @@ -99,20 +103,20 @@ Widget sentanceArray(BuildContext context) { } Widget arrayCell(dataWord) { - return Container( + return SizedBox( width: 102, child: Column( children: [ ImageFiltered( imageFilter: ImageFilter.blur(sigmaX: 1, sigmaY: 1), child: Text(dataWord.split(':')[0], - style: TextStyle(fontSize: 14, color: Colors.black)), + style: const TextStyle(fontSize: 14, color: Colors.black)), ), - SizedBox(height: 2), + const SizedBox(height: 2), ImageFiltered( imageFilter: ImageFilter.blur(sigmaX: 4, sigmaY: 4), child: Text(dataWord.split(':')[1], - style: TextStyle(fontSize: 20, color: Colors.black)), + style: const TextStyle(fontSize: 20, color: Colors.black)), ) ], )); diff --git a/lib/screens/onBoarding/7.dart b/lib/screens/onBoarding/7.dart index 7d5fc06..756f046 100644 --- a/lib/screens/onBoarding/7.dart +++ b/lib/screens/onBoarding/7.dart @@ -1,8 +1,10 @@ +// ignore_for_file: file_names + import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/models/generateWallets.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/models/generate_wallets.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/8.dart'; import 'package:printing/printing.dart'; import 'package:provider/provider.dart'; @@ -12,6 +14,8 @@ class OnboardingStepNine extends StatelessWidget { TextEditingController tplController = TextEditingController(); final int progress = 6; + OnboardingStepNine({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -29,7 +33,7 @@ class OnboardingStepNine extends StatelessWidget { context, 'Ma phrase de restauration', progress), common.bubbleSpeak( "C'est le moment de noter votre phrase !", - textKey: Key('step7'), + textKey: const Key('step7'), long: 60, ), SizedBox(height: isTall ? 100 : 70), @@ -56,24 +60,24 @@ class OnboardingStepNine extends StatelessWidget { width: 400, height: 62, child: ElevatedButton( - key: Key('generateMnemonic'), + key: const Key('generateMnemonic'), style: ElevatedButton.styleFrom( elevation: 5, - primary: Color(0xffFFD58D), + primary: const Color(0xffFFD58D), onPrimary: Colors.black, // foreground ), onPressed: () { _generateWalletProvider.reloadBuild(); }, - child: Text("Choisir une autre phrase", + child: const Text("Choisir une autre phrase", style: TextStyle(fontSize: 20))), ))), - SizedBox(height: 25), + const SizedBox(height: 25), SizedBox( width: 400, height: 62, child: ElevatedButton( - key: Key('goStep8'), + key: const Key('goStep8'), style: ElevatedButton.styleFrom( elevation: 5, primary: orangeC, @@ -97,10 +101,10 @@ class OnboardingStepNine extends StatelessWidget { isFast: true), ); }, - child: Text("J'ai noté ma phrase", + child: const Text("J'ai noté ma phrase", style: TextStyle(fontSize: 20))), ), - SizedBox(height: 80), + const SizedBox(height: 80), ]), )); } @@ -112,7 +116,7 @@ Widget sentanceArray(BuildContext context) { return FutureBuilder( future: _generateWalletProvider.generateWordList(), - initialData: [ + initialData: const [ '1:...', '2:...', '3:...', @@ -129,16 +133,16 @@ Widget sentanceArray(BuildContext context) { builder: (context, formatedArray) { // print(formatedArray.data); return Container( - padding: EdgeInsets.symmetric(horizontal: 12), + padding: const EdgeInsets.symmetric(horizontal: 12), child: Container( decoration: BoxDecoration( border: Border.all(color: Colors.black), color: Colors.grey[300], - borderRadius: BorderRadius.all( - const Radius.circular(10), + borderRadius: const BorderRadius.all( + Radius.circular(10), )), // color: Colors.grey[300], - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.max, @@ -150,14 +154,14 @@ Widget sentanceArray(BuildContext context) { arrayCell(formatedArray.data[2]), arrayCell(formatedArray.data[3]), ]), - SizedBox(height: 15), + const SizedBox(height: 15), Row(children: [ arrayCell(formatedArray.data[4]), arrayCell(formatedArray.data[5]), arrayCell(formatedArray.data[6]), arrayCell(formatedArray.data[7]), ]), - SizedBox(height: 15), + const SizedBox(height: 15), Row(children: [ arrayCell(formatedArray.data[8]), arrayCell(formatedArray.data[9]), @@ -169,20 +173,20 @@ Widget sentanceArray(BuildContext context) { } Widget arrayCell(dataWord) { - return Container( + return SizedBox( width: 102, child: Column(children: [ - Text(dataWord.split(':')[0], style: TextStyle(fontSize: 14)), - SizedBox(height: 2), + Text(dataWord.split(':')[0], style: const TextStyle(fontSize: 14)), + const SizedBox(height: 2), Text(dataWord.split(':')[1], key: Key('word${dataWord.split(':')[0]}'), - style: TextStyle(fontSize: 19, color: Colors.black)), + style: const TextStyle(fontSize: 19, color: Colors.black)), ])); } // ignore: must_be_immutable class PrintWallet extends StatelessWidget { - PrintWallet(this.sentence); + const PrintWallet(this.sentence, {Key key}) : super(key: key); final String sentence; @@ -192,7 +196,9 @@ class PrintWallet extends StatelessWidget { Provider.of(context); return MaterialApp( home: Scaffold( - appBar: AppBar(title: Text('Imprimer ce trousseau')), + appBar: AppBar( + toolbarHeight: 60 * ratio, + title: const Text('Imprimer ce trousseau')), body: PdfPreview( build: (format) => _generateWalletProvider.printWallet(sentence), ), diff --git a/lib/screens/onBoarding/8.dart b/lib/screens/onBoarding/8.dart index 3a16dde..9afcda8 100644 --- a/lib/screens/onBoarding/8.dart +++ b/lib/screens/onBoarding/8.dart @@ -1,10 +1,12 @@ +// ignore_for_file: file_names + import 'dart:ui'; import 'package:dubp/dubp.dart'; import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/models/generateWallets.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/models/generate_wallets.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/9.dart'; import 'package:provider/provider.dart'; @@ -21,7 +23,7 @@ class OnboardingStepTen extends StatelessWidget { TextEditingController tplController = TextEditingController(); TextEditingController wordController = TextEditingController(); - TextEditingController _mnemonicController = TextEditingController(); + final TextEditingController _mnemonicController = TextEditingController(); final int progress = 7; @@ -31,7 +33,7 @@ class OnboardingStepTen extends StatelessWidget { GenerateWalletsProvider _generateWalletProvider = Provider.of(context); CommonElements common = CommonElements(); - this._mnemonicController.text = generatedMnemonic; + _mnemonicController.text = generatedMnemonic; return WillPopScope( onWillPop: () { @@ -60,11 +62,11 @@ class OnboardingStepTen extends StatelessWidget { text: " de votre phrase de restauration :", style: TextStyle(fontSize: 16 * ratio)), ], - textKey: Key('step8'), + textKey: const Key('step8'), ), SizedBox(height: isTall ? 70 : 10), Text('${_generateWalletProvider.nbrWord + 1}', - key: Key('askedWord'), + key: const Key('askedWord'), style: TextStyle( fontSize: isTall ? 17 : 10, color: orangeC, @@ -79,10 +81,10 @@ class OnboardingStepTen extends StatelessWidget { )), width: 430, child: TextFormField( - key: Key('inputWord'), + key: const Key('inputWord'), autofocus: true, enabled: !_generateWalletProvider.isAskedWordValid, - controller: this.wordController, + controller: wordController, textInputAction: TextInputAction.next, onChanged: (value) { _generateWalletProvider.checkAskedWord( @@ -100,7 +102,7 @@ class OnboardingStepTen extends StatelessWidget { : "${_generateWalletProvider.nbrWordAlpha} mot de votre phrase de restauration", fillColor: Colors.grey[300], filled: true, - contentPadding: EdgeInsets.all(12), + contentPadding: const EdgeInsets.all(12), ), style: TextStyle( fontSize: 40.0, @@ -115,7 +117,7 @@ class OnboardingStepTen extends StatelessWidget { width: 400, height: 62, child: ElevatedButton( - key: Key('goStep9'), + key: const Key('goStep9'), style: ElevatedButton.styleFrom( elevation: 5, primary: orangeC, @@ -129,10 +131,10 @@ class OnboardingStepTen extends StatelessWidget { isFast: true), ); }, - child: Text("Continuer", + child: const Text("Continuer", style: TextStyle(fontSize: 20))), )))), - SizedBox(height: 80), + const SizedBox(height: 80), ]), ))); } diff --git a/lib/screens/onBoarding/9.dart b/lib/screens/onBoarding/9.dart index 67b9cc5..35b285e 100644 --- a/lib/screens/onBoarding/9.dart +++ b/lib/screens/onBoarding/9.dart @@ -1,7 +1,9 @@ +// ignore_for_file: file_names + import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:gecko/globals.dart'; -import 'package:gecko/screens/commonElements.dart'; +import 'package:gecko/screens/common_elements.dart'; import 'package:gecko/screens/onBoarding/10.dart'; // ignore: must_be_immutable @@ -9,6 +11,8 @@ class OnboardingStepEleven extends StatelessWidget { TextEditingController tplController = TextEditingController(); final int progress = 8; + OnboardingStepEleven({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); @@ -22,15 +26,16 @@ class OnboardingStepEleven extends StatelessWidget { context, 'Ma phrase de restauration', progress), common.bubbleSpeakRich( [ - TextSpan(text: "Super !\n\nJe vais maintenant créer votre "), - TextSpan( + const TextSpan( + text: "Super !\n\nJe vais maintenant créer votre "), + const TextSpan( text: 'code secret.', style: TextStyle(fontWeight: FontWeight.bold)), - TextSpan( + const TextSpan( text: " \n\nVotre code secret chiffre votre trousseau de clefs, ce qui le rend inutilisable par d’autres, par exemple si vous perdez votre téléphone ou si on vous le vole."), ], - textKey: Key('step9'), + textKey: const Key('step9'), ), SizedBox(height: isTall ? 50 : 10), Image.asset( @@ -44,7 +49,7 @@ class OnboardingStepEleven extends StatelessWidget { width: 400, height: 62, child: ElevatedButton( - key: Key('goStep10'), + key: const Key('goStep10'), style: ElevatedButton.styleFrom( elevation: 5, primary: orangeC, @@ -57,10 +62,10 @@ class OnboardingStepEleven extends StatelessWidget { page: OnboardingStepTwelve(), isFast: true), ); }, - child: Text("J'ai compris", + child: const Text("J'ai compris", style: TextStyle(fontSize: 20))), ))), - SizedBox(height: 80), + const SizedBox(height: 80), ]), )); } diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 3f8148a..9494df2 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -2,10 +2,10 @@ import 'package:flutter/material.dart'; import 'package:dubp/dubp.dart'; import 'package:flutter/services.dart'; import 'package:gecko/models/home.dart'; -import 'package:gecko/models/myWallets.dart'; -import 'package:gecko/screens/myWallets/generateWallets.dart'; +import 'package:gecko/models/my_wallets.dart'; +import 'package:gecko/screens/myWallets/generate_wallets.dart'; import 'dart:io'; -import 'package:gecko/screens/myWallets/importWallet.dart'; +import 'package:gecko/screens/myWallets/import_wallet.dart'; import 'package:gecko/globals.dart'; import 'package:provider/provider.dart'; @@ -22,7 +22,9 @@ class SettingsScreen extends StatelessWidget { var pinColor = Colors.grey[300]; Directory appPath; - MyWalletsProvider _myWallets = MyWalletsProvider(); + final MyWalletsProvider _myWallets = MyWalletsProvider(); + + SettingsScreen({Key key}) : super(key: key); @override Widget build(BuildContext context) { @@ -32,12 +34,13 @@ class SettingsScreen extends StatelessWidget { // getAppDirectory(); return Scaffold( appBar: AppBar( - title: SizedBox( - height: 22, - child: Text('Paramètres'), - )), + toolbarHeight: 60 * ratio, + title: const SizedBox( + height: 22, + child: Text('Paramètres'), + )), body: Column(children: [ - SizedBox(height: 40), + const SizedBox(height: 40), SizedBox( height: 70, width: 500, @@ -50,35 +53,31 @@ class SettingsScreen extends StatelessWidget { onPressed: () => Navigator.push( context, MaterialPageRoute(builder: (context) { - return ImportWalletScreen(); + return const ImportWalletScreen(); }), ).then((value) => { if (value == true) {Navigator.pop(context)} }), - child: Text("Importer un portefeuille Cesium", + child: const Text("Importer un portefeuille Cesium", style: TextStyle(fontSize: 16)))), - SizedBox(height: 30), + const SizedBox(height: 30), SizedBox( height: 70, width: 500, child: ElevatedButton( - key: Key('generateKeychain'), + key: const Key('generateKeychain'), style: ElevatedButton.styleFrom( elevation: 5, primary: yellowC, // background onPrimary: Colors.black, // foreground ), - onPressed: !_myWallets.checkIfWalletExist() - ? () => Navigator.push( - context, - MaterialPageRoute(builder: (context) { - return GenerateWalletsScreen(); - }), - ).then((value) => { - if (value == true) {Navigator.pop(context)} - }) - : null, - child: Text("Générer un nouveau trousseau", + onPressed: () => Navigator.push( + context, + MaterialPageRoute(builder: (context) { + return GenerateFastChestScreen(); + }), + ), + child: const Text("Générer un nouveau trousseau", style: TextStyle(fontSize: 16)))), Expanded( child: Align( @@ -87,7 +86,7 @@ class SettingsScreen extends StatelessWidget { height: 100, width: 500, child: ElevatedButton( - key: Key('deleteAllWallets'), + key: const Key('deleteAllWallets'), style: ElevatedButton.styleFrom( elevation: 5, primary: Colors.redAccent, // background @@ -99,9 +98,9 @@ class SettingsScreen extends StatelessWidget { .deleteAllWallet(context) .then((v) => _homeProvider.rebuildWidget()) }, - child: Text("EFFACER TOUS MES PORTEFEUILLES", + child: const Text("EFFACER TOUS MES PORTEFEUILLES", style: TextStyle(fontSize: 20)))))), - SizedBox(height: 50), + const SizedBox(height: 50), ])); } } diff --git a/lib/screens/templateScreen.dart b/lib/screens/template_screen.dart similarity index 76% rename from lib/screens/templateScreen.dart rename to lib/screens/template_screen.dart index cf6dfd6..4759e7b 100644 --- a/lib/screens/templateScreen.dart +++ b/lib/screens/template_screen.dart @@ -9,17 +9,20 @@ import 'package:flutter/material.dart'; class TemplateScreen extends StatelessWidget { TextEditingController tplController = TextEditingController(); + TemplateScreen({Key key}) : super(key: key); + @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); // HomeProvider _homeProvider = Provider.of(context); return Scaffold( appBar: AppBar( - title: SizedBox( - height: 22, - child: Text('Template screen'), - )), - floatingActionButton: Container( + toolbarHeight: 60 * ratio, + title: const SizedBox( + height: 22, + child: Text('Template screen'), + )), + floatingActionButton: SizedBox( height: 80.0, width: 80.0, child: FittedBox( @@ -28,10 +31,10 @@ class TemplateScreen extends StatelessWidget { onPressed: () => Navigator.push( context, MaterialPageRoute(builder: (context) { - return HomeScreen(); + return const HomeScreen(); }), ), - child: Container( + child: SizedBox( height: 40.0, width: 40.0, child: Icon(Icons.home, color: Colors.grey[850]), @@ -41,20 +44,20 @@ class TemplateScreen extends StatelessWidget { ))), body: SafeArea( child: Column(children: [ - SizedBox(height: 20), + const SizedBox(height: 20), TextField( enabled: true, controller: tplController, maxLines: 1, textAlign: TextAlign.center, - decoration: InputDecoration( + decoration: const InputDecoration( contentPadding: EdgeInsets.all(15.0), ), - style: TextStyle( + style: const TextStyle( fontSize: 22.0, color: Colors.black, fontWeight: FontWeight.w400)), - SizedBox(height: 20), + const SizedBox(height: 20), ElevatedButton( style: ElevatedButton.styleFrom( primary: yellowC, // background @@ -64,12 +67,13 @@ class TemplateScreen extends StatelessWidget { Navigator.push( context, MaterialPageRoute(builder: (context) { - return HomeScreen(); + return const HomeScreen(); }), ); }, - child: Text('Retour Accueil', style: TextStyle(fontSize: 20))), - SizedBox(height: 20), + child: const Text('Retour Accueil', + style: TextStyle(fontSize: 20))), + const SizedBox(height: 20), GestureDetector( onTap: () { Navigator.popUntil( @@ -77,7 +81,7 @@ class TemplateScreen extends StatelessWidget { ModalRoute.withName('/'), ); }, - child: Icon(Icons.home)) + child: const Icon(Icons.home)) ]), )); } diff --git a/macos/.gitignore b/macos/.gitignore new file mode 100644 index 0000000..746adbb --- /dev/null +++ b/macos/.gitignore @@ -0,0 +1,7 @@ +# Flutter-related +**/Flutter/ephemeral/ +**/Pods/ + +# Xcode-related +**/dgph +**/xcuserdata/ diff --git a/macos/Flutter/Flutter-Debug.xcconfig b/macos/Flutter/Flutter-Debug.xcconfig new file mode 100644 index 0000000..c2efd0b --- /dev/null +++ b/macos/Flutter/Flutter-Debug.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/macos/Flutter/Flutter-Release.xcconfig b/macos/Flutter/Flutter-Release.xcconfig new file mode 100644 index 0000000..c2efd0b --- /dev/null +++ b/macos/Flutter/Flutter-Release.xcconfig @@ -0,0 +1 @@ +#include "ephemeral/Flutter-Generated.xcconfig" diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift new file mode 100644 index 0000000..fc41ebe --- /dev/null +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -0,0 +1,24 @@ +// +// Generated file. Do not edit. +// + +import FlutterMacOS +import Foundation + +import connectivity_plus_macos +import package_info +import package_info_plus_macos +import path_provider_macos +import printing +import sentry_flutter +import shared_preferences_macos + +func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin")) + FLTPackageInfoPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlugin")) + FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) + PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) + PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin")) + SentryFlutterPlugin.register(with: registry.registrar(forPlugin: "SentryFlutterPlugin")) + SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) +} diff --git a/macos/Runner.xcodeproj/project.pbxproj b/macos/Runner.xcodeproj/project.pbxproj new file mode 100644 index 0000000..bfee57a --- /dev/null +++ b/macos/Runner.xcodeproj/project.pbxproj @@ -0,0 +1,572 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 51; + objects = { + +/* Begin PBXAggregateTarget section */ + 33CC111A2044C6BA0003C045 /* Flutter Assemble */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */; + buildPhases = ( + 33CC111E2044C6BF0003C045 /* ShellScript */, + ); + dependencies = ( + ); + name = "Flutter Assemble"; + productName = FLX; + }; +/* End PBXAggregateTarget section */ + +/* Begin PBXBuildFile section */ + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */; }; + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC10F02044A3C60003C045 /* AppDelegate.swift */; }; + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F22044A3C60003C045 /* Assets.xcassets */; }; + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 33CC10F42044A3C60003C045 /* MainMenu.xib */; }; + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */; }; +/* End PBXBuildFile section */ + +/* Begin PBXContainerItemProxy section */ + 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 33CC10E52044A3C60003C045 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 33CC111A2044C6BA0003C045; + remoteInfo = FLX; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 33CC110E2044A8840003C045 /* Bundle Framework */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + ); + name = "Bundle Framework"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Warnings.xcconfig; sourceTree = ""; }; + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GeneratedPluginRegistrant.swift; sourceTree = ""; }; + 33CC10ED2044A3C60003C045 /* gecko.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "gecko.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 33CC10F02044A3C60003C045 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; + 33CC10F22044A3C60003C045 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Assets.xcassets; path = Runner/Assets.xcassets; sourceTree = ""; }; + 33CC10F52044A3C60003C045 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 33CC10F72044A3C60003C045 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = Runner/Info.plist; sourceTree = ""; }; + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainFlutterWindow.swift; sourceTree = ""; }; + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Debug.xcconfig"; sourceTree = ""; }; + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = "Flutter-Release.xcconfig"; sourceTree = ""; }; + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = "Flutter-Generated.xcconfig"; path = "ephemeral/Flutter-Generated.xcconfig"; sourceTree = ""; }; + 33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = ""; }; + 33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = ""; }; + 33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = ""; }; + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; + 9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 33CC10EA2044A3C60003C045 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 33BA886A226E78AF003329D5 /* Configs */ = { + isa = PBXGroup; + children = ( + 33E5194F232828860026EE4D /* AppInfo.xcconfig */, + 9740EEB21CF90195004384FC /* Debug.xcconfig */, + 7AFA3C8E1D35360C0083082E /* Release.xcconfig */, + 333000ED22D3DE5D00554162 /* Warnings.xcconfig */, + ); + path = Configs; + sourceTree = ""; + }; + 33CC10E42044A3C60003C045 = { + isa = PBXGroup; + children = ( + 33FAB671232836740065AC1E /* Runner */, + 33CEB47122A05771004F2AC0 /* Flutter */, + 33CC10EE2044A3C60003C045 /* Products */, + D73912EC22F37F3D000D13A0 /* Frameworks */, + ); + sourceTree = ""; + }; + 33CC10EE2044A3C60003C045 /* Products */ = { + isa = PBXGroup; + children = ( + 33CC10ED2044A3C60003C045 /* gecko.app */, + ); + name = Products; + sourceTree = ""; + }; + 33CC11242044D66E0003C045 /* Resources */ = { + isa = PBXGroup; + children = ( + 33CC10F22044A3C60003C045 /* Assets.xcassets */, + 33CC10F42044A3C60003C045 /* MainMenu.xib */, + 33CC10F72044A3C60003C045 /* Info.plist */, + ); + name = Resources; + path = ..; + sourceTree = ""; + }; + 33CEB47122A05771004F2AC0 /* Flutter */ = { + isa = PBXGroup; + children = ( + 335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */, + 33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */, + 33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */, + 33CEB47722A0578A004F2AC0 /* Flutter-Generated.xcconfig */, + ); + path = Flutter; + sourceTree = ""; + }; + 33FAB671232836740065AC1E /* Runner */ = { + isa = PBXGroup; + children = ( + 33CC10F02044A3C60003C045 /* AppDelegate.swift */, + 33CC11122044BFA00003C045 /* MainFlutterWindow.swift */, + 33E51913231747F40026EE4D /* DebugProfile.entitlements */, + 33E51914231749380026EE4D /* Release.entitlements */, + 33CC11242044D66E0003C045 /* Resources */, + 33BA886A226E78AF003329D5 /* Configs */, + ); + path = Runner; + sourceTree = ""; + }; + D73912EC22F37F3D000D13A0 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 33CC10EC2044A3C60003C045 /* Runner */ = { + isa = PBXNativeTarget; + buildConfigurationList = 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */; + buildPhases = ( + 33CC10E92044A3C60003C045 /* Sources */, + 33CC10EA2044A3C60003C045 /* Frameworks */, + 33CC10EB2044A3C60003C045 /* Resources */, + 33CC110E2044A8840003C045 /* Bundle Framework */, + 3399D490228B24CF009A79C7 /* ShellScript */, + ); + buildRules = ( + ); + dependencies = ( + 33CC11202044C79F0003C045 /* PBXTargetDependency */, + ); + name = Runner; + productName = Runner; + productReference = 33CC10ED2044A3C60003C045 /* gecko.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 33CC10E52044A3C60003C045 /* Project object */ = { + isa = PBXProject; + attributes = { + LastSwiftUpdateCheck = 0920; + LastUpgradeCheck = 0930; + ORGANIZATIONNAME = ""; + TargetAttributes = { + 33CC10EC2044A3C60003C045 = { + CreatedOnToolsVersion = 9.2; + LastSwiftMigration = 1100; + ProvisioningStyle = Automatic; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 1; + }; + }; + }; + 33CC111A2044C6BA0003C045 = { + CreatedOnToolsVersion = 9.2; + ProvisioningStyle = Manual; + }; + }; + }; + buildConfigurationList = 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 33CC10E42044A3C60003C045; + productRefGroup = 33CC10EE2044A3C60003C045 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 33CC10EC2044A3C60003C045 /* Runner */, + 33CC111A2044C6BA0003C045 /* Flutter Assemble */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 33CC10EB2044A3C60003C045 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC10F32044A3C60003C045 /* Assets.xcassets in Resources */, + 33CC10F62044A3C60003C045 /* MainMenu.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 3399D490228B24CF009A79C7 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "echo \"$PRODUCT_NAME.app\" > \"$PROJECT_DIR\"/Flutter/ephemeral/.app_filename && \"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh embed\n"; + }; + 33CC111E2044C6BF0003C045 /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + Flutter/ephemeral/FlutterInputs.xcfilelist, + ); + inputPaths = ( + Flutter/ephemeral/tripwire, + ); + outputFileListPaths = ( + Flutter/ephemeral/FlutterOutputs.xcfilelist, + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"$FLUTTER_ROOT\"/packages/flutter_tools/bin/macos_assemble.sh && touch Flutter/ephemeral/tripwire"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 33CC10E92044A3C60003C045 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 33CC11132044BFA00003C045 /* MainFlutterWindow.swift in Sources */, + 33CC10F12044A3C60003C045 /* AppDelegate.swift in Sources */, + 335BBD1B22A9A15E00E9071D /* GeneratedPluginRegistrant.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 33CC11202044C79F0003C045 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 33CC111A2044C6BA0003C045 /* Flutter Assemble */; + targetProxy = 33CC111F2044C79F0003C045 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin PBXVariantGroup section */ + 33CC10F42044A3C60003C045 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 33CC10F52044A3C60003C045 /* Base */, + ); + name = MainMenu.xib; + path = Runner; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 338D0CE9231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Profile; + }; + 338D0CEA231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Profile; + }; + 338D0CEB231458BD00FA5F75 /* Profile */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Profile; + }; + 33CC10F92044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 33CC10FA2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.11; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = macosx; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + }; + name = Release; + }; + 33CC10FC2044A3C60003C045 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/DebugProfile.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + }; + name = Debug; + }; + 33CC10FD2044A3C60003C045 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 33E5194F232828860026EE4D /* AppInfo.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_ENTITLEMENTS = Runner/Release.entitlements; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + INFOPLIST_FILE = Runner/Info.plist; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + PROVISIONING_PROFILE_SPECIFIER = ""; + SWIFT_VERSION = 5.0; + }; + name = Release; + }; + 33CC111C2044C6BA0003C045 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Manual; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 33CC111D2044C6BA0003C045 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CODE_SIGN_STYLE = Automatic; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 33CC10E82044A3C60003C045 /* Build configuration list for PBXProject "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10F92044A3C60003C045 /* Debug */, + 33CC10FA2044A3C60003C045 /* Release */, + 338D0CE9231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC10FB2044A3C60003C045 /* Build configuration list for PBXNativeTarget "Runner" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC10FC2044A3C60003C045 /* Debug */, + 33CC10FD2044A3C60003C045 /* Release */, + 338D0CEA231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 33CC111B2044C6BA0003C045 /* Build configuration list for PBXAggregateTarget "Flutter Assemble" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 33CC111C2044C6BA0003C045 /* Debug */, + 33CC111D2044C6BA0003C045 /* Release */, + 338D0CEB231458BD00FA5F75 /* Profile */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 33CC10E52044A3C60003C045 /* Project object */; +} diff --git a/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/macos/Runner.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme new file mode 100644 index 0000000..1e2f67b --- /dev/null +++ b/macos/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -0,0 +1,89 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macos/Runner.xcworkspace/contents.xcworkspacedata b/macos/Runner.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..1d526a1 --- /dev/null +++ b/macos/Runner.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/macos/Runner.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/macos/Runner/AppDelegate.swift b/macos/Runner/AppDelegate.swift new file mode 100644 index 0000000..d53ef64 --- /dev/null +++ b/macos/Runner/AppDelegate.swift @@ -0,0 +1,9 @@ +import Cocoa +import FlutterMacOS + +@NSApplicationMain +class AppDelegate: FlutterAppDelegate { + override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + return true + } +} diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json b/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..a2ec33f --- /dev/null +++ b/macos/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,68 @@ +{ + "images" : [ + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "app_icon_16.png", + "scale" : "1x" + }, + { + "size" : "16x16", + "idiom" : "mac", + "filename" : "app_icon_32.png", + "scale" : "2x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "app_icon_32.png", + "scale" : "1x" + }, + { + "size" : "32x32", + "idiom" : "mac", + "filename" : "app_icon_64.png", + "scale" : "2x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "app_icon_128.png", + "scale" : "1x" + }, + { + "size" : "128x128", + "idiom" : "mac", + "filename" : "app_icon_256.png", + "scale" : "2x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "app_icon_256.png", + "scale" : "1x" + }, + { + "size" : "256x256", + "idiom" : "mac", + "filename" : "app_icon_512.png", + "scale" : "2x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "app_icon_512.png", + "scale" : "1x" + }, + { + "size" : "512x512", + "idiom" : "mac", + "filename" : "app_icon_1024.png", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png new file mode 100644 index 0000000..3c4935a Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_1024.png differ diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png new file mode 100644 index 0000000..ed4cc16 Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_128.png differ diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png new file mode 100644 index 0000000..483be61 Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_16.png differ diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png new file mode 100644 index 0000000..bcbf36d Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_256.png differ diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png new file mode 100644 index 0000000..9c0a652 Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_32.png differ diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png new file mode 100644 index 0000000..e71a726 Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_512.png differ diff --git a/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png new file mode 100644 index 0000000..8a31fe2 Binary files /dev/null and b/macos/Runner/Assets.xcassets/AppIcon.appiconset/app_icon_64.png differ diff --git a/macos/Runner/Base.lproj/MainMenu.xib b/macos/Runner/Base.lproj/MainMenu.xib new file mode 100644 index 0000000..537341a --- /dev/null +++ b/macos/Runner/Base.lproj/MainMenu.xib @@ -0,0 +1,339 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/macos/Runner/Configs/AppInfo.xcconfig b/macos/Runner/Configs/AppInfo.xcconfig new file mode 100644 index 0000000..b374696 --- /dev/null +++ b/macos/Runner/Configs/AppInfo.xcconfig @@ -0,0 +1,14 @@ +// Application-level settings for the Runner target. +// +// This may be replaced with something auto-generated from metadata (e.g., pubspec.yaml) in the +// future. If not, the values below would default to using the project name when this becomes a +// 'flutter create' template. + +// The application's name. By default this is also the title of the Flutter window. +PRODUCT_NAME = gecko + +// The application's bundle identifier +PRODUCT_BUNDLE_IDENTIFIER = com.example.gecko + +// The copyright displayed in application information +PRODUCT_COPYRIGHT = Copyright © 2021 com.example. All rights reserved. diff --git a/macos/Runner/Configs/Debug.xcconfig b/macos/Runner/Configs/Debug.xcconfig new file mode 100644 index 0000000..36b0fd9 --- /dev/null +++ b/macos/Runner/Configs/Debug.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Debug.xcconfig" +#include "Warnings.xcconfig" diff --git a/macos/Runner/Configs/Release.xcconfig b/macos/Runner/Configs/Release.xcconfig new file mode 100644 index 0000000..dff4f49 --- /dev/null +++ b/macos/Runner/Configs/Release.xcconfig @@ -0,0 +1,2 @@ +#include "../../Flutter/Flutter-Release.xcconfig" +#include "Warnings.xcconfig" diff --git a/macos/Runner/Configs/Warnings.xcconfig b/macos/Runner/Configs/Warnings.xcconfig new file mode 100644 index 0000000..42bcbf4 --- /dev/null +++ b/macos/Runner/Configs/Warnings.xcconfig @@ -0,0 +1,13 @@ +WARNING_CFLAGS = -Wall -Wconditional-uninitialized -Wnullable-to-nonnull-conversion -Wmissing-method-return-type -Woverlength-strings +GCC_WARN_UNDECLARED_SELECTOR = YES +CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES +CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE +CLANG_WARN__DUPLICATE_METHOD_MATCH = YES +CLANG_WARN_PRAGMA_PACK = YES +CLANG_WARN_STRICT_PROTOTYPES = YES +CLANG_WARN_COMMA = YES +GCC_WARN_STRICT_SELECTOR_MATCH = YES +CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES +CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES +GCC_WARN_SHADOW = YES +CLANG_WARN_UNREACHABLE_CODE = YES diff --git a/macos/Runner/DebugProfile.entitlements b/macos/Runner/DebugProfile.entitlements new file mode 100644 index 0000000..dddb8a3 --- /dev/null +++ b/macos/Runner/DebugProfile.entitlements @@ -0,0 +1,12 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.cs.allow-jit + + com.apple.security.network.server + + + diff --git a/macos/Runner/Info.plist b/macos/Runner/Info.plist new file mode 100644 index 0000000..4789daa --- /dev/null +++ b/macos/Runner/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + $(FLUTTER_BUILD_NAME) + CFBundleVersion + $(FLUTTER_BUILD_NUMBER) + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + $(PRODUCT_COPYRIGHT) + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/macos/Runner/MainFlutterWindow.swift b/macos/Runner/MainFlutterWindow.swift new file mode 100644 index 0000000..2722837 --- /dev/null +++ b/macos/Runner/MainFlutterWindow.swift @@ -0,0 +1,15 @@ +import Cocoa +import FlutterMacOS + +class MainFlutterWindow: NSWindow { + override func awakeFromNib() { + let flutterViewController = FlutterViewController.init() + let windowFrame = self.frame + self.contentViewController = flutterViewController + self.setFrame(windowFrame, display: true) + + RegisterGeneratedPlugins(registry: flutterViewController) + + super.awakeFromNib() + } +} diff --git a/macos/Runner/Release.entitlements b/macos/Runner/Release.entitlements new file mode 100644 index 0000000..852fa1a --- /dev/null +++ b/macos/Runner/Release.entitlements @@ -0,0 +1,8 @@ + + + + + com.apple.security.app-sandbox + + + diff --git a/packages/dubp_rs/pubspec.lock b/packages/dubp_rs/pubspec.lock index 98f9562..e6f0b3d 100644 --- a/packages/dubp_rs/pubspec.lock +++ b/packages/dubp_rs/pubspec.lock @@ -7,7 +7,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0" + version: "2.8.1" boolean_selector: dependency: transitive description: @@ -28,7 +28,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -108,7 +108,7 @@ packages: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: @@ -127,7 +127,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.8.1" stack_trace: dependency: transitive description: @@ -169,7 +169,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19" + version: "0.4.2" typed_data: dependency: transitive description: diff --git a/pubspec.lock b/pubspec.lock index ee51741..49c04fe 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -29,6 +29,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "2.3.0" + assorted_layout_widgets: + dependency: "direct main" + description: + name: assorted_layout_widgets + url: "https://pub.dartlang.org" + source: hosted + version: "5.2.1" async: dependency: transitive description: @@ -113,6 +120,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "8.1.3" + carousel_slider: + dependency: "direct main" + description: + name: carousel_slider + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.0" characters: dependency: transitive description: @@ -162,6 +176,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.15.0" + confirm_dialog: + dependency: "direct main" + description: + name: confirm_dialog + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.0" connectivity_plus: dependency: transitive description: @@ -312,6 +333,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.9.2" + flutter_lints: + dependency: "direct main" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" flutter_logs: dependency: "direct main" description: @@ -563,6 +591,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "4.3.0" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" logger: dependency: "direct main" description: @@ -584,6 +619,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.12.10" + matrix4_transform: + dependency: transitive + description: + name: matrix4_transform + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" meta: dependency: transitive description: @@ -779,7 +821,7 @@ packages: name: pin_code_fields url: "https://pub.dartlang.org" source: hosted - version: "6.1.0" + version: "7.3.0" platform: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index d6fbafd..7de7c38 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,7 +5,7 @@ description: Pay with G1. # pub.dev using `pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 0.0.2+7 +version: 0.0.2+11 environment: sdk: ">=2.7.0 <3.0.0" @@ -20,7 +20,7 @@ dependencies: sdk: flutter flutter_driver: sdk: flutter - flutter_launcher_icons: ^0.9.0 + flutter_launcher_icons: ^0.9.2 flutter_logs: ^2.1.4 flutter_svg: ^0.22.0 graphql_flutter: ^5.0.0 @@ -36,7 +36,7 @@ dependencies: path_provider: ^2.0.3 pdf: ^3.5.0 permission_handler: 8.1.6 - pin_code_fields: ^6.0.2 + pin_code_fields: ^7.3.0 printing: ^5.6.0 provider: ^6.0.0 qrscan: ^0.3.2 @@ -53,11 +53,15 @@ dependencies: truncate: ^3.0.1 unorm_dart: ^0.2.0 xml: ^5.3.0 + assorted_layout_widgets: ^5.2.1 + carousel_slider: ^4.0.0 + flutter_lints: ^1.0.4 + confirm_dialog: ^1.0.0 flutter_icons: android: "ic_launcher" ios: true - image_path: "assets/icon/gecko_final.png" + image_path: "assets/icon/gecko_flat.png" cupertino_icons: ^1.0.0 dev_dependencies: @@ -76,6 +80,9 @@ flutter: - images/ - config/gva_endpoints.json - assets/ + - assets/customs/ + - assets/avatars/ + - assets/chests/ - assets/icon/ - assets/onBoarding/ - assets/onBoarding/progress_bar/ diff --git a/scripts/generatePartFiles.sh b/scripts/generatePartFiles.sh new file mode 100755 index 0000000..05b776a --- /dev/null +++ b/scripts/generatePartFiles.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +flutter packages pub run build_runner build --delete-conflicting-outputs + diff --git a/test_driver/app_test.dart b/test_driver/app_test.dart index 7bcf48b..e9f4c76 100644 --- a/test_driver/app_test.dart +++ b/test_driver/app_test.dart @@ -1,4 +1,5 @@ -// Imports the Flutter Driver API. +// ignore_for_file: avoid_print + import 'dart:async'; import 'dart:io'; import 'package:flutter_driver/flutter_driver.dart'; @@ -70,13 +71,8 @@ void main() { } // Create a derivation - Future createDerivation(String _name) async { + Future createDerivation() async { await tapOn('addDerivation'); - await sleep(100); - - await driver.enterText(_name); - - await tapOn('validDerivation'); await sleep(300); } @@ -117,6 +113,7 @@ void main() { await driver.enterText('triche'); await tapOn('walletName'); await driver.enterText(name); + await sleep(50); await tapOn('confirmStorage'); await sleep(300); return pinCode; @@ -125,13 +122,10 @@ void main() { // *** Begin of tests *** // test('OnBoarding - Open wallets management', ( - {timeout: Timeout.none}) async { + {timeout = Timeout.none}) async { // await driver.runUnsynchronized(() async { // Needed if we want to manage async drivers await driver.tap(manageWalletsFinder); - print( - '####################################################################'); - // If a wallet exist, go to delete theme all if (!await isPresent(find.byValueKey('goStep1'))) { await goBack(); @@ -154,7 +148,7 @@ void main() { }); test('OnBoarding - Go to create restore sentance', ( - {timeout: Timeout.none}) async { + {timeout = Timeout.none}) async { await tapOn('goStep1'); await tapOn('goStep2'); await tapOn('goStep3'); @@ -170,7 +164,7 @@ void main() { }); test('OnBoarding - Generate sentance and confirme it', ( - {timeout: Timeout.none}) async { + {timeout = Timeout.none}) async { await tapOn('goStep7'); while (await getText('word1') == '...') { @@ -220,7 +214,7 @@ void main() { await selectWord(); }); test('OnBoarding - Generate secret code and confirm it', ( - {timeout: Timeout.none}) async { + {timeout = Timeout.none}) async { expect(await getText('step9'), "Super !\n\nJe vais maintenant créer votre code secret. \n\nVotre code secret chiffre votre trousseau de clefs, ce qui le rend inutilisable par d’autres, par exemple si vous perdez votre téléphone ou si on vous le vole."); @@ -233,7 +227,9 @@ void main() { } // Change secret code 4 times - for (int i = 0; i < 4; i++) await tapOn('changeSecretCode'); + for (int i = 0; i < 4; i++) { + await tapOn('changeSecretCode'); + } await sleep(500); pinCode = await getText('generatedPin'); @@ -255,10 +251,10 @@ void main() { }); test('My wallets - Rename first derivation', ( - {timeout: const Duration(seconds: 2)}) async { + {timeout = const Duration(seconds: 2)}) async { await tapOn('goWalletHome'); - expect(await getText('myWallets'), "Mes portefeuilles"); + expect(await getText('myWallets'), "Coffre à Ğecko"); await sleep(300); // Go to first derivation and rename it @@ -278,13 +274,13 @@ void main() { }); test('My wallets - Create a derivations, open thems, tap all buttons', ( - {timeout: const Duration(seconds: 2)}) async { + {timeout = const Duration(seconds: 2)}) async { await driver.waitFor(find.text('Renommage wallet 1'), timeout: timeout); // Add a second derivation - await createDerivation('Derivation 2'); + await createDerivation(); // Go to second derivation options - await driver.tap(find.text('Derivation 2')); + await driver.tap(find.text('Portefeuille 2')); await sleep(100); // Test options @@ -305,14 +301,14 @@ void main() { await goBack(); // Add a third derivation - await createDerivation('Derivation 3'); + await createDerivation(); // Add a fourth derivation - await createDerivation('Derivation 4'); + await createDerivation(); await sleep(50); // Go to third derivation options - await driver.tap(find.text('Derivation 3')); + await driver.tap(find.text('Portefeuille 3')); await sleep(100); await tapOn('displayBalance'); @@ -321,12 +317,12 @@ void main() { }); test('My wallets - Extra tests', ( - {timeout: const Duration(seconds: 2)}) async { + {timeout = const Duration(seconds: 2)}) async { // Add derivation 5,6 and 7 - await driver.waitFor(find.text('Derivation 4'), timeout: timeout); - await createDerivation('Derivation 5'); - await createDerivation('Derivation 6'); - await createDerivation('Derivation 7'); + await driver.waitFor(find.text('Portefeuille 4'), timeout: timeout); + await createDerivation(); + await createDerivation(); + await createDerivation(); // Go home and come back to my wallets view await goBack(); @@ -338,12 +334,12 @@ void main() { await sleep(200); // Go to derivation 6 and delete it - await driver.tap(find.text('Derivation 6')); + await driver.tap(find.text('Portefeuille 6')); await sleep(100); await deleteWallet(true); // Go to 2nd derivation and check if it's de default - await driver.tap(find.text('Derivation 2')); + await driver.tap(find.text('Portefeuille 2')); await driver.waitFor(find.text('Ce portefeuille est celui par defaut')); await tapOn('setDefaultWallet'); await sleep(100); @@ -369,37 +365,44 @@ void main() { await sleep(400); await goBack(); await driver.waitFor(find.text('Renommage wallet 2')); - await createDerivation('Derivation 8'); - await createDerivation('Derivation 9'); - await createDerivation('Derivation 10'); - await createDerivation('Derivation 11'); - await createDerivation('Derivation 12'); - await createDerivation('Derivation 13'); - await createDerivation('Derivation 14'); - await createDerivation('Derivation 15'); - await createDerivation('Derivation 16'); - await createDerivation('Derivation 17'); - await createDerivation('Derivation 18'); - await createDerivation('Derivation 19'); - await createDerivation('Derivation 20'); + await driver.scrollIntoView(find.text('+')); + await createDerivation(); + await createDerivation(); + await driver.scrollIntoView(find.text('+')); + await createDerivation(); + await createDerivation(); + await driver.scrollIntoView(find.text('+')); + await createDerivation(); + await createDerivation(); + await driver.scrollIntoView(find.text('+')); + await createDerivation(); + await createDerivation(); + await driver.scrollIntoView(find.text('+')); + await createDerivation(); + await createDerivation(); + await driver.scrollIntoView(find.text('+')); + await createDerivation(); + await createDerivation(); + await driver.scrollIntoView(find.text('+')); + await createDerivation(); await sleep(400); // Scroll the wallet screen until Derivation 20 and open it await driver.scrollUntilVisible( find.byValueKey('listWallets'), - find.text('Derivation 20'), + find.text('Portefeuille 20'), dyScroll: -300.0, ); - await driver.waitFor(find.text('Derivation 20')); + await driver.waitFor(find.text('Portefeuille 20')); await sleep(400); - await driver.tap(find.text('Derivation 20')); + await driver.tap(find.text('Portefeuille 20')); await tapOn('copyPubkey'); }); test('Search - Search Pi profile, navigate in history transactions', ( - {timeout: const Duration(seconds: 2)}) async { - await driver.waitFor(find.text('Derivation 20'), timeout: timeout); + {timeout = const Duration(seconds: 2)}) async { + await driver.waitFor(find.text('Portefeuille 20'), timeout: timeout); await goBack(); await goBack(); await sleep(200); @@ -430,19 +433,17 @@ void main() { }, timeout: Timeout(Duration(minutes: globalTimeout))); test('Wallet generation - Fast wallets generations', ( - {timeout: const Duration(seconds: 2)}) async { + {timeout = const Duration(seconds: 2)}) async { await driver.waitFor(find.text('Commentaire:'), timeout: timeout); await goBack(); await goBack(); await deleteAllWallets(); await sleep(100); final String pincode = await createNewKeychain('Fast wallet'); - await sleep(100); - await tapOn('manageWallets'); await sleep(200); await driver.enterText(pincode); await sleep(100); - await createDerivation('Derivation 2'); + await createDerivation(); await sleep(100); await driver.tap(find.text('Fast wallet')); await driver.waitFor(find.text('Fast wallet')); diff --git a/windows/.gitignore b/windows/.gitignore new file mode 100644 index 0000000..d492d0d --- /dev/null +++ b/windows/.gitignore @@ -0,0 +1,17 @@ +flutter/ephemeral/ + +# Visual Studio user-specific files. +*.suo +*.user +*.userosscache +*.sln.docstates + +# Visual Studio build-related files. +x64/ +x86/ + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ diff --git a/windows/CMakeLists.txt b/windows/CMakeLists.txt new file mode 100644 index 0000000..5d61367 --- /dev/null +++ b/windows/CMakeLists.txt @@ -0,0 +1,95 @@ +cmake_minimum_required(VERSION 3.15) +project(gecko LANGUAGES CXX) + +set(BINARY_NAME "gecko") + +cmake_policy(SET CMP0063 NEW) + +set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") + +# Configure build options. +get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) +if(IS_MULTICONFIG) + set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" + CACHE STRING "" FORCE) +else() + if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + set(CMAKE_BUILD_TYPE "Debug" CACHE + STRING "Flutter build mode" FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Profile" "Release") + endif() +endif() + +set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") +set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") +set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") +set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") + +# Use Unicode for all projects. +add_definitions(-DUNICODE -D_UNICODE) + +# Compilation settings that should be applied to most targets. +function(APPLY_STANDARD_SETTINGS TARGET) + target_compile_features(${TARGET} PUBLIC cxx_std_17) + target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") + target_compile_options(${TARGET} PRIVATE /EHsc) + target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") + target_compile_definitions(${TARGET} PRIVATE "$<$:_DEBUG>") +endfunction() + +set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") + +# Flutter library and tool build rules. +add_subdirectory(${FLUTTER_MANAGED_DIR}) + +# Application build +add_subdirectory("runner") + +# Generated plugin build rules, which manage building the plugins and adding +# them to the application. +include(flutter/generated_plugins.cmake) + + +# === Installation === +# Support files are copied into place next to the executable, so that it can +# run in place. This is done instead of making a separate bundle (as on Linux) +# so that building and running from within Visual Studio will work. +set(BUILD_BUNDLE_DIR "$") +# Make the "install" step default, as it's required to run. +set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) +endif() + +set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") +set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") + +install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + COMPONENT Runtime) + +install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) + +if(PLUGIN_BUNDLED_LIBRARIES) + install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" + DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" + COMPONENT Runtime) +endif() + +# Fully re-copy the assets directory on each build to avoid having stale files +# from a previous install. +set(FLUTTER_ASSET_DIR_NAME "flutter_assets") +install(CODE " + file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") + " COMPONENT Runtime) +install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" + DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) + +# Install the AOT library on non-Debug builds only. +install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" + CONFIGURATIONS Profile;Release + COMPONENT Runtime) diff --git a/windows/flutter/CMakeLists.txt b/windows/flutter/CMakeLists.txt new file mode 100644 index 0000000..b02c548 --- /dev/null +++ b/windows/flutter/CMakeLists.txt @@ -0,0 +1,103 @@ +cmake_minimum_required(VERSION 3.15) + +set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") + +# Configuration provided via flutter tool. +include(${EPHEMERAL_DIR}/generated_config.cmake) + +# TODO: Move the rest of this into files in ephemeral. See +# https://github.com/flutter/flutter/issues/57146. +set(WRAPPER_ROOT "${EPHEMERAL_DIR}/cpp_client_wrapper") + +# === Flutter Library === +set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/flutter_windows.dll") + +# Published to parent scope for install step. +set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) +set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) +set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) +set(AOT_LIBRARY "${PROJECT_DIR}/build/windows/app.so" PARENT_SCOPE) + +list(APPEND FLUTTER_LIBRARY_HEADERS + "flutter_export.h" + "flutter_windows.h" + "flutter_messenger.h" + "flutter_plugin_registrar.h" + "flutter_texture_registrar.h" +) +list(TRANSFORM FLUTTER_LIBRARY_HEADERS PREPEND "${EPHEMERAL_DIR}/") +add_library(flutter INTERFACE) +target_include_directories(flutter INTERFACE + "${EPHEMERAL_DIR}" +) +target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}.lib") +add_dependencies(flutter flutter_assemble) + +# === Wrapper === +list(APPEND CPP_WRAPPER_SOURCES_CORE + "core_implementations.cc" + "standard_codec.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_CORE PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_PLUGIN + "plugin_registrar.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_PLUGIN PREPEND "${WRAPPER_ROOT}/") +list(APPEND CPP_WRAPPER_SOURCES_APP + "flutter_engine.cc" + "flutter_view_controller.cc" +) +list(TRANSFORM CPP_WRAPPER_SOURCES_APP PREPEND "${WRAPPER_ROOT}/") + +# Wrapper sources needed for a plugin. +add_library(flutter_wrapper_plugin STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} +) +apply_standard_settings(flutter_wrapper_plugin) +set_target_properties(flutter_wrapper_plugin PROPERTIES + POSITION_INDEPENDENT_CODE ON) +set_target_properties(flutter_wrapper_plugin PROPERTIES + CXX_VISIBILITY_PRESET hidden) +target_link_libraries(flutter_wrapper_plugin PUBLIC flutter) +target_include_directories(flutter_wrapper_plugin PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_plugin flutter_assemble) + +# Wrapper sources needed for the runner. +add_library(flutter_wrapper_app STATIC + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_APP} +) +apply_standard_settings(flutter_wrapper_app) +target_link_libraries(flutter_wrapper_app PUBLIC flutter) +target_include_directories(flutter_wrapper_app PUBLIC + "${WRAPPER_ROOT}/include" +) +add_dependencies(flutter_wrapper_app flutter_assemble) + +# === Flutter tool backend === +# _phony_ is a non-existent file to force this command to run every time, +# since currently there's no way to get a full input/output list from the +# flutter tool. +set(PHONY_OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/_phony_") +set_source_files_properties("${PHONY_OUTPUT}" PROPERTIES SYMBOLIC TRUE) +add_custom_command( + OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} + ${PHONY_OUTPUT} + COMMAND ${CMAKE_COMMAND} -E env + ${FLUTTER_TOOL_ENVIRONMENT} + "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.bat" + windows-x64 $ + VERBATIM +) +add_custom_target(flutter_assemble DEPENDS + "${FLUTTER_LIBRARY}" + ${FLUTTER_LIBRARY_HEADERS} + ${CPP_WRAPPER_SOURCES_CORE} + ${CPP_WRAPPER_SOURCES_PLUGIN} + ${CPP_WRAPPER_SOURCES_APP} +) diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc new file mode 100644 index 0000000..25cb188 --- /dev/null +++ b/windows/flutter/generated_plugin_registrant.cc @@ -0,0 +1,20 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#include "generated_plugin_registrant.h" + +#include +#include +#include + +void RegisterPlugins(flutter::PluginRegistry* registry) { + ConnectivityPlusWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin")); + PrintingPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("PrintingPlugin")); + SentryFlutterPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("SentryFlutterPlugin")); +} diff --git a/windows/flutter/generated_plugin_registrant.h b/windows/flutter/generated_plugin_registrant.h new file mode 100644 index 0000000..dc139d8 --- /dev/null +++ b/windows/flutter/generated_plugin_registrant.h @@ -0,0 +1,15 @@ +// +// Generated file. Do not edit. +// + +// clang-format off + +#ifndef GENERATED_PLUGIN_REGISTRANT_ +#define GENERATED_PLUGIN_REGISTRANT_ + +#include + +// Registers Flutter plugins. +void RegisterPlugins(flutter::PluginRegistry* registry); + +#endif // GENERATED_PLUGIN_REGISTRANT_ diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake new file mode 100644 index 0000000..fcd7a40 --- /dev/null +++ b/windows/flutter/generated_plugins.cmake @@ -0,0 +1,18 @@ +# +# Generated file, do not edit. +# + +list(APPEND FLUTTER_PLUGIN_LIST + connectivity_plus_windows + printing + sentry_flutter +) + +set(PLUGIN_BUNDLED_LIBRARIES) + +foreach(plugin ${FLUTTER_PLUGIN_LIST}) + add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) + target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) + list(APPEND PLUGIN_BUNDLED_LIBRARIES $) + list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) +endforeach(plugin) diff --git a/windows/runner/CMakeLists.txt b/windows/runner/CMakeLists.txt new file mode 100644 index 0000000..0b899a0 --- /dev/null +++ b/windows/runner/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.15) +project(runner LANGUAGES CXX) + +add_executable(${BINARY_NAME} WIN32 + "flutter_window.cpp" + "main.cpp" + "utils.cpp" + "win32_window.cpp" + "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" + "Runner.rc" + "runner.exe.manifest" +) +apply_standard_settings(${BINARY_NAME}) +target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") +target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) +target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") +add_dependencies(${BINARY_NAME} flutter_assemble) diff --git a/windows/runner/Runner.rc b/windows/runner/Runner.rc new file mode 100644 index 0000000..ed275d2 --- /dev/null +++ b/windows/runner/Runner.rc @@ -0,0 +1,121 @@ +// Microsoft Visual C++ generated resource script. +// +#pragma code_page(65001) +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "winres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""winres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_APP_ICON ICON "resources\\app_icon.ico" + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +#ifdef FLUTTER_BUILD_NUMBER +#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER +#else +#define VERSION_AS_NUMBER 1,0,0 +#endif + +#ifdef FLUTTER_BUILD_NAME +#define VERSION_AS_STRING #FLUTTER_BUILD_NAME +#else +#define VERSION_AS_STRING "1.0.0" +#endif + +VS_VERSION_INFO VERSIONINFO + FILEVERSION VERSION_AS_NUMBER + PRODUCTVERSION VERSION_AS_NUMBER + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK +#ifdef _DEBUG + FILEFLAGS VS_FF_DEBUG +#else + FILEFLAGS 0x0L +#endif + FILEOS VOS__WINDOWS32 + FILETYPE VFT_APP + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904e4" + BEGIN + VALUE "CompanyName", "com.example" "\0" + VALUE "FileDescription", "A new Flutter project." "\0" + VALUE "FileVersion", VERSION_AS_STRING "\0" + VALUE "InternalName", "gecko" "\0" + VALUE "LegalCopyright", "Copyright (C) 2021 com.example. All rights reserved." "\0" + VALUE "OriginalFilename", "gecko.exe" "\0" + VALUE "ProductName", "gecko" "\0" + VALUE "ProductVersion", VERSION_AS_STRING "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1252 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED diff --git a/windows/runner/flutter_window.cpp b/windows/runner/flutter_window.cpp new file mode 100644 index 0000000..b43b909 --- /dev/null +++ b/windows/runner/flutter_window.cpp @@ -0,0 +1,61 @@ +#include "flutter_window.h" + +#include + +#include "flutter/generated_plugin_registrant.h" + +FlutterWindow::FlutterWindow(const flutter::DartProject& project) + : project_(project) {} + +FlutterWindow::~FlutterWindow() {} + +bool FlutterWindow::OnCreate() { + if (!Win32Window::OnCreate()) { + return false; + } + + RECT frame = GetClientArea(); + + // The size here must match the window dimensions to avoid unnecessary surface + // creation / destruction in the startup path. + flutter_controller_ = std::make_unique( + frame.right - frame.left, frame.bottom - frame.top, project_); + // Ensure that basic setup of the controller was successful. + if (!flutter_controller_->engine() || !flutter_controller_->view()) { + return false; + } + RegisterPlugins(flutter_controller_->engine()); + SetChildContent(flutter_controller_->view()->GetNativeWindow()); + return true; +} + +void FlutterWindow::OnDestroy() { + if (flutter_controller_) { + flutter_controller_ = nullptr; + } + + Win32Window::OnDestroy(); +} + +LRESULT +FlutterWindow::MessageHandler(HWND hwnd, UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + // Give Flutter, including plugins, an opportunity to handle window messages. + if (flutter_controller_) { + std::optional result = + flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, + lparam); + if (result) { + return *result; + } + } + + switch (message) { + case WM_FONTCHANGE: + flutter_controller_->engine()->ReloadSystemFonts(); + break; + } + + return Win32Window::MessageHandler(hwnd, message, wparam, lparam); +} diff --git a/windows/runner/flutter_window.h b/windows/runner/flutter_window.h new file mode 100644 index 0000000..6da0652 --- /dev/null +++ b/windows/runner/flutter_window.h @@ -0,0 +1,33 @@ +#ifndef RUNNER_FLUTTER_WINDOW_H_ +#define RUNNER_FLUTTER_WINDOW_H_ + +#include +#include + +#include + +#include "win32_window.h" + +// A window that does nothing but host a Flutter view. +class FlutterWindow : public Win32Window { + public: + // Creates a new FlutterWindow hosting a Flutter view running |project|. + explicit FlutterWindow(const flutter::DartProject& project); + virtual ~FlutterWindow(); + + protected: + // Win32Window: + bool OnCreate() override; + void OnDestroy() override; + LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, + LPARAM const lparam) noexcept override; + + private: + // The project to run. + flutter::DartProject project_; + + // The Flutter instance hosted by this window. + std::unique_ptr flutter_controller_; +}; + +#endif // RUNNER_FLUTTER_WINDOW_H_ diff --git a/windows/runner/main.cpp b/windows/runner/main.cpp new file mode 100644 index 0000000..aa55141 --- /dev/null +++ b/windows/runner/main.cpp @@ -0,0 +1,43 @@ +#include +#include +#include + +#include "flutter_window.h" +#include "utils.h" + +int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, + _In_ wchar_t *command_line, _In_ int show_command) { + // Attach to console when present (e.g., 'flutter run') or create a + // new console when running with a debugger. + if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { + CreateAndAttachConsole(); + } + + // Initialize COM, so that it is available for use in the library and/or + // plugins. + ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); + + flutter::DartProject project(L"data"); + + std::vector command_line_arguments = + GetCommandLineArguments(); + + project.set_dart_entrypoint_arguments(std::move(command_line_arguments)); + + FlutterWindow window(project); + Win32Window::Point origin(10, 10); + Win32Window::Size size(1280, 720); + if (!window.CreateAndShow(L"gecko", origin, size)) { + return EXIT_FAILURE; + } + window.SetQuitOnClose(true); + + ::MSG msg; + while (::GetMessage(&msg, nullptr, 0, 0)) { + ::TranslateMessage(&msg); + ::DispatchMessage(&msg); + } + + ::CoUninitialize(); + return EXIT_SUCCESS; +} diff --git a/windows/runner/resource.h b/windows/runner/resource.h new file mode 100644 index 0000000..66a65d1 --- /dev/null +++ b/windows/runner/resource.h @@ -0,0 +1,16 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by Runner.rc +// +#define IDI_APP_ICON 101 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 102 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/windows/runner/resources/app_icon.ico b/windows/runner/resources/app_icon.ico new file mode 100644 index 0000000..c04e20c Binary files /dev/null and b/windows/runner/resources/app_icon.ico differ diff --git a/windows/runner/runner.exe.manifest b/windows/runner/runner.exe.manifest new file mode 100644 index 0000000..c977c4a --- /dev/null +++ b/windows/runner/runner.exe.manifest @@ -0,0 +1,20 @@ + + + + + PerMonitorV2 + + + + + + + + + + + + + + + diff --git a/windows/runner/utils.cpp b/windows/runner/utils.cpp new file mode 100644 index 0000000..d19bdbb --- /dev/null +++ b/windows/runner/utils.cpp @@ -0,0 +1,64 @@ +#include "utils.h" + +#include +#include +#include +#include + +#include + +void CreateAndAttachConsole() { + if (::AllocConsole()) { + FILE *unused; + if (freopen_s(&unused, "CONOUT$", "w", stdout)) { + _dup2(_fileno(stdout), 1); + } + if (freopen_s(&unused, "CONOUT$", "w", stderr)) { + _dup2(_fileno(stdout), 2); + } + std::ios::sync_with_stdio(); + FlutterDesktopResyncOutputStreams(); + } +} + +std::vector GetCommandLineArguments() { + // Convert the UTF-16 command line arguments to UTF-8 for the Engine to use. + int argc; + wchar_t** argv = ::CommandLineToArgvW(::GetCommandLineW(), &argc); + if (argv == nullptr) { + return std::vector(); + } + + std::vector command_line_arguments; + + // Skip the first argument as it's the binary name. + for (int i = 1; i < argc; i++) { + command_line_arguments.push_back(Utf8FromUtf16(argv[i])); + } + + ::LocalFree(argv); + + return command_line_arguments; +} + +std::string Utf8FromUtf16(const wchar_t* utf16_string) { + if (utf16_string == nullptr) { + return std::string(); + } + int target_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, nullptr, 0, nullptr, nullptr); + if (target_length == 0) { + return std::string(); + } + std::string utf8_string; + utf8_string.resize(target_length); + int converted_length = ::WideCharToMultiByte( + CP_UTF8, WC_ERR_INVALID_CHARS, utf16_string, + -1, utf8_string.data(), + target_length, nullptr, nullptr); + if (converted_length == 0) { + return std::string(); + } + return utf8_string; +} diff --git a/windows/runner/utils.h b/windows/runner/utils.h new file mode 100644 index 0000000..3879d54 --- /dev/null +++ b/windows/runner/utils.h @@ -0,0 +1,19 @@ +#ifndef RUNNER_UTILS_H_ +#define RUNNER_UTILS_H_ + +#include +#include + +// Creates a console for the process, and redirects stdout and stderr to +// it for both the runner and the Flutter library. +void CreateAndAttachConsole(); + +// Takes a null-terminated wchar_t* encoded in UTF-16 and returns a std::string +// encoded in UTF-8. Returns an empty std::string on failure. +std::string Utf8FromUtf16(const wchar_t* utf16_string); + +// Gets the command line arguments passed in as a std::vector, +// encoded in UTF-8. Returns an empty std::vector on failure. +std::vector GetCommandLineArguments(); + +#endif // RUNNER_UTILS_H_ diff --git a/windows/runner/win32_window.cpp b/windows/runner/win32_window.cpp new file mode 100644 index 0000000..c10f08d --- /dev/null +++ b/windows/runner/win32_window.cpp @@ -0,0 +1,245 @@ +#include "win32_window.h" + +#include + +#include "resource.h" + +namespace { + +constexpr const wchar_t kWindowClassName[] = L"FLUTTER_RUNNER_WIN32_WINDOW"; + +// The number of Win32Window objects that currently exist. +static int g_active_window_count = 0; + +using EnableNonClientDpiScaling = BOOL __stdcall(HWND hwnd); + +// Scale helper to convert logical scaler values to physical using passed in +// scale factor +int Scale(int source, double scale_factor) { + return static_cast(source * scale_factor); +} + +// Dynamically loads the |EnableNonClientDpiScaling| from the User32 module. +// This API is only needed for PerMonitor V1 awareness mode. +void EnableFullDpiSupportIfAvailable(HWND hwnd) { + HMODULE user32_module = LoadLibraryA("User32.dll"); + if (!user32_module) { + return; + } + auto enable_non_client_dpi_scaling = + reinterpret_cast( + GetProcAddress(user32_module, "EnableNonClientDpiScaling")); + if (enable_non_client_dpi_scaling != nullptr) { + enable_non_client_dpi_scaling(hwnd); + FreeLibrary(user32_module); + } +} + +} // namespace + +// Manages the Win32Window's window class registration. +class WindowClassRegistrar { + public: + ~WindowClassRegistrar() = default; + + // Returns the singleton registar instance. + static WindowClassRegistrar* GetInstance() { + if (!instance_) { + instance_ = new WindowClassRegistrar(); + } + return instance_; + } + + // Returns the name of the window class, registering the class if it hasn't + // previously been registered. + const wchar_t* GetWindowClass(); + + // Unregisters the window class. Should only be called if there are no + // instances of the window. + void UnregisterWindowClass(); + + private: + WindowClassRegistrar() = default; + + static WindowClassRegistrar* instance_; + + bool class_registered_ = false; +}; + +WindowClassRegistrar* WindowClassRegistrar::instance_ = nullptr; + +const wchar_t* WindowClassRegistrar::GetWindowClass() { + if (!class_registered_) { + WNDCLASS window_class{}; + window_class.hCursor = LoadCursor(nullptr, IDC_ARROW); + window_class.lpszClassName = kWindowClassName; + window_class.style = CS_HREDRAW | CS_VREDRAW; + window_class.cbClsExtra = 0; + window_class.cbWndExtra = 0; + window_class.hInstance = GetModuleHandle(nullptr); + window_class.hIcon = + LoadIcon(window_class.hInstance, MAKEINTRESOURCE(IDI_APP_ICON)); + window_class.hbrBackground = 0; + window_class.lpszMenuName = nullptr; + window_class.lpfnWndProc = Win32Window::WndProc; + RegisterClass(&window_class); + class_registered_ = true; + } + return kWindowClassName; +} + +void WindowClassRegistrar::UnregisterWindowClass() { + UnregisterClass(kWindowClassName, nullptr); + class_registered_ = false; +} + +Win32Window::Win32Window() { + ++g_active_window_count; +} + +Win32Window::~Win32Window() { + --g_active_window_count; + Destroy(); +} + +bool Win32Window::CreateAndShow(const std::wstring& title, + const Point& origin, + const Size& size) { + Destroy(); + + const wchar_t* window_class = + WindowClassRegistrar::GetInstance()->GetWindowClass(); + + const POINT target_point = {static_cast(origin.x), + static_cast(origin.y)}; + HMONITOR monitor = MonitorFromPoint(target_point, MONITOR_DEFAULTTONEAREST); + UINT dpi = FlutterDesktopGetDpiForMonitor(monitor); + double scale_factor = dpi / 96.0; + + HWND window = CreateWindow( + window_class, title.c_str(), WS_OVERLAPPEDWINDOW | WS_VISIBLE, + Scale(origin.x, scale_factor), Scale(origin.y, scale_factor), + Scale(size.width, scale_factor), Scale(size.height, scale_factor), + nullptr, nullptr, GetModuleHandle(nullptr), this); + + if (!window) { + return false; + } + + return OnCreate(); +} + +// static +LRESULT CALLBACK Win32Window::WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + if (message == WM_NCCREATE) { + auto window_struct = reinterpret_cast(lparam); + SetWindowLongPtr(window, GWLP_USERDATA, + reinterpret_cast(window_struct->lpCreateParams)); + + auto that = static_cast(window_struct->lpCreateParams); + EnableFullDpiSupportIfAvailable(window); + that->window_handle_ = window; + } else if (Win32Window* that = GetThisFromHandle(window)) { + return that->MessageHandler(window, message, wparam, lparam); + } + + return DefWindowProc(window, message, wparam, lparam); +} + +LRESULT +Win32Window::MessageHandler(HWND hwnd, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept { + switch (message) { + case WM_DESTROY: + window_handle_ = nullptr; + Destroy(); + if (quit_on_close_) { + PostQuitMessage(0); + } + return 0; + + case WM_DPICHANGED: { + auto newRectSize = reinterpret_cast(lparam); + LONG newWidth = newRectSize->right - newRectSize->left; + LONG newHeight = newRectSize->bottom - newRectSize->top; + + SetWindowPos(hwnd, nullptr, newRectSize->left, newRectSize->top, newWidth, + newHeight, SWP_NOZORDER | SWP_NOACTIVATE); + + return 0; + } + case WM_SIZE: { + RECT rect = GetClientArea(); + if (child_content_ != nullptr) { + // Size and position the child window. + MoveWindow(child_content_, rect.left, rect.top, rect.right - rect.left, + rect.bottom - rect.top, TRUE); + } + return 0; + } + + case WM_ACTIVATE: + if (child_content_ != nullptr) { + SetFocus(child_content_); + } + return 0; + } + + return DefWindowProc(window_handle_, message, wparam, lparam); +} + +void Win32Window::Destroy() { + OnDestroy(); + + if (window_handle_) { + DestroyWindow(window_handle_); + window_handle_ = nullptr; + } + if (g_active_window_count == 0) { + WindowClassRegistrar::GetInstance()->UnregisterWindowClass(); + } +} + +Win32Window* Win32Window::GetThisFromHandle(HWND const window) noexcept { + return reinterpret_cast( + GetWindowLongPtr(window, GWLP_USERDATA)); +} + +void Win32Window::SetChildContent(HWND content) { + child_content_ = content; + SetParent(content, window_handle_); + RECT frame = GetClientArea(); + + MoveWindow(content, frame.left, frame.top, frame.right - frame.left, + frame.bottom - frame.top, true); + + SetFocus(child_content_); +} + +RECT Win32Window::GetClientArea() { + RECT frame; + GetClientRect(window_handle_, &frame); + return frame; +} + +HWND Win32Window::GetHandle() { + return window_handle_; +} + +void Win32Window::SetQuitOnClose(bool quit_on_close) { + quit_on_close_ = quit_on_close; +} + +bool Win32Window::OnCreate() { + // No-op; provided for subclasses. + return true; +} + +void Win32Window::OnDestroy() { + // No-op; provided for subclasses. +} diff --git a/windows/runner/win32_window.h b/windows/runner/win32_window.h new file mode 100644 index 0000000..17ba431 --- /dev/null +++ b/windows/runner/win32_window.h @@ -0,0 +1,98 @@ +#ifndef RUNNER_WIN32_WINDOW_H_ +#define RUNNER_WIN32_WINDOW_H_ + +#include + +#include +#include +#include + +// A class abstraction for a high DPI-aware Win32 Window. Intended to be +// inherited from by classes that wish to specialize with custom +// rendering and input handling +class Win32Window { + public: + struct Point { + unsigned int x; + unsigned int y; + Point(unsigned int x, unsigned int y) : x(x), y(y) {} + }; + + struct Size { + unsigned int width; + unsigned int height; + Size(unsigned int width, unsigned int height) + : width(width), height(height) {} + }; + + Win32Window(); + virtual ~Win32Window(); + + // Creates and shows a win32 window with |title| and position and size using + // |origin| and |size|. New windows are created on the default monitor. Window + // sizes are specified to the OS in physical pixels, hence to ensure a + // consistent size to will treat the width height passed in to this function + // as logical pixels and scale to appropriate for the default monitor. Returns + // true if the window was created successfully. + bool CreateAndShow(const std::wstring& title, + const Point& origin, + const Size& size); + + // Release OS resources associated with window. + void Destroy(); + + // Inserts |content| into the window tree. + void SetChildContent(HWND content); + + // Returns the backing Window handle to enable clients to set icon and other + // window properties. Returns nullptr if the window has been destroyed. + HWND GetHandle(); + + // If true, closing this window will quit the application. + void SetQuitOnClose(bool quit_on_close); + + // Return a RECT representing the bounds of the current client area. + RECT GetClientArea(); + + protected: + // Processes and route salient window messages for mouse handling, + // size change and DPI. Delegates handling of these to member overloads that + // inheriting classes can handle. + virtual LRESULT MessageHandler(HWND window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Called when CreateAndShow is called, allowing subclass window-related + // setup. Subclasses should return false if setup fails. + virtual bool OnCreate(); + + // Called when Destroy is called. + virtual void OnDestroy(); + + private: + friend class WindowClassRegistrar; + + // OS callback called by message pump. Handles the WM_NCCREATE message which + // is passed when the non-client area is being created and enables automatic + // non-client DPI scaling so that the non-client area automatically + // responsponds to changes in DPI. All other messages are handled by + // MessageHandler. + static LRESULT CALLBACK WndProc(HWND const window, + UINT const message, + WPARAM const wparam, + LPARAM const lparam) noexcept; + + // Retrieves a class instance pointer for |window| + static Win32Window* GetThisFromHandle(HWND const window) noexcept; + + bool quit_on_close_ = false; + + // window handle for top level window. + HWND window_handle_ = nullptr; + + // window handle for hosted content. + HWND child_content_ = nullptr; +}; + +#endif // RUNNER_WIN32_WINDOW_H_