mirror of https://github.com/flutter/samples.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.2 KiB
84 lines
2.2 KiB
5 years ago
|
// Copyright 2019 The Flutter team. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style license that can be
|
||
|
// found in the LICENSE file.
|
||
|
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:provider/provider.dart';
|
||
|
import 'package:provider_shopper/models/cart.dart';
|
||
|
|
||
|
class MyCart extends StatelessWidget {
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
return Scaffold(
|
||
|
appBar: AppBar(
|
||
|
title: Text('Cart', style: Theme.of(context).textTheme.display4),
|
||
|
backgroundColor: Colors.white,
|
||
|
),
|
||
|
body: Container(
|
||
|
color: Colors.yellow,
|
||
|
child: Column(
|
||
|
children: [
|
||
|
Expanded(
|
||
|
child: Padding(
|
||
|
padding: const EdgeInsets.all(32),
|
||
|
child: _CartList(),
|
||
|
),
|
||
|
),
|
||
|
Divider(height: 4, color: Colors.black),
|
||
|
_CartTotal()
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class _CartList extends StatelessWidget {
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
var itemNameStyle = Theme.of(context).textTheme.title;
|
||
|
var cart = Provider.of<CartModel>(context);
|
||
|
|
||
|
return ListView.builder(
|
||
|
itemCount: cart.items.length,
|
||
|
itemBuilder: (context, index) => ListTile(
|
||
|
leading: Icon(Icons.done),
|
||
|
title: Text(
|
||
|
cart.items[index].name,
|
||
|
style: itemNameStyle,
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class _CartTotal extends StatelessWidget {
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
var hugeStyle = Theme.of(context).textTheme.display4.copyWith(fontSize: 48);
|
||
|
|
||
|
return SizedBox(
|
||
|
height: 200,
|
||
|
child: Center(
|
||
|
child: Row(
|
||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||
|
children: [
|
||
|
Consumer<CartModel>(
|
||
|
builder: (context, cart, child) =>
|
||
|
Text('\$${cart.totalPrice}', style: hugeStyle)),
|
||
|
SizedBox(width: 24),
|
||
|
FlatButton(
|
||
|
onPressed: () {
|
||
|
Scaffold.of(context).showSnackBar(
|
||
|
SnackBar(content: Text('Buying not supported yet.')));
|
||
|
},
|
||
|
color: Colors.white,
|
||
|
child: Text('BUY'),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|