105 lines
3.9 KiB
Dart
105 lines
3.9 KiB
Dart
import 'package:birzha/core/adaptix/adaptix.dart';
|
|
import 'package:birzha/models/categories/products/pure.dart';
|
|
import 'package:birzha/screens/productsScreen.dart';
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class CategoryBuilder extends StatefulWidget {
|
|
const CategoryBuilder({Key? key, required this.category}) : super(key: key);
|
|
|
|
final ProductsPureCategory category;
|
|
|
|
@override
|
|
_CategoryBuilderState createState() => _CategoryBuilderState();
|
|
}
|
|
|
|
class _CategoryBuilderState extends State<CategoryBuilder> {
|
|
bool _isPressed = false;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnimatedContainer(
|
|
duration: Duration(milliseconds: 300),
|
|
curve: Curves.ease,
|
|
padding: EdgeInsets.all(_isPressed ? 8.adaptedPx() : 0),
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) => PhysicalModel(
|
|
color: Theme.of(context).accentColor.withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(constraints.biggest.height * 0.04),
|
|
child: Material(
|
|
color: Colors.transparent,
|
|
child: InkWell(
|
|
onTap: () {
|
|
setState(() {
|
|
_isPressed = false;
|
|
});
|
|
Navigator.of(context, rootNavigator: false)
|
|
.push(MaterialPageRoute(builder: (_) => ProductsScreen(route: 'category', category: widget.category.toRemote())));
|
|
},
|
|
borderRadius: BorderRadius.circular(constraints.biggest.height * 0.04),
|
|
onTapCancel: () {
|
|
setState(() {
|
|
_isPressed = false;
|
|
});
|
|
},
|
|
onTapDown: (details) {
|
|
setState(() {
|
|
_isPressed = true;
|
|
});
|
|
},
|
|
child: Align(
|
|
alignment: Alignment.center,
|
|
child: Flex(
|
|
direction: Axis.vertical,
|
|
children: [
|
|
Spacer(
|
|
flex: 3,
|
|
),
|
|
Expanded(
|
|
flex: 12,
|
|
child: ConstrainedBox(
|
|
constraints: BoxConstraints.expand(),
|
|
child: FittedBox(
|
|
child: CachedNetworkImage(
|
|
imageUrl: widget.category.icon,
|
|
placeholder: (_, __) {
|
|
return Icon(
|
|
Icons.category,
|
|
color: Theme.of(context).iconTheme.color?.withOpacity(0.5),
|
|
);
|
|
},
|
|
errorWidget: (_, __, ___) {
|
|
return Icon(
|
|
Icons.category,
|
|
color: Theme.of(context).iconTheme.color?.withOpacity(0.5),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Spacer(flex: 2),
|
|
Expanded(
|
|
flex: 6,
|
|
child: Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: constraints.biggest.width * 0.1),
|
|
child: Text(widget.category.name,
|
|
textScaleFactor: 1,
|
|
maxLines: 2,
|
|
textAlign: TextAlign.center,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: Theme.of(context).textTheme.headline2?.copyWith(fontSize: constraints.biggest.height * 0.074, height: 1.6)),
|
|
),
|
|
),
|
|
Spacer(flex: 3)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|