FlutterのWidget内で
if (isHoge) ..._bar(), if (isHoge) ..._fuga(),
って同じ条件並べてるのきもい。
if (isHoge) ...[ ...bar(), ...fuga(), ],
がシンプルだ!
FlutterのWidget内で
if (isHoge) ..._bar(), if (isHoge) ..._fuga(),
って同じ条件並べてるのきもい。
if (isHoge) ...[ ...bar(), ...fuga(), ],
がシンプルだ!
Intelli Jでのパスを確認する。
gradle.properties
にはGradleバージョン
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
gradle/wrapper/gradle-wrapper.properties
には
/usr/libexec/java_home -v 11
の結果を
org.gradle.java.home=/Users/shinriyo/Library/Java/JavaVirtualMachines/corretto-11.0.24/Contents/Home
flutter packages pub publish
でのエラー。
以下のエラー
Then click "Allow access". Waiting for your authorization... Authorization received, processing... Successfully authorized. Uploading... Failed to scan tar archive. (Entry "example/ios/Runner.xcodeproj/project.pbxproj" has no default mode bits (644).) pub finished with exit code 1
example/ios
に行こう。
$ ls -l total 16 drwxr-xr-x 8 shinriyo staff 256 Aug 9 07:50 Flutter -rw-r--r--@ 1 shinriyo staff 1347 Aug 9 08:07 Podfile -rw-r--r--@ 1 shinriyo staff 771 Aug 9 08:25 Podfile.lock drwxr-xr-x@ 7 shinriyo staff 224 Aug 9 08:25 Pods drwxr-xr-x 9 shinriyo staff 288 Aug 9 07:45 Runner drwxr-xr-x@ 5 shinriyo staff 160 Aug 9 08:25 Runner.xcodeproj drwxr-xr-x@ 5 shinriyo staff 160 Aug 9 07:52 Runner.xcworkspace drwxr-xr-x 3 shinriyo staff 96 Aug 9 07:40 RunnerTests
以下実行
chmod 777 Runner.xcodeproj
$ ls -l total 16 drwxr-xr-x 8 shinriyo staff 256 Aug 9 07:50 Flutter -rw-r--r--@ 1 shinriyo staff 1347 Aug 9 08:07 Podfile -rw-r--r--@ 1 shinriyo staff 771 Aug 9 08:25 Podfile.lock drwxr-xr-x@ 7 shinriyo staff 224 Aug 9 08:25 Pods drwxr-xr-x 9 shinriyo staff 288 Aug 9 07:45 Runner drw-r--r--@ 5 shinriyo staff 160 Aug 9 08:25 Runner.xcodeproj drwxr-xr-x@ 5 shinriyo staff 160 Aug 9 07:52 Runner.xcworkspace drwxr-xr-x 3 shinriyo staff 96 Aug 9 07:40 RunnerTests
しかし重要なのはさらに中の project.pbxproj
だった。
sudo chmod 644 Runner.xcodeproj/project.pbxproj
SharedPreferencesの型ごとにやるの面倒くさいからこれで型を意識しなくていいような?
prefs_manager.dart
class PrefsManager { final SharedPreferences _prefs; PrefsManager(this._prefs); Future<void> save<T>(String key, T value) async { if (value is String) { await _prefs.setString(key, value); } else if (value is int) { await _prefs.setInt(key, value); } else if (value is bool) { await _prefs.setBool(key, value); } else if (value is double) { await _prefs.setDouble(key, value); } else { throw ArgumentError('Unsupported type'); } } T? load<T>(String key) { if (T == String) { return _prefs.getString(key) as T?; } else if (T == int) { return _prefs.getInt(key) as T?; } else if (T == bool) { return _prefs.getBool(key) as T?; } else if (T == double) { return _prefs.getDouble(key) as T?; } else { throw ArgumentError('Unsupported type'); } } }
windows/runner/keyboard_mode.cpp
#include <windows.h> #include <iostream> extern "C" __declspec(dllexport) void SetKeyboardToEnglish() { // Load the English (United States) keyboard layout HKL hkl = LoadKeyboardLayout(TEXT("00000409"), KLF_ACTIVATE); // English (United States) layout if (hkl == NULL) { std::cerr << "Failed to load keyboard layout" << std::endl; return; } // Activate the layout if (!ActivateKeyboardLayout(hkl, KLF_SETFORPROCESS)) { std::cerr << "Failed to activate keyboard layout" << std::endl; } } extern "C" __declspec(dllexport) void SetKeyboardToHalfWidthAlphanumeric() { // Load the Japanese keyboard layout with half-width alphanumeric mode HKL hkl = LoadKeyboardLayout(TEXT("00000411"), KLF_ACTIVATE); // Japanese IME if (hkl == NULL) { std::cerr << "Failed to load keyboard layout" << std::endl; return; } // Activate the layout if (!ActivateKeyboardLayout(hkl, KLF_SETFORPROCESS)) { std::cerr << "Failed to activate keyboard layout" << std::endl; return; } // Simulate the Alt + 半角/全角 key press to switch to half-width alphanumeric INPUT inputs[4] = {}; // Press Alt inputs[0].type = INPUT_KEYBOARD; inputs[0].ki.wVk = VK_MENU; // Press 半角/全角 (VK_KANA) inputs[1].type = INPUT_KEYBOARD; inputs[1].ki.wVk = VK_KANA; // Release 半角/全角 (VK_KANA) inputs[2].type = INPUT_KEYBOARD; inputs[2].ki.wVk = VK_KANA; inputs[2].ki.dwFlags = KEYEVENTF_KEYUP; // Release Alt inputs[3].type = INPUT_KEYBOARD; inputs[3].ki.wVk = VK_MENU; inputs[3].ki.dwFlags = KEYEVENTF_KEYUP; // Send the key events if (SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT)) == 0) { std::cerr << "Failed to send input" << std::endl; } }
KeyboardMode
クラス
import 'dart:ffi'; import 'dart:io'; typedef SetKeyboardToEnglishFunc = Void Function(); typedef SetKeyboardToHalfWidthAlphanumericFunc = Void Function(); class KeyboardMode { final DynamicLibrary _nativeLib; KeyboardMode() : _nativeLib = Platform.isWindows ? DynamicLibrary.open('keyboard_mode.dll') : throw UnsupportedError('This platform is not supported') { _setKeyboardToEnglish = _nativeLib .lookup<NativeFunction<SetKeyboardToEnglishFunc>>('SetKeyboardToEnglish') .asFunction(); _setKeyboardToHalfWidthAlphanumeric = _nativeLib .lookup<NativeFunction<SetKeyboardToHalfWidthAlphanumericFunc>>('SetKeyboardToHalfWidthAlphanumeric') .asFunction(); } late final void Function() _setKeyboardToEnglish; late final void Function() _setKeyboardToHalfWidthAlphanumeric; void setKeyboardToEnglish() => _setKeyboardToEnglish(); void setKeyboardToHalfWidthAlphanumeric() => _setKeyboardToHalfWidthAlphanumeric(); }
windows/runner/CMakeLists.txt
"win32_window.cpp" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" "Runner.rc" "runner.exe.manifest" ) # ここを追加 # Define the DLL set(PLUGIN_NAME "keyboard_mode") add_library(${PLUGIN_NAME} SHARED "keyboard_mode.cpp") # Define the libraries to link to. #target_link_libraries(runner PRIVATE flutter keyboard_hook) apply_standard_settings(${PLUGIN_NAME}) # Apply the standard set of build settings. This can be removed for applications # that need different build settings. apply_standard_settings(${BINARY_NAME}) # ここまで