我对这段代码有疑问:
return SubscriptionTile(subscription: subscriptions[index].toString());
------------------------完整代码(subscription_list.dart)---------------- --------
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xhub/screens/subscription/subscription_tile.dart';
class SubscriptionList extends StatefulWidget {
@override
_SubscriptionListState createState() => _SubscriptionListState();
}
class _SubscriptionListState extends State<SubscriptionList> {
@override
Widget build(BuildContext context) {
final subscriptions = Provider.of<List<SubscriptionList>>(context);
return ListView.builder(
itemCount: subscriptions.length,
itemBuilder: (context, index) {
return SubscriptionTile(subscription: subscriptions[index].toString());
},
);
}
}
------------------------完整代码(subscription_tile.dart)---------------- --------
import 'package:flutter/material.dart';
import 'package:xhub/models/user.dart';
class SubscriptionTile extends StatelessWidget {
final SubscriptionsList subscription;
SubscriptionTile({this.subscription});
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(top: 8.0),
child: Card(
margin: EdgeInsets.fromLTRB(20.0, 6.0, 20.0, 0.0),
child: ListTile(
leading: CircleAvatar(
radius: 25.0,
backgroundColor: Colors.grey,
),
title: Text(subscription.domain),
subtitle: Text('Renew Date: ${subscription.renew}'),
isThreeLine: true,
),
),
);
}
}
------------------------完整代码(user.dart)---------------- --------
class SubscriptionsList {
final String domain;
final String type;
final String plan;
final String renew;
final String backup;
final String ssl;
final String ns1;
final String ns2;
final String cplink;
final String cpuser;
final String cppass;
final String serveruser;
final String serverpass;
SubscriptionsList(
{this.domain,
this.type,
this.plan,
this.renew,
this.backup,
this.ssl,
this.ns1,
this.ns2,
this.cplink,
this.cpuser,
this.cppass,
this.serveruser,
this.serverpass});
}
------------------------错误--------------------- ---
The argument type 'SubscriptionList' can't be assigned to the parameter type 'SubscriptionsList'.
答案 0 :(得分:0)
您定义了两个SubscriptionList类。因此,您的代码必须是一种,但是要导入另一种。重命名两者之一。例如,为SubscriptionList小部件命名为SubscriptionListWidget。