provider_state_management/lib/ui/myapp.dart
2022-08-22 19:18:37 +07:00

94 lines
3.3 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:provider_state/model/products.dart';
import 'package:provider_state/provider/card.dart';
import 'package:provider_state/ui/drawer_sidbar/sidbar_profile.dart';
import 'package:provider_state/ui/favorite_screen.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
var obj = Provider.of<CardProvider>(context);
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.lightBlue,
title: const Text("Provider"),
actions: [
InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
FavoriteScreen(favoriteList: obj.localStorage),
));
},
child: Stack(
alignment: Alignment.center,
textDirection: TextDirection.rtl,
children: [
const Icon(Icons.favorite, size: 30, color: Colors.pink),
obj.isLocal
? Positioned(
left: 0,
top: 10,
child: Container(
padding: const EdgeInsets.all(5.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.white.withOpacity(0.4)),
child: Text("${obj.localStorage.length}",
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 14)),
))
: const SizedBox.shrink(),
],
))
],
),
drawer: const SidBarProfile(),
body: ListView.separated(
itemCount: ProductModel.person.length,
separatorBuilder: (context, index) =>
const Divider(color: Colors.red, thickness: 1.0),
itemBuilder: (context, index) {
final data = ProductModel.person[index];
return InkWell(
onTap: () => obj.addCard(data),
child: Container(
alignment: Alignment.centerLeft,
padding: const EdgeInsets.all(10.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(data.id.toString()),
const SizedBox(
height: 10.0,
),
Text(data.name.toString()),
],
),
data.select
? const Icon(
Icons.done,
color: Colors.blue,
)
: const SizedBox.shrink()
],
),
),
);
},
),
);
}
}