I am unable to assign my one class to another even though I have imported the lib for them. I am following a course . In this I will fetch the orders from firebase and showing the orderscreen.
Orderscreen(where i am getting the error):
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/orders.dart' show Orders;
import '../Widgets/OrderItem.dart';
import '../widgets/app_drawer.dart';
import 'package:shop_app/Widgets/OrderItem.dart';
class OrdersScreen extends StatelessWidget {
static const routeName = '/orders';
@override
Widget build(BuildContext context) {
print('building orders');
return Scaffold(
appBar: AppBar(
title: Text('Your Orders'),
),
drawer: AppDrawer(),
body: FutureBuilder(
future: Provider.of<Orders>(context, listen: false).fetchandSetOrders(),
builder: (ctx, dataSnapshot) {
if (dataSnapshot.connectionState == ConnectionState.waiting) {
return Center(child: CircularProgressIndicator());
} else {
if (dataSnapshot.error != null) {
return Center(
child: Text('An error occurred!'),
);
} else {
return Consumer<Orders>(
builder: (ctx, orderData, child) => ListView.builder(
itemCount: orderData.orders.length,
itemBuilder: (ctx, i) =>
OrderItemview(orderData.orders[i])),
);
}
}
},
),
);
}
}
My orderitem class :
class OrderItemview extends StatefulWidget {
final ord.OrderItems order;
OrderItemview(this.order);
@override
State<OrderItemview> createState() => _OrderItemState();
}
class _OrderItemState extends State<OrderItemview> {
var _expanded = false;
@override
Widget build(BuildContext context) {
return Card(
margin: EdgeInsets.all(10),
child: Column(
children: [
ListTile(
title: Text('\$${widget.order.amount}'),
subtitle: Text(
DateFormat('dd/MM/yyyy/ hh:mm').format(widget.order.dateTime),
),
trailing: IconButton(
icon: Icon(_expanded
? Icons.expand_less_rounded
: Icons.expand_more_rounded),
onPressed: () {
setState(() {
_expanded = !_expanded;
});
},
)),
if (_expanded)
Container(
height: min(widget.order.products.length * 20.0 + 100, 180),
child: ListView(
children: widget.order.products
.map((prod) => Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(prod.title),
Text('${prod.quanitity}x \$${prod.price}')
],
))
.toList()
,
),
),
],
),
);
}
}
My orders class:
class OrderItems {
final String id;
final double amount;
final List<CartItem> products;
final DateTime dateTime;
OrderItems(this.id, this.amount, this.products, this.dateTime);
}
class Orders with ChangeNotifier {
List<OrderItems> _orders = [];
List<OrderItems> get orders {
return [..._orders];
}
Thanks guys for all your help. it would be helpful if you can explain why i got this error as I am a novice to flutter
What I have tried:
I changed the class and widget name as before both with orderitem to avoid confusion but that has changed the error