記事一覧
URL以前の文字列を抽出する方法
方法 ①正規表現で抽出 void main() { final text = 'これはYouTubeのリンクです。https://www.youtube.com/'; final exp = RegExp(r'.*(http\S+)'); final match = e…
文字列の中からURLを抽出する方法
コード void main() { final text = 'Youtubeのリンクはhttps://www.youtube.com/です。'; // 正規表現 final regExp = RegExp( r'((https?:www\.)|(https?://)|(…
多言語対応・文字列リソースの定義と利用方法
①Flutterアプリ内では、文字列リソースは直打ちせず共通のファイルに定義した上で利用する
②多言語対応も可能になる
1. 多言語用のライブラリのインストール
// pubspec.yamldependencies: flutter: sdk: flutter flutter_localizations: # 多言語ライブラリの本体 sdk: flutter intl
FlutterFlowマーケットプレイス / FlutterFlow日本語ドキュメント
数秒でアプリに新機能を追加できます!
FlutterFlowマーケットプレイスには、FlutterFlowプロジェクトに直接追加できるコンポーネントやテンプレートがあります。これらのアイテムを使えば、現在FlutterFlowでは利用できない、または簡単に構築できない機能を追加することができます。
このセクションでは下記の内容を説明します。
・マーケットプレイスアイテムをプロジェクトに追加する
半角カナを全角カナに変換・全角英数字を半角英数字に変換
DartPad
コード
void main() { final samples = [ 'テスト', //全角カナ 'テスト', //半角カナ 'テスト', //全角カナ「テ」 + 半角カナ「スト」 'TEST1', //全角英数字 ]; for (final sample in samples) { final convertedText = conver
freezed(Dataクラス)のLiveテンプレートを追加する方法
Preferences > Editor > Live Templates > Flutter
画面右上の+ボタンをクリックし、
1. Live Templateをクリック
ショートカット用のAbbreviation(名前)とDescription(説明)を記入
Template textにテンプレートを入力
import 'package:freezed_annotation/freez
HookConsumerWidgetのLiveテンプレートを追加する方法(VSCode編)
「Cmd + Shift + P」から
「Preferences: Configure User Snippets」>「dart.json (Dart)」を呼び出す
初期は以下の感じ
snippet generatorにてスニペットを作成
登録したスニペット
→ 「$1」にはクラス名が入る
class $1 extends HookConsumerWidget { const $1({s
「2023-12-22 21:43:20」と表示する方法
コード
import 'package:intl/intl.dart';void main() { final time = DateTime.parse('2023-12-22 21:43:20.585096'); final result = DateFormat('yyyy-MM-dd HH:mm:ss').format(time); print('result: $result')
TextFormFieldのonChangedにクラス引数としてメソッドを渡す方法
コード
class _TextForm extends StatelessWidget { const _TextForm({ required this.textEditingController, required this.onChanged, }); final TextEditingController textEditingController; final vo
HookConsumerWidgetのLiveテンプレートを追加する方法
Android Studio編
Preferences > Editor > Live Templates > Flutter
画面右上の+ボタンをクリックし、
1. Live Templateをクリック
ショートカット用のAbbreviation(名前)とDescription(説明)を記入
Template textにテンプレートを入力
class _$NAME$ extends
テキストキーボードを自動で立ち上げる方法
ポイント
TextFormFieldにautofocus: trueを追加
TextFormField( autofocus: true, //👈ここ),
利用シーン
検索ボックスをクリックして、検索画面に遷移する際に
自動でテキストキーボードを立ち上げる
URL以前の文字列を抽出する方法
方法
①正規表現で抽出
void main() { final text = 'これはYouTubeのリンクです。https://www.youtube.com/'; final exp = RegExp(r'.*(http\S+)'); final match = exp.firstMatch(text); final beforeUrl = match?.group(0)?.rep
文字列の中からURLを抽出する方法
コード
void main() { final text = 'Youtubeのリンクはhttps://www.youtube.com/です。'; // 正規表現 final regExp = RegExp( r'((https?:www\.)|(https?://)|(www\.))[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9]{1,6}(/