スポンサーリンク

生成された実際のコード紹介

Gemini CLI 生成コード

実際の Google CLI のプロンプト実行以降の出力は以下のとおりです。

1. メインページ(text_edit_page.dart)
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:animated_text_kit/animated_text_kit.dart';

import '../provider/text_edit_provider.dart';

class TextEditPage extends HookConsumerWidget {
  const TextEditPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final textController = useTextEditingController();
    final textEditState = ref.watch(textEditProvider);
    final textEditNotifier = ref.read(textEditProvider.notifier);

    final textStyles = [
      const TextStyle(fontSize: 30, fontWeight: FontWeight.bold, color: Colors.blue),
      const TextStyle(fontSize: 24, fontStyle: FontStyle.italic, color: Colors.red),
      const TextStyle(fontSize: 28, decoration: TextDecoration.underline, color: Colors.green),
      const TextStyle(fontSize: 26, letterSpacing: 2.0, color: Colors.purple),
    ];

    return Scaffold(
      appBar: AppBar(
        title: const Text('Text Edit'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            TextField(
              controller: textController,
              decoration: const InputDecoration(
                border: OutlineInputBorder(),
                labelText: 'Enter Text',
              ),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                textEditNotifier.setText(textController.text);
              },
              child: const Text('Show Rich Text'),
            ),
            const SizedBox(height: 20),
            if (textEditState.text.isNotEmpty)
              GestureDetector(
                onTap: () {
                  Clipboard.setData(ClipboardData(text: textEditState.text));
                  EasyLoading.showToast('Copied to Clipboard');
                },
                child: AnimatedTextKit(
                  animatedTexts: [
                    WavyAnimatedText(
                      textEditState.text,
                      textStyle: textStyles[textEditState.styleIndex],
                    ),
                  ],
                  isRepeatingAnimation: false,
                ),
              ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                textEditNotifier.changeStyle();
              },
              child: const Text('Change Style'),
            ),
          ],
        ),
      ),
    );
  }
}
2. 状態管理(text_edit_state_notifier.dart)
import 'dart:math';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

part 'text_edit_state_notifier.freezed.dart';

@freezed
class TextEditState with _$TextEditState {
  const factory TextEditState({
    @Default('') String text,
    @Default(0) int styleIndex,
  }) = _TextEditState;
}

class TextEditStateNotifier extends StateNotifier<TextEditState> {
  TextEditStateNotifier() : super(const TextEditState());

  final _random = Random();

  void setText(String text) {
    state = state.copyWith(text: text, styleIndex: _random.nextInt(4));
  }

  void changeStyle() {
    state = state.copyWith(styleIndex: _random.nextInt(4));
  }
}
3. Provider定義(text_edit_provider.dart)
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'text_edit_state_notifier.dart';

final textEditProvider = StateNotifierProvider<TextEditStateNotifier, TextEditState>(
  (ref) => TextEditStateNotifier(),
);

Claude Code 生成コード

Claude Codeは text_edit_page.dart の一つのファイルに、providerやstate_notifierがまとめられてしまっていました。

1. メインページ(text_edit_page.dart)
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

part 'text_edit_page.freezed.dart';

@freezed
class TextEditPageState with _$TextEditPageState {
  const factory TextEditPageState({
    @Default('') String inputText,
    @Default('') String displayText,
    @Default(Colors.black) Color textColor,
    @Default(16.0) double fontSize,
    @Default(FontWeight.normal) FontWeight fontWeight,
    @Default(false) bool isItalic,
    @Default(false) bool isUnderline,
  }) = _TextEditPageState;
}

class TextEditPageStateNotifier extends StateNotifier<TextEditPageState> {
  TextEditPageStateNotifier() : super(const TextEditPageState());

  void setInputText(String text) {
    state = state.copyWith(inputText: text);
  }

  void updateDisplayText() {
    if (state.inputText.isEmpty) return;
    
    final random = Random();
    final colors = [
      Colors.red,
      Colors.blue,
      Colors.green,
      Colors.purple,
      Colors.orange,
      Colors.pink,
      Colors.teal,
      Colors.indigo,
      Colors.amber,
      Colors.deepOrange,
    ];

    final fontSizes = [14.0, 16.0, 18.0, 20.0, 24.0, 28.0];
    final fontWeights = [FontWeight.normal, FontWeight.bold, FontWeight.w300, FontWeight.w600];

    state = state.copyWith(
      displayText: state.inputText,
      textColor: colors[random.nextInt(colors.length)],
      fontSize: fontSizes[random.nextInt(fontSizes.length)],
      fontWeight: fontWeights[random.nextInt(fontWeights.length)],
      isItalic: random.nextBool(),
      isUnderline: random.nextBool(),
    );
  }

  void copyToClipboard() {
    if (state.displayText.isEmpty) return;
    
    Clipboard.setData(ClipboardData(text: state.displayText));
    EasyLoading.showToast('テキストをコピーしました');
  }
}

final textEditPageProvider = StateNotifierProvider.autoDispose<TextEditPageStateNotifier, TextEditPageState>(
  (ref) => TextEditPageStateNotifier(),
);

class TextEditPage extends HookConsumerWidget {
  const TextEditPage({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final state = ref.watch(textEditPageProvider);
    final notifier = ref.watch(textEditPageProvider.notifier);
    final textController = useTextEditingController();

    return Scaffold(
      appBar: AppBar(
        title: const Text('テキストエディット'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            TextField(
              controller: textController,
              decoration: const InputDecoration(
                hintText: 'テキストを入力してください',
                border: OutlineInputBorder(),
              ),
              maxLines: 3,
              onChanged: (text) {
                notifier.setInputText(text);
              },
            ),
            const SizedBox(height: 16),
            ElevatedButton(
              onPressed: state.inputText.isNotEmpty
                  ? () {
                      notifier.updateDisplayText();
                    }
                  : null,
              child: const Text('リッチテキストで表示'),
            ),
            const SizedBox(height: 32),
            if (state.displayText.isNotEmpty) ...[
              const Text(
                'タップしてコピー',
                style: TextStyle(
                  fontSize: 12,
                  color: Colors.grey,
                ),
              ),
              const SizedBox(height: 8),
              GestureDetector(
                onTap: () {
                  notifier.copyToClipboard();
                },
                child: Container(
                  padding: const EdgeInsets.all(16),
                  decoration: BoxDecoration(
                    border: Border.all(color: Colors.grey.shade300),
                    borderRadius: BorderRadius.circular(8),
                  ),
                  child: Text(
                    state.displayText,
                    style: TextStyle(
                      color: state.textColor,
                      fontSize: state.fontSize,
                      fontWeight: state.fontWeight,
                      fontStyle: state.isItalic ? FontStyle.italic : FontStyle.normal,
                      decoration: state.isUnderline ? TextDecoration.underline : TextDecoration.none,
                    ),
                  ),
                ),
              ),
            ],
          ],
        ),
      ),
    );
  }
}
Gemini CLI と Claude Code の生成コードを並べて比較

Claude Code のまとまったコードを分けたとして、それぞれ比較してみます。

1. メインページ(text_edit_page.dart)
Gemini CLI 生成コード
class TextEditPage extends HookConsumerWidget {
  const TextEditPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final textController = useTextEditingController();
    final textEditState = ref.watch(textEditProvider);
    final textEditNotifier = ref.read(textEditProvider.notifier);

    final textStyles = [
      const TextStyle(fontSize: 30, fontWeight: FontWeight.bold, color: Colors.blue),
      const TextStyle(fontSize: 24, fontStyle: FontStyle.italic, color: Colors.red),
      const TextStyle(fontSize: 28, decoration: TextDecoration.underline, color: Colors.green),
      const TextStyle(fontSize: 26, letterSpacing: 2.0, color: Colors.purple),
    ];

