@miyajima0630

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

[flutter]qr_flutterについてわかる方助けてください

解決したいこと

このエラーを解決してビルドしたい

例)
flutterでアプリを作っているのですが
前任から引きついたアプリをAPIレベルを34から36に引き上げ
flutterのバージョンも最新にしました。
そうしたところ下記のようなエラーが出ました。
解決しようといろいろ試してみましたが解決できません。
chatGPTにも考えてもらい、バージョンを落とした書き方で書いても見ましたが駄目なようです。
キャッシュの可能性も考慮し、flutter clean →flutter pub getも行いましたしdel pubspec.lockも行いました。
わかる方や思い当たることがある方はご教授願います。
ほしい情報などございましたら塚で記入させていただきます。
よろしくお願いいたします。

発生している問題・エラー

PS C:\Users\miyajima\StudioProjects\app> flutter run --flavor dev
Launching lib\main.dart on sdk gphone64 x86 64 in debug mode...
lib/UI/data_transfer.dart:46:30: Error: Too few positional arguments: 1 required, 0 given.
                      QrImage(
                             ^
../../AppData/Local/Pub/Cache/hosted/pub.dev/qr-3.0.2/lib/src/qr_image.dart:17:11: Context: Found this candidate, but the arguments don't match.
  factory QrImage(QrCode qrCode) {
          ^
lib/UI/data_transfer.dart:44:32: Error: Too many positional arguments: 0 allowed, but 3 found.
Try removing the extra positional arguments.
                  return Column(
                               ^
../../flutter/packages/flutter/lib/src/widgets/basic.dart:5850:9: Context: Found this candidate, but the arguments don't match.
  const Column({
        ^^^^^^
Target kernel_snapshot_program failed: Exception


FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileFlutterBuildDevDebug'.
> Process 'command 'C:\Users\miyajima\flutter\bin\flutter.bat'' finished with non-zero exit value 1

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.

BUILD FAILED in 10s
Running Gradle task 'assembleDevDebug'...                          10.8s
Error: Gradle task assembleDevDebug failed with exit code 1

↓↓↓↓↓↓↓下記が対象と思われるソースコードです。↓↓↓↓↓(data_transfer.dart)

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:qr_flutter/qr_flutter.dart';

import '../bloc.dart';
import '../entity.dart';
import '../properties.dart';

class DataTransfer extends StatelessWidget {
  const DataTransfer({super.key});
  @override
  Widget build(BuildContext context) {
    final bloc = Provider.of<Bloc>(context, listen: false);

    return WillPopScope(
      onWillPop: () async{
        ScaffoldMessenger.of(context).removeCurrentSnackBar();
        return true;
      },
      child: Scaffold(
        backgroundColor: const Color(0xfff4f0ed),
        appBar: AppBar(
          iconTheme: const IconThemeData(color:Color(primaryColor)),
          backgroundColor: Colors.transparent,
          elevation: 0,
          title: const Text('引き継ぎコード発行',
              style: TextStyle(color: Color(primaryColor), fontSize: 16),),
          centerTitle: true,
        ),
        body: Container(
          padding: const EdgeInsets.all(15),
          alignment: Alignment.center,
          child: Column(
            children: [
              Selector<Bloc, TransferData>(
                selector: (context, bloc) => bloc.transferData,
                builder:  (context, data, child) {
                  if(data.transferCode == null || data.transferCode == ''){
                    return const Icon(Icons.qr_code_rounded,
                      size: 200, color: Colors.grey,);
                  }
                  final transferCode = data.transferCode.toString();
                  return Column(
                    children: [
                      QrImage(
                        data: transferCode,
                        version: QrVersions.auto,
                        size: 200,
                      ),
                      const Align(
                        alignment: Alignment.centerLeft,
                        child: Text('引き継ぎコード'),),
                      DecoratedBox(
                        decoration: BoxDecoration(
                          border: Border.all(
                            color: const Color(primaryColor).withOpacity(0.2),),
                          borderRadius: BorderRadius.circular(10),
                        ),
                        child: Row(
                          children: [
                            Expanded(
                              child: Center(
                                child: Text(transferCode,
                                  style: const TextStyle(
                                    fontSize: 16,
                                    color: Colors.black54,
                                  ),
                                ),
                              ),
                            ),
                            SizedBox(
                              width: 35,
                              child: IconButton(
                                padding: EdgeInsets.zero,
                                icon: const Icon(Icons.content_copy_rounded,
                                    color: Color(primaryColor),),
                                tooltip: 'コピー',
                                onPressed: () async {
                                  final data = ClipboardData(
                                      text: transferCode,);
                                  await Clipboard.setData(data).then((value){
                                    ScaffoldMessenger.of(context).showSnackBar(
                                      const SnackBar(
                                        behavior: SnackBarBehavior.floating,
                                        backgroundColor: Colors.black45,
                                        margin: EdgeInsets.all(20),
                                        duration: Duration(seconds: 1),
                                        elevation: 0,
                                        content: Text(
                                            'クリップボードにコピーしました。',),),
                                    );
                                  });
                                },),
                            )
                          ],
                        ),
                      ),
                      Text('有効期限:${dtFormatter.format(data.timeLimit!)}',
                        style: const TextStyle(
                          fontSize: 13,
                          color: Colors.black45,
                        ),
                      )
                    ],
                  );
                },
              ),
              Padding(
                padding: const EdgeInsets.only(top:15),
                child: ElevatedButton(
                  onPressed: () async {
                    var alertResult = true;
                    if(bloc.transferData.transferCode != ''){
                      alertResult = await showDialog<bool>(
                        context: context,
                        barrierDismissible: false,
                        builder: (BuildContext context) {
                          const message = '現在の引き継ぎコードは無効になります。'
                              'よろしいですか?';
                          return AlertDialog(
                            content: const Text(message,
                              style: TextStyle(fontSize: 15),),
                            actions: <Widget>[
                              TextButton(
                                onPressed: () {
                                  Navigator.of(context).pop(true);
                                },
                                child: const Text('はい'),
                              ),
                              TextButton(
                                onPressed: () {
                                  Navigator.of(context).pop(false);
                                },
                                child: const Text('いいえ'),
                              ),
                            ],
                          );
                        },
                      ) ?? false;
                    }
                    if(alertResult) {
                      await bloc.getDataTransferToken(
                          newToken: true, context: context,);
                    }
                  },
                  child: const Text('引き継ぎコードを発行する'),
              ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

環境

pubspec.yaml

environment:
  sdk: ">=2.19.0 <4.0.0"

dependencies:
  badges: ^3.1.2
  cupertino_icons: ^1.0.2
  dotted_line: ^3.0.0
  expandable_text: ^2.3.0
  firebase_analytics: ^12.0.1
  firebase_core: ^4.1.0
  firebase_crashlytics: ^5.0.0
  firebase_messaging: ^16.0.1
  firebase_remote_config: ^6.0.1
  flip_card: ^0.7.0
  flutter:
    sdk: flutter
  flutter_keyboard_visibility: ^6.0.0
  flutter_local_notifications: ^19.4.2
  flutter_localizations:
    sdk: flutter
  flutter_share_me: ^1.4.0
  flutter_spinkit: ^5.0.0
  flutter_svg: ^2.2.1
  future_progress_dialog: ^0.2.0
  geolocator: ^14.0.2
  get_it: ^8.2.0
  google_fonts: ^6.3.1
  google_maps_flutter: ^2.1.0
  http: ^1.5.0
  intl:
  just_audio: ^0.10.5
  nfc_manager: ^4.0.2
  package_info_plus: ^8.3.1
  perfect_volume_control: ^1.0.4
  provider: ^6.0.2
  qr_code_scanner: ^1.0.0
  qr_flutter: ^4.1.0 ←ここ
  rive: ^0.13.20
  rxdart: ^0.28.0
  share_plus: ^12.0.0
  shared_preferences: ^2.0.5
  simple_animations: ^5.0.0+2
  smooth_page_indicator: ^1.0.0+2
  supercharged: ^2.1.1
  tutorial_coach_mark: ^1.0.0
  url_launcher: ^6.0.3
  webview_flutter: ^4.13.0
  webview_flutter_android: ^4.10.2
  flutter_plugin_android_lifecycle: ^2.0.30

 flutter --version  
Flutter 3.35.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision d693b4b9db (3 days ago) • 2025-09-16 14:27:41 +0000
Engine • hash feee8ee8fb8b975dd9990f86d3bda11e6e75faf3 (revision c298091351) (3 days ago) • 2025-09-15 14:04:24.000Z
Tools • Dart 3.9.2 • DevTools 2.48.0

android studioの方ではこのようなエラーになっています。

 QrImage(
    data: transferCode,
    version: QrVersions.auto,
    size: 200,
),
The element type 'QrImage' can't be assigned to the list type 'Widget'. (Documentation) 
The named parameter 'data' isn't defined. (Documentation)  Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'data'.
1 positional argument expected by 'QrImage. new', but 0 found. (Documentation)  Try adding the missing argument.
0 likes

1Answer

解決しました。

 QrImageView(
                        data: transferCode,
                        version: QrVersions.auto,
                        size: 200,
                      ),

QrImage→QrImageViewにしないといけなかったようです。

1Like

Your answer might help someone💌