Add discounts page
This commit is contained in:
parent
cd5989beb5
commit
d74ed5bcfa
3 changed files with 101 additions and 16 deletions
|
@ -4,8 +4,8 @@ import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:nekoya_app/data/auth.dart';
|
import 'package:nekoya_app/data/auth.dart';
|
||||||
import 'package:nekoya_app/screens/products.dart';
|
import 'package:nekoya_app/screens/products.dart';
|
||||||
|
import 'package:nekoya_app/screens/discounts.dart';
|
||||||
import 'package:nekoya_app/screens/cart.dart';
|
import 'package:nekoya_app/screens/cart.dart';
|
||||||
import 'package:nekoya_app/screens/sessions.dart';
|
|
||||||
import 'package:nekoya_app/screens/transactions.dart';
|
import 'package:nekoya_app/screens/transactions.dart';
|
||||||
import 'package:nekoya_app/screens/home.dart';
|
import 'package:nekoya_app/screens/home.dart';
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ class _MenuState extends State<Menu> {
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
if (widget.initialScreen == 0) {
|
if (widget.initialScreen == 0) {
|
||||||
_selectedWidget = const Sessions();
|
_selectedWidget = const Discounts();
|
||||||
} else if (widget.initialScreen == 1) {
|
} else if (widget.initialScreen == 1) {
|
||||||
_selectedWidget = const Products();
|
_selectedWidget = const Products();
|
||||||
} else if (widget.initialScreen == 2) {
|
} else if (widget.initialScreen == 2) {
|
||||||
|
@ -45,7 +45,7 @@ class _MenuState extends State<Menu> {
|
||||||
body: _selectedWidget,
|
body: _selectedWidget,
|
||||||
bottomNavigationBar: Navigation(
|
bottomNavigationBar: Navigation(
|
||||||
itemIcons: const [
|
itemIcons: const [
|
||||||
Icons.settings,
|
Icons.percent,
|
||||||
Icons.list_alt_rounded,
|
Icons.list_alt_rounded,
|
||||||
Icons.shopping_cart,
|
Icons.shopping_cart,
|
||||||
Icons.wysiwyg
|
Icons.wysiwyg
|
||||||
|
@ -62,15 +62,8 @@ class _MenuState extends State<Menu> {
|
||||||
var oldSelectedIndex = _selectedIndex;
|
var oldSelectedIndex = _selectedIndex;
|
||||||
_selectedIndex = index;
|
_selectedIndex = index;
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
_selectedWidget = const Sessions();
|
html.window.history.pushState(null, '', '/#/discount');
|
||||||
checkSessionExist().then((isLoggedIn) {
|
_selectedWidget = const Discounts();
|
||||||
if (!isLoggedIn) {
|
|
||||||
_selectedIndex = oldSelectedIndex;
|
|
||||||
Navigator.of(context).pushReplacement(MaterialPageRoute(
|
|
||||||
builder: (context) => const Menu(initialScreen: 2)));
|
|
||||||
Navigator.pushNamed(context, '/login');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (index == 1) {
|
} else if (index == 1) {
|
||||||
html.window.history.pushState(null, '', '/#/products');
|
html.window.history.pushState(null, '', '/#/products');
|
||||||
_selectedWidget = const Products();
|
_selectedWidget = const Products();
|
||||||
|
|
|
@ -62,13 +62,12 @@ class _NekoyaState extends State<Nekoya> {
|
||||||
'/products': (context) => const Menu(
|
'/products': (context) => const Menu(
|
||||||
initialScreen: 1,
|
initialScreen: 1,
|
||||||
),
|
),
|
||||||
|
'/discount': (context) => const Menu(
|
||||||
|
initialScreen: 0,
|
||||||
|
),
|
||||||
'/cart': (context) => const Menu(
|
'/cart': (context) => const Menu(
|
||||||
initialScreen: 3,
|
initialScreen: 3,
|
||||||
),
|
),
|
||||||
'/sessions': (context) => const NavigationAuth(
|
|
||||||
route: Menu(
|
|
||||||
initialScreen: 0,
|
|
||||||
)),
|
|
||||||
'/transactions': (context) => const NavigationAuth(
|
'/transactions': (context) => const NavigationAuth(
|
||||||
route: Menu(
|
route: Menu(
|
||||||
initialScreen: 4,
|
initialScreen: 4,
|
||||||
|
|
93
lib/screens/discounts.dart
Normal file
93
lib/screens/discounts.dart
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:nekoya_app/api/api.dart';
|
||||||
|
import 'package:nekoya_app/components/product_box.dart';
|
||||||
|
import 'package:nekoya_app/components/product_detail.dart';
|
||||||
|
import 'package:nekoya_app/utils/utils.dart'
|
||||||
|
show kMobileBreakpoint, kTabletBreakpoint, kDesktopBreakPoint;
|
||||||
|
|
||||||
|
class Discounts extends StatefulWidget {
|
||||||
|
const Discounts({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<Discounts> createState() => _DiscountsState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DiscountsState extends State<Discounts> {
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: const Color(0xff1b1c1e),
|
||||||
|
appBar: AppBar(
|
||||||
|
title: const Text('Discounts'),
|
||||||
|
centerTitle: true,
|
||||||
|
backgroundColor: const Color(0xff212226),
|
||||||
|
automaticallyImplyLeading: false,
|
||||||
|
),
|
||||||
|
body: LayoutBuilder(builder: (context, dimension) {
|
||||||
|
int gridCount = 2;
|
||||||
|
double fontSize = 14.0;
|
||||||
|
|
||||||
|
if (dimension.maxWidth <= kMobileBreakpoint) {
|
||||||
|
gridCount = 2;
|
||||||
|
fontSize = 14.0;
|
||||||
|
} else if (dimension.maxWidth > kMobileBreakpoint &&
|
||||||
|
dimension.maxWidth <= kTabletBreakpoint) {
|
||||||
|
gridCount = 4;
|
||||||
|
fontSize = 15.0;
|
||||||
|
} else if (dimension.maxWidth > kTabletBreakpoint &&
|
||||||
|
dimension.maxWidth <= kDesktopBreakPoint) {
|
||||||
|
gridCount = 5;
|
||||||
|
fontSize = 10.0;
|
||||||
|
} else {
|
||||||
|
gridCount = 6;
|
||||||
|
fontSize = 10.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return FutureBuilder<dynamic>(
|
||||||
|
future: getProducts(),
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasData) {
|
||||||
|
List<dynamic> data = snapshot.data;
|
||||||
|
|
||||||
|
List<dynamic> currentData = [];
|
||||||
|
for (var product in data) {
|
||||||
|
if (product['DISCOUNT'] != 0) {
|
||||||
|
currentData.add(product);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return GridView.count(
|
||||||
|
crossAxisCount: gridCount,
|
||||||
|
children: List.generate(currentData.length, (index) {
|
||||||
|
return ProductBox(
|
||||||
|
imageUrl:
|
||||||
|
"https://nekoya.moe.team/img/${currentData[index]['IMAGE']}",
|
||||||
|
title: currentData[index]['TITLE'],
|
||||||
|
discount: currentData[index]['DISCOUNT'],
|
||||||
|
fontSize: fontSize,
|
||||||
|
callback: () {
|
||||||
|
showModalBottomSheet(
|
||||||
|
isScrollControlled: true,
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
context: context,
|
||||||
|
builder: (context) =>
|
||||||
|
productDetail(context, currentData[index]['ID']),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return const Center(
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
color: Color(0xff8B0000),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue