body: Body(),
);
}
AppBar buildAppBar() {
return AppBar(
backgroundColor: Colors.white,
elevation: 0,
leading: IconButton(
icon: SvgPicture.asset("assets/icons/back.svg"),
onPressed: () {},
),
actions: [
IconButton(
icon: SvgPicture.asset(
"assets/icons/search.svg",
// By default our icon color is white
color: kTextColor,
),
onPressed: () {},
),
IconButton(
icon: SvgPicture.asset(
"assets/icons/cart.svg",
// By default our icon color is white
color: kTextColor,
),
onPressed: () {},
),
SizedBox(width: kDefaultPaddin / 2)
],
);
}}
2-sahifa:
import 'package:flutter/material.dart';
import 'package:shop_app/constants.dart';
import 'package:shop_app/models/Product.dart';
import 'package:shop_app/screens/details/details_screen.dart';
import 'categorries.dart';
import 'item_card.dart';
class Body extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: kDefaultPaddin),
child: Text(
"Women",
style: Theme.of(context)
.textTheme
.headline5
.copyWith(fontWeight: FontWeight.bold),
),
),
Categories(),
Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: kDefaultPaddin),
child: GridView.builder(
itemCount: products.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
mainAxisSpacing: kDefaultPaddin,
crossAxisSpacing: kDefaultPaddin,
childAspectRatio: 0.75,
),
itemBuilder: (context, index) => ItemCard(
product: products[index],
press: () => Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailsScreen(
product: products[index],
),
)),
)),
),
),
],
);
}
}
3-sahifa:
import 'package:flutter/material.dart';
import '../../../constants.dart';
// We need satefull widget for our categories
class Categories extends StatefulWidget {
@override
_CategoriesState createState() => _CategoriesState();
}
class _CategoriesState extends State {
List categories = ["Hand bag", "Jewellery", "Footwear", "Dresses"];
// By default our first item will be selected
int selectedIndex = 0;
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: kDefaultPaddin),
child: SizedBox(
height: 25,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: categories.length,
itemBuilder: (context, index) => buildCategory(index),
),
),
);
}
Widget buildCategory(int index) {
return GestureDetector(
onTap: () {
setState(() {
selectedIndex = index;
});
},
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: kDefaultPaddin),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
categories[index],
style: TextStyle(
fontWeight: FontWeight.bold,
color: selectedIndex == index ? kTextColor : kTextLightColor,
),
),
Container(
margin: EdgeInsets.only(top: kDefaultPaddin / 4), //top padding 5
height: 2,
width: 30,
color: selectedIndex == index ? Colors.black : Colors.transparent,
)
],
), ),);}}
Dastur ko’rinishi:
Do'stlaringiz bilan baham: |