在使用 qr_flutter 包时,我收到错误“参数类型‘QrImage’无法分配给参数类型‘Widget?’。”对于 QrImage()
import 'package:flutter/material.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:qr_flutter/qr_flutter.dart';
class ProfileScreen extends StatelessWidget {
final String userId;
const ProfileScreen({Key? key, required this.userId}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Your Profile'),
actions: [
IconButton(
icon: const Icon(Icons.logout),
onPressed: () async {
try {
await FirebaseAuth.instance.signOut();
Navigator.of(context).pushReplacementNamed('/login');
} catch (e) {
print('Logout failed: $e');
// Handle logout failure
}
},
),
],
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(
child: QrImage(
data: userId, // Use the provided user ID to generate a unique QR code
version: QrVersions.auto,
size: 200.0,
),
),
const SizedBox(height: 20),
// Additional user information widgets can be added here
// For example, you can fetch and display the user's name, email, etc.
],
),
),
);
}
}
我有flutter版本“Flutter 3.16.2”。并且依赖项也添加到pubspec.yaml文件中。
我已将频道更改为 Beta(之后又恢复为稳定版) flutter 升级到最新版本 添加了适当的依赖项 尝试重新打开 vscode
QRImageView
小部件。
Center(
child: QrImageView(
data: userId, // Use the provided user ID to generate a unique QR code
version: QrVersions.auto,
size: 200.0,
),
),