    return Scaffold(
      appBar: AppBar(
        title: const Text('Text Edit'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            TextField(
              controller: textController,
              decoration: const InputDecoration(
                border: OutlineInputBorder(),
                labelText: 'Enter Text',
              ),
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                textEditNotifier.setText(textController.text);
              },
              child: const Text('Show Rich Text'),
            ),
            const SizedBox(height: 20),
            if (textEditState.text.isNotEmpty)
              GestureDetector(
                onTap: () {
                  Clipboard.setData(ClipboardData(text: textEditState.text));
                  EasyLoading.showToast('Copied to Clipboard');
                },
                child: AnimatedTextKit(
                  animatedTexts: [
                    WavyAnimatedText(
                      textEditState.text,
                      textStyle: textStyles[textEditState.styleIndex],
                    ),
                  ],
                  isRepeatingAnimation: false,
                ),
              ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                textEditNotifier.changeStyle();
              },
              child: const Text('Change Style'),
            ),
          ],
        ),
      ),
    );
  }
}
Claude Code 生成コード
class TextEditPage extends HookConsumerWidget {
  const TextEditPage({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final state = ref.watch(textEditPageProvider);
    final notifier = ref.watch(textEditPageProvider.notifier);
    final textController = useTextEditingController();

    return Scaffold(
      appBar: AppBar(
        title: const Text('テキストエディット'),
      ),
      body: Padding(
        padding: const EdgeInsets.all(16.0),
        child: Column(
          children: [
            TextField(
              controller: textController,
              decoration: const InputDecoration(
                hintText: 'テキストを入力してください',
                border: OutlineInputBorder(),
              ),
              maxLines: 3,
              onChanged: (text) {
                notifier.setInputText(text);
              },
            ),
            const SizedBox(height: 16),
            ElevatedButton(
              onPressed: state.inputText.isNotEmpty
                  ? () {
                      notifier.updateDisplayText();
                    }
                  : null,
              child: const Text('リッチテキストで表示'),
            ),
            const SizedBox(height: 32),
            if (state.displayText.isNotEmpty) ...[
              const Text(
                'タップしてコピー',
                style: TextStyle(
                  fontSize: 12,
                  color: Colors.grey,
                ),
              ),
              const SizedBox(height: 8),
              GestureDetector(
                onTap: () {
                  notifier.copyToClipboard();
                },
                child: Container(
                  padding: const EdgeInsets.all(16),
                  decoration: BoxDecoration(
                    border: Border.all(color: Colors.grey.shade300),
                    borderRadius: BorderRadius.circular(8),
                  ),
                  child: Text(
                    state.displayText,
                    style: TextStyle(
                      color: state.textColor,
                      fontSize: state.fontSize,
                      fontWeight: state.fontWeight,
                      fontStyle: state.isItalic ? FontStyle.italic : FontStyle.normal,
                      decoration: state.isUnderline ? TextDecoration.underline : TextDecoration.none,
                    ),
                  ),
                ),
              ),
            ],
          ],
        ),
      ),
    );
  }
}
2. 状態管理(text_edit_state_notifier.dart)
Gemini CLI 生成コード
@freezed
class TextEditState with _$TextEditState {
  const factory TextEditState({
    @Default('') String text,
    @Default(0) int styleIndex,
  }) = _TextEditState;
}

class TextEditStateNotifier extends StateNotifier<TextEditState> {
  TextEditStateNotifier() : super(const TextEditState());

  final _random = Random();

  void setText(String text) {
    state = state.copyWith(text: text, styleIndex: _random.nextInt(4));
  }

  void changeStyle() {
    state = state.copyWith(styleIndex: _random.nextInt(4));
  }
}
Claude Code 生成コード
@freezed
class TextEditPageState with _$TextEditPageState {
  const factory TextEditPageState({
    @Default('') String inputText,
    @Default('') String displayText,
    @Default(Colors.black) Color textColor,
    @Default(16.0) double fontSize,
    @Default(FontWeight.normal) FontWeight fontWeight,
    @Default(false) bool isItalic,
    @Default(false) bool isUnderline,
  }) = _TextEditPageState;
}

class TextEditPageStateNotifier extends StateNotifier<TextEditPageState> {
  TextEditPageStateNotifier() : super(const TextEditPageState());

  void setInputText(String text) {
    state = state.copyWith(inputText: text);
  }

  void updateDisplayText() {
    if (state.inputText.isEmpty) return;
    
    final random = Random();
    final colors = [
      Colors.red,
      Colors.blue,
      Colors.green,
      Colors.purple,
      Colors.orange,
      Colors.pink,
      Colors.teal,
      Colors.indigo,
      Colors.amber,
      Colors.deepOrange,
    ];

    final fontSizes = [14.0, 16.0, 18.0, 20.0, 24.0, 28.0];
    final fontWeights = [FontWeight.normal, FontWeight.bold, FontWeight.w300, FontWeight.w600];

    state = state.copyWith(
      displayText: state.inputText,
      textColor: colors[random.nextInt(colors.length)],
      fontSize: fontSizes[random.nextInt(fontSizes.length)],
      fontWeight: fontWeights[random.nextInt(fontWeights.length)],
      isItalic: random.nextBool(),
      isUnderline: random.nextBool(),
    );
  }

  void copyToClipboard() {
    if (state.displayText.isEmpty) return;
    
    Clipboard.setData(ClipboardData(text: state.displayText));
    EasyLoading.showToast('テキストをコピーしました');
  }
}
3. Provider定義(text_edit_provider.dart)
Gemini CLI 生成コード
final textEditProvider = StateNotifierProvider<TextEditStateNotifier, TextEditState>(
  (ref) => TextEditStateNotifier(),
);
Claude Code 生成コード
final textEditPageProvider = StateNotifierProvider.autoDispose<TextEditPageStateNotifier, TextEditPageState>(
  (ref) => TextEditPageStateNotifier(),
);


楽天ブックス
¥1,760 (2026/01/09 08:23時点 | 楽天市場調べ)
スポンサーリンク

Twitterでフォローしよう

おすすめの記事