Initial commit: Penyerahan final Source code Tugas Akhir
This commit is contained in:
236
lib/screens/home/components/appBar/home_header.dart
Normal file
236
lib/screens/home/components/appBar/home_header.dart
Normal file
@ -0,0 +1,236 @@
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:initial_folder/providers/carts_provider.dart';
|
||||
import 'package:initial_folder/providers/notification_provider.dart';
|
||||
import 'package:initial_folder/providers/user_info_provider.dart';
|
||||
import 'package:initial_folder/screens/cart/cart_page.dart';
|
||||
import 'package:initial_folder/screens/login/login_with_email/login_email_screen.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:initial_folder/widgets/custom_navigator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../../size_config.dart';
|
||||
import '../notification.dart';
|
||||
import 'icon_btn_with_counter.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/screens/splash/splash_screen_login.dart';
|
||||
|
||||
class HomeHeader extends StatefulWidget {
|
||||
const HomeHeader({
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<HomeHeader> createState() => _HomeHeaderState();
|
||||
}
|
||||
|
||||
class _HomeHeaderState extends State<HomeHeader> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
Future.delayed(Duration(seconds: 0), () async {
|
||||
await Provider.of<NotificationProvider>(context, listen: false)
|
||||
.getNotificationCount();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
UserInfoProvider userInfoProvider = Provider.of<UserInfoProvider>(context);
|
||||
FirebaseMessaging.onMessage.listen((event) async {
|
||||
if (event.notification!.body!.isNotEmpty) {
|
||||
await Provider.of<NotificationProvider>(context, listen: false)
|
||||
.getNotificationCount();
|
||||
}
|
||||
});
|
||||
|
||||
Future _showDialogNotLogin(String teks) {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
elevation: 0.0,
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(20),
|
||||
vertical: getProportionateScreenHeight(20),
|
||||
),
|
||||
content: Text(
|
||||
'Mohon login terlebih dahulu sebelum $teks',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(11)),
|
||||
),
|
||||
actions: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text('Batal',
|
||||
style: primaryTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(12),
|
||||
letterSpacing: 1,
|
||||
color: primaryColor)),
|
||||
),
|
||||
SizedBox(width: getProportionateScreenWidth(5)),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context).pushNamedAndRemoveUntil(
|
||||
LoginEmail.routeName, (Route<dynamic> route) => false);
|
||||
},
|
||||
child: Text(
|
||||
'Login',
|
||||
style: primaryTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(12),
|
||||
letterSpacing: 1,
|
||||
color: primaryColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
handleNotLoginCart() async {
|
||||
var token = await UsersInfo().getToken();
|
||||
if (token != null || Condition.loginFirebase == true) {
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
CustomNavigator(
|
||||
child: CartPage(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
String teks = 'dapat mengakses keranjang';
|
||||
return _showDialogNotLogin(teks);
|
||||
}
|
||||
}
|
||||
|
||||
handleNotLoginNotif() async {
|
||||
var token = await UsersInfo().getToken();
|
||||
if (token != null || Condition.loginFirebase == true) {
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
CustomNavigator(
|
||||
child: Notifikasi(),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
String teks = 'dapat mengakses notifikasi';
|
||||
return _showDialogNotLogin(teks);
|
||||
}
|
||||
}
|
||||
|
||||
return Container(
|
||||
height: getProportionateScreenHeight(60),
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: getProportionateScreenWidth(23)),
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
children: [
|
||||
TextSpan(
|
||||
text: 'Welcome ${userInfoProvider.fullName}\n',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(12),
|
||||
color: Theme.of(context).brightness == Brightness.dark
|
||||
? Colors.white
|
||||
: Colors.black),
|
||||
),
|
||||
TextSpan(
|
||||
text: 'Let\'s\ Explore Course',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(16),
|
||||
fontWeight: bold,
|
||||
color: Theme.of(context).brightness == Brightness.dark
|
||||
? Colors.white
|
||||
: Colors.black),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Transform.scale(
|
||||
origin: Offset(-11, 0),
|
||||
scale: getProportionateScreenHeight(0.9),
|
||||
child: Container(
|
||||
padding:
|
||||
EdgeInsets.only(right: getProportionateScreenWidth(10)),
|
||||
child: Consumer<NotificationProvider>(
|
||||
builder: (context, value, child) {
|
||||
return IconBtnWithCounter(
|
||||
icon: Theme.of(context).brightness == Brightness.dark
|
||||
? SvgPicture.asset(
|
||||
"assets/icons/notification_dark.svg")
|
||||
: SvgPicture.asset(
|
||||
"assets/icons/notification.svg"),
|
||||
numOfitem:
|
||||
(Condition.loginEmail || Condition.loginFirebase)
|
||||
? value.notificationCount
|
||||
: 0,
|
||||
press: () {
|
||||
handleNotLoginNotif();
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
!Condition.loginEmail && !Condition.loginFirebase
|
||||
? Transform.scale(
|
||||
origin: Offset(0, 0),
|
||||
scale: getProportionateScreenHeight(1),
|
||||
child: Container(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
getProportionateScreenHeight(3),
|
||||
0,
|
||||
getProportionateScreenHeight(3),
|
||||
0),
|
||||
child: IconBtnWithCounter(
|
||||
numOfitem: 0,
|
||||
icon: Theme.of(context).brightness ==
|
||||
Brightness.dark
|
||||
? SvgPicture.asset("assets/icons/cart_dark.svg")
|
||||
: SvgPicture.asset("assets/icons/cart.svg"),
|
||||
press: () => handleNotLoginCart(),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Transform.scale(
|
||||
origin: Offset(0, 0),
|
||||
scale: getProportionateScreenHeight(1),
|
||||
child: Container(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
getProportionateScreenHeight(3),
|
||||
0,
|
||||
getProportionateScreenHeight(3),
|
||||
0),
|
||||
child: Consumer<CartsProvider>(
|
||||
builder: (context, state, _) {
|
||||
return IconBtnWithCounter(
|
||||
numOfitem: state.result == null
|
||||
? 0
|
||||
: state.data.length,
|
||||
icon: Theme.of(context).brightness ==
|
||||
Brightness.dark
|
||||
? SvgPicture.asset(
|
||||
"assets/icons/cart_dark.svg")
|
||||
: SvgPicture.asset("assets/icons/cart.svg"),
|
||||
press: () => handleNotLoginCart(),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding:
|
||||
EdgeInsets.only(left: SizeConfig.blockHorizontal! * 4),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
|
||||
class IconBtnWithCounter extends StatelessWidget {
|
||||
const IconBtnWithCounter({
|
||||
Key? key,
|
||||
required this.icon,
|
||||
this.numOfitem = 0,
|
||||
required this.press,
|
||||
}) : super(key: key);
|
||||
|
||||
final Widget icon;
|
||||
final int numOfitem;
|
||||
final GestureTapCallback press;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return IconButton(
|
||||
highlightColor: Colors.transparent,
|
||||
hoverColor: Colors.transparent,
|
||||
onPressed: press,
|
||||
visualDensity: VisualDensity(horizontal: -4.0, vertical: -4.0),
|
||||
padding: EdgeInsets.zero,
|
||||
icon: Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Container(
|
||||
height: 26,
|
||||
width: 26,
|
||||
child: icon,
|
||||
),
|
||||
if (numOfitem != 0)
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: -2,
|
||||
child: Container(
|
||||
height: 14,
|
||||
width: 16,
|
||||
decoration: BoxDecoration(
|
||||
color: Color(0xffCD2228),
|
||||
shape: BoxShape.circle,
|
||||
// border: Border.all(width: 1.5, color: Colors.red),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
"$numOfitem",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 8,
|
||||
height: 1.3,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
72
lib/screens/home/components/body_comp/beginning.dart
Normal file
72
lib/screens/home/components/body_comp/beginning.dart
Normal file
@ -0,0 +1,72 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../../theme.dart';
|
||||
import '../../../../size_config.dart';
|
||||
import 'package:firebase_auth/firebase_auth.dart';
|
||||
import 'package:initial_folder/screens/splash/splash_screen_login.dart';
|
||||
|
||||
class Begin extends StatelessWidget {
|
||||
const Begin({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//EmailProvider emailProvider = Provider.of<EmailProvider>(context);
|
||||
final user = FirebaseAuth.instance.currentUser;
|
||||
return Row(
|
||||
children: <Widget>[
|
||||
Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
height: getProportionateScreenWidth(60),
|
||||
width: getProportionateScreenWidth(60),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
shape: BoxShape.circle,
|
||||
//border: Border.all(width: 2.0, color: Colors.white),
|
||||
image: (Condition.loginFirebase == true)
|
||||
? DecorationImage(
|
||||
fit: BoxFit.fill,
|
||||
image: NetworkImage(user!.photoURL!))
|
||||
: DecorationImage(
|
||||
image:
|
||||
AssetImage('assets/images/Profile Image.png'))),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(width: getProportionateScreenWidth(24)),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
//SizedBox(height: getProportionateScreenWidth(4)),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
"Hai,",
|
||||
style: primaryTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(12),
|
||||
fontWeight: reguler,
|
||||
color: tenthColor,
|
||||
),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(7)),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Text(
|
||||
'Mau Upgrade Skill Apa?',
|
||||
style: secondaryTextStyle.copyWith(
|
||||
color: tenthColor,
|
||||
fontWeight: semiBold,
|
||||
fontSize: getProportionateScreenWidth(14),
|
||||
),
|
||||
textAlign: TextAlign.left,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
218
lib/screens/home/components/body_comp/carousel.dart
Normal file
218
lib/screens/home/components/body_comp/carousel.dart
Normal file
@ -0,0 +1,218 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:carousel_slider/carousel_slider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/banners_model.dart';
|
||||
import 'package:initial_folder/providers/banners_provider.dart';
|
||||
import 'package:initial_folder/screens/detail_course/detail_course_screen.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:initial_folder/widgets/custom_navigator.dart';
|
||||
import 'package:initial_folder/widgets/terms_and_privacy.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
import '../../../../size_config.dart';
|
||||
|
||||
class CarouselWithIndicatorDemo extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _CarouselWithIndicatorState();
|
||||
}
|
||||
}
|
||||
|
||||
class _CarouselWithIndicatorState extends State<CarouselWithIndicatorDemo> {
|
||||
int _current = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget listBannerPicture(BannersModel listBanner) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
String? idCourse;
|
||||
if (listBanner.courseId.isNotEmpty) {
|
||||
idCourse = listBanner.courseId;
|
||||
} else {
|
||||
if (listBanner.url!.isNotEmpty) {
|
||||
if (listBanner.url!
|
||||
.contains('https://vocasia-v4-develop.vercel.app/')) {
|
||||
List<String> urlList = listBanner.url!.split('/');
|
||||
try {
|
||||
idCourse = urlList.last;
|
||||
} on StateError {
|
||||
idCourse = '0';
|
||||
}
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
CustomNavigator(
|
||||
child: DetailCourseScreen(
|
||||
idcourse: idCourse ?? '0',
|
||||
),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => TermsAndCondition(
|
||||
// url: 'https://vocasia.id/home/contact',
|
||||
url: listBanner.url!,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
splashColor: Colors.white10,
|
||||
child: Container(
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(16),
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.all(Radius.circular(10)),
|
||||
child: AspectRatio(
|
||||
aspectRatio: 2,
|
||||
child: CachedNetworkImage(
|
||||
fadeInDuration: Duration(microseconds: 1),
|
||||
imageUrl: listBanner.img.toString(),
|
||||
fit: BoxFit.contain,
|
||||
placeholder: (context, url) => Shimmer(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: ninthColor,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
),
|
||||
gradient: LinearGradient(
|
||||
stops: [0.2, 0.5, 0.6],
|
||||
colors: [ninthColor, fourthColor, ninthColor])),
|
||||
errorWidget: (context, url, error) => Icon(Icons.error),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
child: Consumer<BannersProvider>(builder: (context, state, _) {
|
||||
if (state.state == ResultState.Loading) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(18.0),
|
||||
child: Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
color: Colors.white),
|
||||
height: 210,
|
||||
width: 50,
|
||||
)),
|
||||
);
|
||||
} else if (state.state == ResultState.HasData) {
|
||||
return Container(
|
||||
child: Column(
|
||||
children: [
|
||||
CarouselSlider(
|
||||
items: state.result
|
||||
.map((banner) => listBannerPicture(banner))
|
||||
.toList(),
|
||||
options: CarouselOptions(
|
||||
height: getProportionateScreenHeight(200),
|
||||
disableCenter: true,
|
||||
autoPlay: true,
|
||||
autoPlayInterval: Duration(seconds: 10),
|
||||
enlargeCenterPage: true,
|
||||
viewportFraction: 1,
|
||||
aspectRatio: 2,
|
||||
onPageChanged: (index, reason) {
|
||||
setState(() {
|
||||
_current = index;
|
||||
});
|
||||
}),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: state.result.map((url) {
|
||||
int index = state.result.indexOf(url);
|
||||
return Container(
|
||||
width: getProportionateScreenWidth(6.0),
|
||||
height: getProportionateScreenWidth(6.0),
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(3.0),
|
||||
vertical: getProportionateScreenWidth(16)),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: _current == index ? thirdColor : fourthColor,
|
||||
),
|
||||
);
|
||||
}).toList()),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else if (state.state == ResultState.NoData) {
|
||||
final defaultBanners = [
|
||||
'assets/images/deffault_banner.png',
|
||||
'assets/images/default_banner_2.png'
|
||||
];
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
CarouselSlider.builder(
|
||||
itemCount: defaultBanners.length,
|
||||
itemBuilder: (context, index, realIndex) {
|
||||
return Image.asset(
|
||||
defaultBanners[index],
|
||||
width: double.infinity,
|
||||
);
|
||||
},
|
||||
options: CarouselOptions(
|
||||
height: getProportionateScreenHeight(200),
|
||||
autoPlay: true,
|
||||
autoPlayInterval: Duration(seconds: 10),
|
||||
enlargeCenterPage: true,
|
||||
viewportFraction: 1,
|
||||
aspectRatio: 2,
|
||||
onPageChanged: (index, reason) {
|
||||
setState(() {
|
||||
_current = index;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: List.generate(defaultBanners.length, (index) {
|
||||
return Container(
|
||||
width: getProportionateScreenWidth(6.0),
|
||||
height: getProportionateScreenWidth(6.0),
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(3.0),
|
||||
vertical: getProportionateScreenWidth(16),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: _current == index ? thirdColor : fourthColor,
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (state.state == ResultState.Error) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(76),
|
||||
top: getProportionateScreenHeight(45),
|
||||
),
|
||||
child: Container(
|
||||
width: getProportionateScreenWidth(480),
|
||||
height: getProportionateScreenHeight(100),
|
||||
color: Colors.transparent,
|
||||
child: Text('Internet lemah, mohon muat ulang'),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Center(child: Text(''));
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
164
lib/screens/home/components/body_comp/certificate_voucher.dart
Normal file
164
lib/screens/home/components/body_comp/certificate_voucher.dart
Normal file
@ -0,0 +1,164 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:initial_folder/screens/certificate/certificate.dart';
|
||||
import 'package:initial_folder/screens/coupon/coupon_page.dart';
|
||||
import 'package:initial_folder/screens/login/login_screen.dart';
|
||||
import 'package:initial_folder/screens/login/login_with_email/login_email_screen.dart';
|
||||
import 'package:initial_folder/screens/splash/splash_screen_login.dart';
|
||||
import 'package:initial_folder/size_config.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:initial_folder/widgets/custom_navigator_bottom.dart';
|
||||
|
||||
class CertificateVoucher extends StatelessWidget {
|
||||
const CertificateVoucher({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Future _showDialogNotLogin() {
|
||||
return showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
elevation: 0.0,
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(20),
|
||||
vertical: getProportionateScreenHeight(20),
|
||||
),
|
||||
content: Text(
|
||||
'Mohon login terlebih dahulu sebelum menukarkan kupon',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(11)),
|
||||
),
|
||||
actions: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
child: Text(
|
||||
'Batal',
|
||||
style: primaryTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(12),
|
||||
letterSpacing: 1,
|
||||
color: primaryColor),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: getProportionateScreenWidth(5),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () => Navigator.of(context).pushNamedAndRemoveUntil(
|
||||
LoginEmail.routeName, (Route<dynamic> route) => false),
|
||||
child: Text('Login',
|
||||
style: primaryTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(12),
|
||||
letterSpacing: 1,
|
||||
color: primaryColor)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return IntrinsicHeight(
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(height: getProportionateScreenHeight(20)),
|
||||
Container(
|
||||
height: getProportionateScreenHeight(44),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.5),
|
||||
spreadRadius: -5,
|
||||
blurRadius: 10,
|
||||
offset: Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
CustomNavigatorBottom(
|
||||
child: Certificate(),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
"assets/icons/certificate.svg",
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
width: getProportionateScreenWidth(13),
|
||||
),
|
||||
SizedBox(width: getProportionateScreenWidth(5)),
|
||||
Text(
|
||||
'Sertifikat',
|
||||
textAlign: TextAlign.start,
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(12),
|
||||
fontWeight: reguler,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(width: getProportionateScreenWidth(40)),
|
||||
Container(
|
||||
height: getProportionateScreenHeight(18),
|
||||
child: VerticalDivider(
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
thickness: 1),
|
||||
),
|
||||
SizedBox(width: getProportionateScreenWidth(40)),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (Condition.loginEmail || Condition.loginFirebase) {
|
||||
showModalBottomSheet(
|
||||
elevation: 0,
|
||||
backgroundColor:
|
||||
Theme.of(context).colorScheme.background,
|
||||
context: context,
|
||||
builder: (context) => ClipRect(child: CouponPage()),
|
||||
isScrollControlled: true,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(0),
|
||||
),
|
||||
);
|
||||
} else if (!Condition.loginEmail ||
|
||||
!Condition.loginFirebase) {
|
||||
_showDialogNotLogin();
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
SvgPicture.asset(
|
||||
"assets/icons/voucher.svg",
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
width: getProportionateScreenWidth(13),
|
||||
),
|
||||
SizedBox(width: getProportionateScreenWidth(5)),
|
||||
Text(
|
||||
'Voucher',
|
||||
textAlign: TextAlign.start,
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(12),
|
||||
fontWeight: reguler,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
286
lib/screens/home/components/body_comp/course_by_category.dart
Normal file
286
lib/screens/home/components/body_comp/course_by_category.dart
Normal file
@ -0,0 +1,286 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:initial_folder/helper/validator.dart';
|
||||
import 'package:initial_folder/providers/course_by_category_provider.dart';
|
||||
import 'package:initial_folder/screens/detail_course/components/app_bar.dart';
|
||||
import 'package:initial_folder/screens/detail_course/components/app_bar_filter.dart';
|
||||
import 'package:initial_folder/screens/detail_course/detail_course_screen.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/latest_course.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/list_of_categories.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/populer_course.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/product_card/product_card.dart';
|
||||
import 'package:initial_folder/services/course_by_category_service.dart';
|
||||
import 'package:initial_folder/size_config.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:initial_folder/widgets/custom_navigator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class CourseByCategory extends StatefulWidget {
|
||||
CourseByCategory({
|
||||
Key? key,
|
||||
required this.name,
|
||||
required this.categoryId,
|
||||
required this.subId,
|
||||
this.homeCategories,
|
||||
}) : super(key: key);
|
||||
|
||||
final String name;
|
||||
final String categoryId;
|
||||
final String subId;
|
||||
final bool? homeCategories;
|
||||
|
||||
@override
|
||||
State<CourseByCategory> createState() => _CourseByCategoryState();
|
||||
}
|
||||
|
||||
class _CourseByCategoryState extends State<CourseByCategory> {
|
||||
bool _isExpanded = false;
|
||||
bool _buttonPressed = false;
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
controller: _scrollController,
|
||||
child: ChangeNotifierProvider<CourseByCategoryProvider>(
|
||||
create: (context) => CourseByCategoryProvider(
|
||||
courseByCategoryService: CourseByCategoryService(),
|
||||
id: widget.categoryId,
|
||||
subId: widget.subId,
|
||||
fetchBySubcategory: false,
|
||||
),
|
||||
child: Container(
|
||||
child: Consumer<CourseByCategoryProvider>(
|
||||
builder: (context, state, _) {
|
||||
if (state.state == ResultState.Loading) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: getProportionateScreenHeight(300)),
|
||||
child: CircularProgressIndicator(
|
||||
color: secondaryColor,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
);
|
||||
} else if (state.state == ResultState.HasData) {
|
||||
return Stack(
|
||||
children: [
|
||||
GestureDetector(
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_isExpanded = !_isExpanded;
|
||||
_buttonPressed = !_buttonPressed;
|
||||
});
|
||||
},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppBarHeader(),
|
||||
SizedBox(height: getProportionateScreenHeight(23)),
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(19)),
|
||||
child: Text(
|
||||
'${widget.name.replaceAll('&', '&')}',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(20),
|
||||
letterSpacing: -0.5,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
textAlign: TextAlign.start,
|
||||
),
|
||||
),
|
||||
if (widget.homeCategories == null)
|
||||
SizedBox(
|
||||
height: getProportionateScreenHeight(65)),
|
||||
if (widget.homeCategories == null)
|
||||
PopulerCourse(text: 'Populer'),
|
||||
if (widget.homeCategories == null)
|
||||
LatestCourse(text: "New Release"),
|
||||
if (widget.homeCategories == null)
|
||||
SizedBox(
|
||||
height: getProportionateScreenHeight(15)),
|
||||
if (widget.homeCategories != null)
|
||||
SizedBox(
|
||||
height: getProportionateScreenHeight(25)),
|
||||
if (widget.homeCategories == null)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(16),
|
||||
bottom: getProportionateScreenHeight(28),
|
||||
),
|
||||
child: Text(
|
||||
"${widget.name}",
|
||||
textAlign: TextAlign.left,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontSize: getProportionateScreenWidth(15),
|
||||
fontWeight: semiBold,
|
||||
),
|
||||
),
|
||||
),
|
||||
GridView.builder(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(21),
|
||||
left: getProportionateScreenWidth(7),
|
||||
bottom: getProportionateScreenHeight(18),
|
||||
),
|
||||
physics: ScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
gridDelegate:
|
||||
SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 2.8 / 4,
|
||||
crossAxisSpacing: 16,
|
||||
mainAxisSpacing: 14,
|
||||
),
|
||||
itemCount: state.result.length,
|
||||
itemBuilder: (context, index) {
|
||||
var courses = state.result[index];
|
||||
int price = int.tryParse(
|
||||
courses.price.replaceAll('.', '')) ??
|
||||
0;
|
||||
int discountPrice = int.tryParse(courses
|
||||
.discountPrice
|
||||
.replaceAll('.', '')) ??
|
||||
0;
|
||||
|
||||
int calculatedPrice =
|
||||
(courses.discountPrice != '0')
|
||||
? price - discountPrice
|
||||
: price;
|
||||
String displayedPrice = (calculatedPrice == 0)
|
||||
? courses.price
|
||||
: calculatedPrice.toString();
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.only(
|
||||
bottom: getProportionateScreenHeight(13)),
|
||||
child: ProductCard(
|
||||
totalDiscount: courses.totalDiscount ?? 0,
|
||||
students: courses.students ?? '0',
|
||||
id: courses.idCourse,
|
||||
thumbnail: courses.thumbnail ??
|
||||
'https://vocasia.id/uploads/thumbnails/course_thumbnails/course_thumbnail_default_63.jpg',
|
||||
title: courses.title,
|
||||
instructorName: courses.instructorName,
|
||||
specificRating: double.parse(courses
|
||||
.rating[0]!.avgRating !=
|
||||
null
|
||||
? '${courses.rating[0]!.avgRating}'
|
||||
: '5.0')
|
||||
.toString(),
|
||||
rating: courses.rating[0]!.avgRating != null
|
||||
? '${courses.rating[0]!.avgRating}'
|
||||
: '5.0',
|
||||
numberOfRatings:
|
||||
courses.rating[0]!.totalReview ?? '0',
|
||||
isTopCourse: '0',
|
||||
price: (courses.discountPrice == '0')
|
||||
? 'Gratis'
|
||||
: numberFormat(displayedPrice),
|
||||
realPrice: (courses.price == '0')
|
||||
? ''
|
||||
: numberFormat(courses.price),
|
||||
press: () async {
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.push(
|
||||
CustomNavigator(
|
||||
child: DetailCourseScreen(
|
||||
idcourse: courses.idCourse,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (widget.homeCategories == null)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.topLeft,
|
||||
widthFactor: 1,
|
||||
heightFactor: 1,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: getProportionateScreenHeight(87)),
|
||||
child: Categories(
|
||||
selectedCategoryId: widget.categoryId,
|
||||
key: UniqueKey(),
|
||||
scrollController: _scrollController,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (state.state == ResultState.NoData) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppBarHeader(),
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(16)),
|
||||
child: Text(
|
||||
'${widget.name.replaceAll('&', '&')}',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(25),
|
||||
letterSpacing: -0.5,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
textAlign: TextAlign.start,
|
||||
),
|
||||
),
|
||||
Categories(
|
||||
selectedCategoryId: widget.categoryId,
|
||||
key: UniqueKey(),
|
||||
scrollController: _scrollController,
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(200)),
|
||||
Center(
|
||||
child: Text(
|
||||
"Oops! Tidak ada kursus yang tersedia dalam kategori ini.",
|
||||
textAlign: TextAlign.center,
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(14),
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(60)),
|
||||
],
|
||||
);
|
||||
} else if (state.state == ResultState.Error) {
|
||||
return Center(child: Text("No internet connections."));
|
||||
} else {
|
||||
return Center(child: Text(''));
|
||||
}
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _collapseSubcategories() {
|
||||
_scrollController.animateTo(
|
||||
0,
|
||||
duration: Duration(milliseconds: 500),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
}
|
237
lib/screens/home/components/body_comp/course_by_subcategory.dart
Normal file
237
lib/screens/home/components/body_comp/course_by_subcategory.dart
Normal file
@ -0,0 +1,237 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/helper/validator.dart';
|
||||
import 'package:initial_folder/providers/course_by_category_provider.dart';
|
||||
import 'package:initial_folder/screens/detail_course/components/app_bar.dart';
|
||||
import 'package:initial_folder/screens/detail_course/components/app_bar_filter.dart';
|
||||
import 'package:initial_folder/screens/detail_course/detail_course_screen.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/product_card/product_card.dart';
|
||||
import 'package:initial_folder/services/course_by_category_service.dart';
|
||||
import 'package:initial_folder/size_config.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:initial_folder/widgets/custom_navigator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class CourseBySubcategory extends StatefulWidget {
|
||||
CourseBySubcategory({
|
||||
Key? key,
|
||||
required this.name,
|
||||
required this.categoryId,
|
||||
required this.subId,
|
||||
}) : super(key: key);
|
||||
|
||||
final String name;
|
||||
final String categoryId;
|
||||
final String subId;
|
||||
|
||||
@override
|
||||
State<CourseBySubcategory> createState() => _CourseBySubcategoryState();
|
||||
}
|
||||
|
||||
class _CourseBySubcategoryState extends State<CourseBySubcategory> {
|
||||
bool _isExpanded = false;
|
||||
bool _buttonPressed = false;
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
controller: _scrollController,
|
||||
child: ChangeNotifierProvider<CourseByCategoryProvider>(
|
||||
create: (context) => CourseByCategoryProvider(
|
||||
courseByCategoryService: CourseByCategoryService(),
|
||||
id: widget.categoryId,
|
||||
subId: widget.subId,
|
||||
fetchBySubcategory: true,
|
||||
),
|
||||
child: Container(
|
||||
child: Consumer<CourseByCategoryProvider>(
|
||||
builder: (context, state, _) {
|
||||
if (state.state == ResultState.Loading) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: secondaryColor,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
);
|
||||
} else if (state.state == ResultState.HasData) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_isExpanded = !_isExpanded;
|
||||
_buttonPressed = !_buttonPressed;
|
||||
});
|
||||
},
|
||||
child: Stack(
|
||||
children: [
|
||||
GestureDetector(
|
||||
child: Container(
|
||||
color: Colors.transparent,
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppBarFilter(),
|
||||
SizedBox(height: getProportionateScreenHeight(10)),
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(16)),
|
||||
child: Text(
|
||||
'${widget.name}',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(20),
|
||||
letterSpacing: -0.5,
|
||||
fontWeight: bold,
|
||||
),
|
||||
textAlign: TextAlign.start,
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(20)),
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(16)),
|
||||
child: Text(
|
||||
"Semua Kursus ${widget.name}",
|
||||
style:
|
||||
thirdTextStyle.copyWith(fontWeight: bold),
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(20)),
|
||||
GridView.builder(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(22),
|
||||
left: getProportionateScreenWidth(7),
|
||||
),
|
||||
physics: ScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
gridDelegate:
|
||||
SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 2.8 / 4,
|
||||
crossAxisSpacing: 16,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
itemCount: state.result.length,
|
||||
itemBuilder: (context, index) {
|
||||
var courses = state.result[index];
|
||||
int price = int.tryParse(
|
||||
courses.price.replaceAll('.', '')) ??
|
||||
0;
|
||||
int discountPrice = int.tryParse(courses
|
||||
.discountPrice
|
||||
.replaceAll('.', '')) ??
|
||||
0;
|
||||
|
||||
int calculatedPrice =
|
||||
(courses.discountPrice != '0')
|
||||
? price - discountPrice
|
||||
: price;
|
||||
String displayedPrice = (calculatedPrice == 0)
|
||||
? courses.price
|
||||
: calculatedPrice.toString();
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.only(
|
||||
bottom: getProportionateScreenHeight(17)),
|
||||
child: ProductCard(
|
||||
totalDiscount: courses.totalDiscount ?? 0,
|
||||
students: courses.students ?? '0',
|
||||
id: courses.idCourse,
|
||||
thumbnail: courses.thumbnail ??
|
||||
'https://vocasia.id/uploads/thumbnails/course_thumbnails/course_thumbnail_default_63.jpg',
|
||||
title: courses.title,
|
||||
instructorName: courses.instructorName,
|
||||
specificRating: double.parse(courses
|
||||
.rating[0]!.avgRating !=
|
||||
null
|
||||
? '${courses.rating[0]!.avgRating}'
|
||||
: '5.0')
|
||||
.toString(),
|
||||
rating: courses.rating[0]!.avgRating != null
|
||||
? '${courses.rating[0]!.avgRating}'
|
||||
: '5.0',
|
||||
numberOfRatings:
|
||||
courses.rating[0]!.totalReview ?? '0',
|
||||
isTopCourse: '0',
|
||||
price: (courses.discountPrice == '0')
|
||||
? 'Gratis'
|
||||
: numberFormat(displayedPrice),
|
||||
realPrice: (courses.price == '0')
|
||||
? ''
|
||||
: numberFormat(courses.price),
|
||||
press: () async {
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.push(
|
||||
CustomNavigator(
|
||||
child: DetailCourseScreen(
|
||||
idcourse: courses.idCourse,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else if (state.state == ResultState.NoData) {
|
||||
return Stack(
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AppBarHeader(),
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(16)),
|
||||
child: Text(
|
||||
'${widget.name.replaceAll('&', '&')}',
|
||||
style: secondaryTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(25),
|
||||
letterSpacing: -0.5,
|
||||
),
|
||||
textAlign: TextAlign.start,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Center(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: getProportionateScreenHeight(300)),
|
||||
child: Text(
|
||||
"Sub kategori yang dipilih tidak memiliki kursus",
|
||||
style: TextStyle(
|
||||
fontSize: getProportionateScreenWidth(10)),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (state.state == ResultState.Error) {
|
||||
return Center(child: Text("Terjadi kesalahan."));
|
||||
} else {
|
||||
return Center(child: Text(''));
|
||||
}
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _collapseSubcategories() {
|
||||
_scrollController.animateTo(
|
||||
0,
|
||||
duration: Duration(milliseconds: 500),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
}
|
173
lib/screens/home/components/body_comp/course_terkait.dart
Normal file
173
lib/screens/home/components/body_comp/course_terkait.dart
Normal file
@ -0,0 +1,173 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:initial_folder/helper/validator.dart';
|
||||
import 'package:initial_folder/providers/course_by_category_provider.dart';
|
||||
import 'package:initial_folder/screens/detail_course/detail_course_screen.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/product_card/product_card.dart';
|
||||
import 'package:initial_folder/services/course_by_category_service.dart';
|
||||
import 'package:initial_folder/size_config.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class CourseTerkait extends StatefulWidget {
|
||||
CourseTerkait({
|
||||
Key? key,
|
||||
required this.name,
|
||||
required this.categoryId,
|
||||
required this.subId,
|
||||
this.homeCategories,
|
||||
}) : super(key: key);
|
||||
|
||||
final String name;
|
||||
final String categoryId;
|
||||
final String subId;
|
||||
final bool? homeCategories;
|
||||
|
||||
@override
|
||||
State<CourseTerkait> createState() => _CourseTerkaitState();
|
||||
}
|
||||
|
||||
class _CourseTerkaitState extends State<CourseTerkait> {
|
||||
final ScrollController _scrollController = ScrollController();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
controller: _scrollController,
|
||||
child: ChangeNotifierProvider<CourseByCategoryProvider>(
|
||||
create: (context) => CourseByCategoryProvider(
|
||||
courseByCategoryService: CourseByCategoryService(),
|
||||
id: widget.categoryId,
|
||||
subId: widget.subId,
|
||||
fetchBySubcategory: false,
|
||||
),
|
||||
child: Container(
|
||||
child: Consumer<CourseByCategoryProvider>(
|
||||
builder: (context, state, _) {
|
||||
if (state.state == ResultState.Loading) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: primaryColor,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
);
|
||||
} else if (state.state == ResultState.HasData) {
|
||||
return Stack(
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: getProportionateScreenHeight(13)),
|
||||
Text(
|
||||
' Kursus Terkait',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontWeight: semiBold,
|
||||
fontSize: getProportionateScreenWidth(15),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(20)),
|
||||
GridView.builder(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(21),
|
||||
left: getProportionateScreenWidth(7),
|
||||
bottom: getProportionateScreenHeight(18),
|
||||
),
|
||||
physics: BouncingScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
gridDelegate:
|
||||
SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 2.8 / 4,
|
||||
crossAxisSpacing: 16,
|
||||
mainAxisSpacing: 14,
|
||||
),
|
||||
itemCount: state.result.length,
|
||||
itemBuilder: (context, index) {
|
||||
var courses = state.result[index];
|
||||
int price = int.tryParse(
|
||||
courses.price.replaceAll('.', '')) ??
|
||||
0;
|
||||
int discountPrice = int.tryParse(courses
|
||||
.discountPrice
|
||||
.replaceAll('.', '')) ??
|
||||
0;
|
||||
|
||||
int calculatedPrice =
|
||||
(courses.discountPrice != '0')
|
||||
? price - discountPrice
|
||||
: price;
|
||||
String displayedPrice = (calculatedPrice == 0)
|
||||
? courses.price
|
||||
: calculatedPrice.toString();
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.only(
|
||||
bottom: getProportionateScreenHeight(13)),
|
||||
child: ProductCard(
|
||||
totalDiscount: courses.totalDiscount ?? 0,
|
||||
students: courses.students ?? '0',
|
||||
id: courses.idCourse,
|
||||
thumbnail: courses.thumbnail ??
|
||||
'https://vocasia.id/uploads/thumbnails/course_thumbnails/course_thumbnail_default_63.jpg',
|
||||
title: courses.title,
|
||||
instructorName: courses.instructorName,
|
||||
specificRating: double.parse(courses
|
||||
.rating[0]!.avgRating !=
|
||||
null
|
||||
? '${courses.rating[0]!.avgRating}'
|
||||
: '5.0')
|
||||
.toString(),
|
||||
rating: courses.rating[0]!.avgRating != null
|
||||
? '${courses.rating[0]!.avgRating}'
|
||||
: '5.0',
|
||||
numberOfRatings:
|
||||
courses.rating[0]!.totalReview ?? '0',
|
||||
isTopCourse: '0',
|
||||
price: (courses.discountPrice == '0')
|
||||
? 'Gratis'
|
||||
: numberFormat(displayedPrice),
|
||||
realPrice: (courses.price == '0')
|
||||
? ''
|
||||
: numberFormat(courses.price),
|
||||
press: () async {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) =>
|
||||
DetailCourseScreen(
|
||||
idcourse: courses.idCourse,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(50)),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
} else if (state.state == ResultState.NoData) {
|
||||
return Center(child: Text("Tidak ada kursus terkait"));
|
||||
} else if (state.state == ResultState.Error) {
|
||||
return Center(child: Text("No internet connections."));
|
||||
} else {
|
||||
return Center(child: Text(''));
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
256
lib/screens/home/components/body_comp/home_categories.dart
Normal file
256
lib/screens/home/components/body_comp/home_categories.dart
Normal file
@ -0,0 +1,256 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:initial_folder/providers/categories_provider.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/course_by_category.dart';
|
||||
import 'package:initial_folder/size_config.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
import 'package:initial_folder/widgets/custom_navigator.dart';
|
||||
|
||||
class HomeCategories extends StatelessWidget {
|
||||
const HomeCategories({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
CategoriesProvider categoriesProvider =
|
||||
Provider.of<CategoriesProvider>(context);
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: getProportionateScreenWidth(17)),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SizedBox(height: getProportionateScreenHeight(15)),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(16)),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'Kategori',
|
||||
textAlign: TextAlign.left,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontSize: getProportionateScreenWidth(15),
|
||||
fontWeight: semiBold,
|
||||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () =>
|
||||
Navigator.pushNamed(context, '/lihatSemuaKategori'),
|
||||
child: Text(
|
||||
'Lihat Semua',
|
||||
textAlign: TextAlign.left,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontSize: getProportionateScreenWidth(11),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(18)),
|
||||
Stack(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(22),
|
||||
right: getProportionateScreenWidth(14),
|
||||
),
|
||||
child: categoriesProvider.state == ResultState.Loading
|
||||
? GridView.count(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 5 / 2,
|
||||
mainAxisSpacing: 13,
|
||||
crossAxisSpacing: 30,
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
children: List.generate(4, (index) {
|
||||
return Shimmer.fromColors(
|
||||
baseColor: Colors.grey,
|
||||
highlightColor: Colors.white,
|
||||
child: SizedBox(
|
||||
width: getProportionateScreenWidth(160),
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: getProportionateScreenHeight(5),
|
||||
horizontal: getProportionateScreenWidth(10),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Colors.grey,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(18)),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
color: Colors.white,
|
||||
height:
|
||||
getProportionateScreenHeight(10),
|
||||
),
|
||||
SizedBox(
|
||||
height:
|
||||
getProportionateScreenHeight(7)),
|
||||
Container(
|
||||
color: Colors.white,
|
||||
height:
|
||||
getProportionateScreenHeight(10),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
)
|
||||
: GridView.count(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 5 / 2,
|
||||
mainAxisSpacing: 13,
|
||||
crossAxisSpacing: 30,
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
children: List.generate(4, (index) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
CustomNavigator(
|
||||
child: CourseByCategory(
|
||||
name: categoriesProvider
|
||||
.result[index].nameCategory! ??
|
||||
'',
|
||||
categoryId:
|
||||
categoriesProvider.result[index].id!,
|
||||
subId: "",
|
||||
homeCategories: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: SizedBox(
|
||||
width: getProportionateScreenWidth(160),
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: getProportionateScreenHeight(5),
|
||||
horizontal: getProportionateScreenWidth(10),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Theme.of(context).brightness ==
|
||||
Brightness.dark
|
||||
? baruTextutih
|
||||
: Colors.grey,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(18)),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
categoriesProvider
|
||||
.result[index].nameCategory!.replaceAll('&', '&'),
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize:
|
||||
getProportionateScreenWidth(10),
|
||||
letterSpacing: 1,
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.topLeft,
|
||||
widthFactor: 0.12,
|
||||
heightFactor: 0.44,
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category1.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.topLeft,
|
||||
widthFactor: 0.12,
|
||||
heightFactor: 1.53,
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category3.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.topCenter,
|
||||
widthFactor: 0.6,
|
||||
heightFactor: 0.4,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(37),
|
||||
top: getProportionateScreenHeight(7),
|
||||
),
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category2.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.bottomCenter,
|
||||
widthFactor: 0.53,
|
||||
heightFactor: 0.39,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(37),
|
||||
bottom: getProportionateScreenHeight(7),
|
||||
),
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category4.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(5)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
485
lib/screens/home/components/body_comp/latest_course.dart
Normal file
485
lib/screens/home/components/body_comp/latest_course.dart
Normal file
@ -0,0 +1,485 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/validator.dart';
|
||||
import 'package:initial_folder/providers/latest_course_provider.dart';
|
||||
import 'package:initial_folder/screens/detail_course/detail_course_screen.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/product_card/product_card.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/product_card/product_card_new.dart';
|
||||
import 'package:initial_folder/widgets/custom_navigator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
|
||||
import '../../../../size_config.dart';
|
||||
import '../../../../theme.dart';
|
||||
|
||||
class LatestCourse extends StatelessWidget {
|
||||
const LatestCourse({Key? key, this.text}) : super(key: key);
|
||||
|
||||
final String? text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(height: getProportionateScreenHeight(20)),
|
||||
Padding(
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(16)),
|
||||
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
|
||||
Text(
|
||||
text.toString(),
|
||||
textAlign: TextAlign.left,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontSize: getProportionateScreenWidth(15),
|
||||
fontWeight: semiBold,
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(10)),
|
||||
Consumer<LatestCourseProvider>(
|
||||
builder: (context, state, _) {
|
||||
if (state.state == ResultState.Loading) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
} else if (state.state == ResultState.HasData) {
|
||||
return text != "New Release"
|
||||
? Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
margin: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(10)),
|
||||
height: getProportionateScreenHeight(240),
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
physics: const ScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemCount: state.result.length,
|
||||
itemBuilder: (context, index) {
|
||||
var latestCourse = state.result[index];
|
||||
int price = int.tryParse(
|
||||
latestCourse.price.replaceAll('.', '')) ??
|
||||
0;
|
||||
int discountPrice = int.tryParse(latestCourse
|
||||
.discountPrice
|
||||
.replaceAll('.', '')) ??
|
||||
0;
|
||||
|
||||
int calculatedPrice =
|
||||
(latestCourse.discountPrice != '0')
|
||||
? price - discountPrice
|
||||
: price;
|
||||
|
||||
String displayedPrice = (calculatedPrice == 0)
|
||||
? latestCourse.price
|
||||
: calculatedPrice.toString();
|
||||
// var finalRating = double.parse(
|
||||
// (topCourse.specificRating![0] / 20).toStringAsFixed(2));
|
||||
return Container(
|
||||
margin: EdgeInsets.only(
|
||||
top: getProportionateScreenHeight(10),
|
||||
bottom: getProportionateScreenHeight(10),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(18),
|
||||
bottom: getProportionateScreenWidth(5),
|
||||
),
|
||||
child: ProductCardNew(
|
||||
totalDiscount: latestCourse.totalDiscount ?? 0,
|
||||
students: latestCourse.students ?? '0',
|
||||
pad: 12,
|
||||
// padRight: 12,
|
||||
id: latestCourse.idCourse,
|
||||
thumbnail: latestCourse.thumbnail ??
|
||||
'$baseUrl/uploads/courses_thumbnail/course_thumbnail_default_57.jpg',
|
||||
title: latestCourse.title,
|
||||
instructorName: latestCourse.instructorName,
|
||||
specificRating:
|
||||
(latestCourse.rating.isNotEmpty &&
|
||||
latestCourse.rating[0]?.avgRating !=
|
||||
null)
|
||||
? latestCourse.rating[0]!.avgRating
|
||||
.toString()
|
||||
: '0',
|
||||
rating:
|
||||
latestCourse.rating[0]!.avgRating != null
|
||||
? '${latestCourse.rating[0]!.avgRating}'
|
||||
: '5.0',
|
||||
numberOfRatings: (latestCourse
|
||||
.rating.isNotEmpty &&
|
||||
latestCourse.rating[0]?.totalReview !=
|
||||
null)
|
||||
? latestCourse.rating[0]!.totalReview!
|
||||
: '0',
|
||||
isTopCourse: latestCourse.topCourse ?? '',
|
||||
price: (latestCourse.price == '0')
|
||||
? 'Gratis'
|
||||
: (latestCourse.promoPrice != '0')
|
||||
? numberFormat(latestCourse.promoPrice)
|
||||
: numberFormat(displayedPrice),
|
||||
realPrice: (latestCourse.price == '0')
|
||||
? ''
|
||||
: numberFormat(latestCourse.price),
|
||||
press: () {
|
||||
print(latestCourse.idCourse);
|
||||
Navigator.of(context, rootNavigator: true)
|
||||
.push(
|
||||
CustomNavigator(
|
||||
child: DetailCourseScreen(
|
||||
idcourse: latestCourse.idCourse,
|
||||
isPromo: latestCourse.promoPrice != '0'
|
||||
? true
|
||||
: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
: GridView.builder(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(22),
|
||||
left: getProportionateScreenWidth(7),
|
||||
top: getProportionateScreenHeight(10),
|
||||
),
|
||||
physics: ScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 2.55 / 4,
|
||||
crossAxisSpacing: 16,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
itemCount: state.result.length,
|
||||
itemBuilder: (context, index) {
|
||||
var latestCourse = state.result[index];
|
||||
int price = int.tryParse(
|
||||
latestCourse.price.replaceAll('.', '')) ??
|
||||
0;
|
||||
int discountPrice = int.tryParse(latestCourse
|
||||
.discountPrice
|
||||
.replaceAll('.', '')) ??
|
||||
0;
|
||||
|
||||
int calculatedPrice =
|
||||
(latestCourse.discountPrice != '0')
|
||||
? price - discountPrice
|
||||
: price;
|
||||
|
||||
String displayedPrice = (calculatedPrice == 0)
|
||||
? latestCourse.price
|
||||
: calculatedPrice.toString();
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.only(
|
||||
bottom: getProportionateScreenHeight(17)),
|
||||
child: ProductCardNew(
|
||||
totalDiscount: latestCourse.totalDiscount ?? 0,
|
||||
students: latestCourse.students ?? '0',
|
||||
id: latestCourse.idCourse,
|
||||
thumbnail: latestCourse.thumbnail ??
|
||||
'https://vocasia.id/uploads/thumbnails/course_thumbnails/course_thumbnail_default_63.jpg',
|
||||
title: latestCourse.title,
|
||||
instructorName: latestCourse.instructorName,
|
||||
specificRating: double.parse(
|
||||
latestCourse.rating[0]!.avgRating != null
|
||||
? '${latestCourse.rating[0]!.avgRating}'
|
||||
: '5.0')
|
||||
.toString(),
|
||||
rating: latestCourse.rating[0]!.avgRating != null
|
||||
? '${latestCourse.rating[0]!.avgRating}'
|
||||
: '5.0',
|
||||
numberOfRatings:
|
||||
latestCourse.rating[0]!.totalReview ?? '0',
|
||||
isTopCourse: '0',
|
||||
price: (latestCourse.discountPrice == '0')
|
||||
? 'Gratis'
|
||||
: numberFormat(displayedPrice),
|
||||
realPrice: (latestCourse.price == '0')
|
||||
? ''
|
||||
: numberFormat(latestCourse.price),
|
||||
press: () async {
|
||||
// await Hive.openBox<Wishlist>("wishlist");
|
||||
// await Hive.openBox('carts');
|
||||
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
CustomNavigator(
|
||||
child: DetailCourseScreen(
|
||||
idcourse: latestCourse.idCourse,
|
||||
isPromo: latestCourse.promoPrice != '0'
|
||||
? true
|
||||
: null,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} else if (state.state == ResultState.NoData) {
|
||||
return Center(child: Text(state.message));
|
||||
} else if (state.state == ResultState.Error) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Center(child: Text(''));
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Column(
|
||||
// children: [
|
||||
// Padding(
|
||||
// padding:
|
||||
// EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(16)),
|
||||
// child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
|
||||
// Text('Kursus Terbaru',
|
||||
// textAlign: TextAlign.left,
|
||||
// style: secondaryTextStyle.copyWith(
|
||||
// letterSpacing: 1,
|
||||
// color: tenthColor,
|
||||
// fontSize: getProportionateScreenWidth(14),
|
||||
// fontWeight: semiBold)),
|
||||
// ]),
|
||||
// ),
|
||||
// SizedBox(height: 20),
|
||||
// Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// children: [
|
||||
// Icon(Icons.construction_outlined),
|
||||
// Text('Under Construction'),
|
||||
// ],
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
}
|
273
lib/screens/home/components/body_comp/lihat_semua_kategori.dart
Normal file
273
lib/screens/home/components/body_comp/lihat_semua_kategori.dart
Normal file
@ -0,0 +1,273 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:initial_folder/providers/categories_provider.dart'
|
||||
as categoriesProv;
|
||||
import 'package:initial_folder/providers/others_course_provider.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/course_by_category.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:initial_folder/widgets/custom_navigator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../../size_config.dart';
|
||||
|
||||
class LihatSemuaKategori extends StatefulWidget {
|
||||
const LihatSemuaKategori({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<LihatSemuaKategori> createState() => _LihatSemuaKategoriState();
|
||||
}
|
||||
|
||||
class _LihatSemuaKategoriState extends State<LihatSemuaKategori> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
categoriesProv.CategoriesProvider categoriesProvider =
|
||||
Provider.of<categoriesProv.CategoriesProvider>(context);
|
||||
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
scrolledUnderElevation: 0.0,
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
title: Text(
|
||||
"Kategori",
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontWeight: bold, fontSize: getProportionateScreenWidth(16)),
|
||||
),
|
||||
),
|
||||
body: Padding(
|
||||
padding: EdgeInsets.only(left: getProportionateScreenWidth(15)),
|
||||
child: Stack(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(20),
|
||||
right: getProportionateScreenWidth(14),
|
||||
top: getProportionateScreenHeight(10),
|
||||
),
|
||||
child: categoriesProvider.state == ResultState.Loading
|
||||
? Center(child: CircularProgressIndicator())
|
||||
: GridView.count(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 4.3 / 2,
|
||||
mainAxisSpacing: 13,
|
||||
crossAxisSpacing: 30,
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
children: List.generate(
|
||||
categoriesProvider.result.length, (index) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
CustomNavigator(
|
||||
child: CourseByCategory(
|
||||
name: categoriesProvider
|
||||
.result[index].nameCategory! ??
|
||||
'',
|
||||
categoryId:
|
||||
categoriesProvider.result[index].id!,
|
||||
subId: "",
|
||||
homeCategories: true,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: SizedBox(
|
||||
width: getProportionateScreenWidth(160),
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: getProportionateScreenHeight(5),
|
||||
horizontal: getProportionateScreenWidth(10),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Theme.of(context).brightness ==
|
||||
Brightness.dark
|
||||
? baruTextutih
|
||||
: Colors.grey,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(18)),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
categoriesProvider
|
||||
.result[index].nameCategory!.replaceAll('&', '&'),
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize:
|
||||
getProportionateScreenWidth(10),
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.topLeft,
|
||||
widthFactor: 0.12,
|
||||
heightFactor: 0.2,
|
||||
child: Padding(
|
||||
padding:
|
||||
EdgeInsets.only(top: getProportionateScreenHeight(9)),
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category1.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.topLeft,
|
||||
widthFactor: 0.12,
|
||||
heightFactor: 0.59,
|
||||
child: Padding(
|
||||
padding:
|
||||
EdgeInsets.only(top: getProportionateScreenHeight(9)),
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category3.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.topRight,
|
||||
widthFactor: 0.51,
|
||||
heightFactor: 0.2,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(133),
|
||||
top: getProportionateScreenHeight(10),
|
||||
),
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category2.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.topRight,
|
||||
widthFactor: 0.51,
|
||||
heightFactor: 0.6,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(133),
|
||||
top: getProportionateScreenHeight(10),
|
||||
),
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category4.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.centerLeft,
|
||||
widthFactor: 0.12,
|
||||
heightFactor: 0.7,
|
||||
child: Padding(
|
||||
padding:
|
||||
EdgeInsets.only(top: getProportionateScreenHeight(9)),
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category5.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.bottomLeft,
|
||||
widthFactor: 0.12,
|
||||
heightFactor: 0.57,
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category7.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.centerRight,
|
||||
widthFactor: 0.51,
|
||||
heightFactor: 0.75,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(133),
|
||||
top: getProportionateScreenHeight(10),
|
||||
),
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category6.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.bottomRight,
|
||||
widthFactor: 0.51,
|
||||
heightFactor: 0.57,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(133)),
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category8.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (categoriesProvider.state != ResultState.Loading)
|
||||
Positioned.fill(
|
||||
child: FractionallySizedBox(
|
||||
alignment: Alignment.bottomLeft,
|
||||
widthFactor: 0.12,
|
||||
heightFactor: 0.17,
|
||||
child: SvgPicture.asset(
|
||||
"assets/icons/category9.svg",
|
||||
width: getProportionateScreenWidth(35),
|
||||
height: getProportionateScreenHeight(35),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,129 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/helper/validator.dart';
|
||||
import 'package:initial_folder/providers/others_course_provider.dart';
|
||||
import 'package:initial_folder/screens/detail_course/components/app_bar.dart';
|
||||
import 'package:initial_folder/screens/detail_course/detail_course_screen.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'others_course.dart';
|
||||
import 'product_card/product_card.dart';
|
||||
import '../../../../size_config.dart';
|
||||
import 'section_title.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class LihatSemuaKursus extends StatefulWidget {
|
||||
static String routeName = "/lihatKursus";
|
||||
|
||||
const LihatSemuaKursus({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<LihatSemuaKursus> createState() => _LihatSemuaKursusState();
|
||||
}
|
||||
|
||||
class _LihatSemuaKursusState extends State<LihatSemuaKursus> {
|
||||
ScrollController _controller = ScrollController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_controller.addListener(() {
|
||||
onScroll();
|
||||
});
|
||||
}
|
||||
|
||||
void onScroll() async {
|
||||
double maxScroll = _controller.position.maxScrollExtent;
|
||||
double currentScroll = _controller.position.pixels;
|
||||
if (maxScroll == currentScroll) {
|
||||
await Provider.of<OthersCourseProvider>(context, listen: false)
|
||||
.getOthersCourses();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_controller.hasClients) {
|
||||
if (_controller.position.pixels != _controller.position.maxScrollExtent) {
|
||||
_controller.animateTo(0,
|
||||
duration: Duration(milliseconds: 900), curve: Curves.linear);
|
||||
}
|
||||
}
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
scrolledUnderElevation: 0.0,
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
title: Text(
|
||||
"Kursus Lainnya",
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontWeight: bold, fontSize: getProportionateScreenWidth(16)),
|
||||
),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Consumer<OthersCourseProvider>(builder: (context, state, _) {
|
||||
if (state.state == ResultState.Loading) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: secondaryColor,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
);
|
||||
} else if (state.state == ResultState.HasData) {
|
||||
return Expanded(
|
||||
child: ListView(controller: _controller, children: [
|
||||
OthersCourse(
|
||||
key: PageStorageKey<String>('lihatKursus'),
|
||||
showTitle: true,
|
||||
),
|
||||
Provider.of<OthersCourseProvider>(context).loading
|
||||
? Center(
|
||||
child: SizedBox(
|
||||
height: 30,
|
||||
width: 30,
|
||||
child: CircularProgressIndicator(
|
||||
color: secondaryColor,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
)
|
||||
: SizedBox(height: 30),
|
||||
SizedBox(height: 25),
|
||||
]),
|
||||
);
|
||||
} else if (state.state == ResultState.NoData) {
|
||||
return Center(child: Text(state.message));
|
||||
} else if (state.state == ResultState.Error) {
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
'Terjadi Kesalahan Coba Lagi',
|
||||
style: thirdTextStyle,
|
||||
),
|
||||
],
|
||||
));
|
||||
} else {
|
||||
return Center(child: Text(''));
|
||||
}
|
||||
})
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// courseProvider.course
|
||||
// .map(
|
||||
// (product) => ProductCard(
|
||||
// product: product,
|
||||
// ),
|
||||
// )
|
||||
// .toList(),
|
239
lib/screens/home/components/body_comp/list_of_categories.dart
Normal file
239
lib/screens/home/components/body_comp/list_of_categories.dart
Normal file
@ -0,0 +1,239 @@
|
||||
import 'dart:ui';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/subcategories_model.dart';
|
||||
import 'package:initial_folder/providers/categories_provider.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/course_by_subcategory.dart';
|
||||
import 'package:initial_folder/size_config.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:initial_folder/widgets/custom_navigator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class Categories extends StatefulWidget {
|
||||
const Categories({
|
||||
Key? key,
|
||||
this.scrollable = false,
|
||||
required this.selectedCategoryId,
|
||||
required this.scrollController,
|
||||
}) : super(key: key);
|
||||
final bool scrollable;
|
||||
final String selectedCategoryId;
|
||||
final ScrollController scrollController;
|
||||
|
||||
@override
|
||||
State<Categories> createState() => _CategoriesState();
|
||||
}
|
||||
|
||||
class _CategoriesState extends State<Categories> {
|
||||
bool _isExpanded = false;
|
||||
bool _buttonPressed = false;
|
||||
final GlobalKey<_CategoriesState> _categoriesKey =
|
||||
GlobalKey<_CategoriesState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.scrollController.addListener(_scrollListener);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.scrollController.removeListener(_scrollListener);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _scrollListener() {
|
||||
if (_isExpanded) {
|
||||
setState(() {
|
||||
_isExpanded = false;
|
||||
_buttonPressed = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void toggleExpansion(bool expanded) {
|
||||
setState(() {
|
||||
_isExpanded = expanded;
|
||||
_buttonPressed = expanded;
|
||||
});
|
||||
|
||||
if (!expanded) {
|
||||
widget.scrollController.animateTo(
|
||||
0,
|
||||
duration: Duration(milliseconds: 500),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
child: Consumer<CategoriesProvider>(builder: (context, state, _) {
|
||||
if (state.state == ResultState.Loading) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
color: secondaryColor,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
);
|
||||
} else if (state.state == ResultState.HasData) {
|
||||
final List<SubCategoryModel> filteredResult = state.result
|
||||
.where((category) => category.id == widget.selectedCategoryId)
|
||||
.map((category) => category.subCategories!)
|
||||
.expand((element) => element)
|
||||
.toList();
|
||||
final bool showExpandIcon = filteredResult.length > 3;
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(
|
||||
vertical: getProportionateScreenHeight(10)),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.background,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Theme.of(context).brightness == Brightness.dark
|
||||
? Colors.grey.withOpacity(0.6)
|
||||
: Colors.black.withOpacity(0.2),
|
||||
spreadRadius: -10,
|
||||
blurRadius: 12,
|
||||
offset: Offset(0, 9),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
...filteredResult
|
||||
.take(_buttonPressed ? 2 : 2)
|
||||
.map<Widget>((subcategory) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(17)),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CustomNavigator(
|
||||
child: CourseBySubcategory(
|
||||
categoryId: widget.selectedCategoryId,
|
||||
subId: subcategory.subId,
|
||||
name: subcategory.nameSubCategory,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
subcategory.nameSubCategory.isNotEmpty
|
||||
? subcategory.nameSubCategory.replaceAll('&', '&')
|
||||
: 'No subcategories available',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(11.5),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
if (showExpandIcon)
|
||||
IconButton(
|
||||
icon: Transform.rotate(
|
||||
angle: _isExpanded ? pi / 2 : 0,
|
||||
child: Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
size: getProportionateScreenWidth(16),
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_isExpanded = !_isExpanded;
|
||||
_buttonPressed = !_buttonPressed;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
if (_isExpanded)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
top: getProportionateScreenHeight(8)),
|
||||
child: Container(
|
||||
color: Theme.of(context).colorScheme.background,
|
||||
height: 160,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
physics: AlwaysScrollableScrollPhysics(),
|
||||
children: filteredResult
|
||||
.skip(2)
|
||||
.map<Widget>((subcategory) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal:
|
||||
getProportionateScreenWidth(17)),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CustomNavigator(
|
||||
child: CourseBySubcategory(
|
||||
categoryId:
|
||||
widget.selectedCategoryId,
|
||||
subId: subcategory.subId,
|
||||
name: subcategory.nameSubCategory,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom:
|
||||
getProportionateScreenHeight(10)),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom:
|
||||
getProportionateScreenHeight(
|
||||
9)),
|
||||
child: Text(
|
||||
subcategory.nameSubCategory.isNotEmpty
|
||||
? subcategory.nameSubCategory.replaceAll('&', '&')
|
||||
: 'No subcategories available',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize:
|
||||
getProportionateScreenWidth(
|
||||
11.5),
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
key: _categoriesKey,
|
||||
);
|
||||
} else if (state.state == ResultState.NoData) {
|
||||
return Center(child: Text("No subcategories available"));
|
||||
} else if (state.state == ResultState.Error) {
|
||||
return Center(child: Text("No internet connections."));
|
||||
} else {
|
||||
print(state.result.length);
|
||||
return Center(child: Text(''));
|
||||
}
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
368
lib/screens/home/components/body_comp/others_course.dart
Normal file
368
lib/screens/home/components/body_comp/others_course.dart
Normal file
@ -0,0 +1,368 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/validator.dart';
|
||||
import 'package:initial_folder/providers/others_course_provider.dart';
|
||||
import 'package:initial_folder/screens/detail_course/detail_course_screen.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/lihat_semua_kursus_page.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:initial_folder/widgets/custom_navigator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
import 'product_card/product_card.dart';
|
||||
import '../../../../size_config.dart';
|
||||
import 'section_title.dart';
|
||||
|
||||
class OthersCourse extends StatelessWidget {
|
||||
final bool? showTitle;
|
||||
const OthersCourse({Key? key, this.showTitle}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(16)),
|
||||
child: (showTitle == null)
|
||||
? SectionTitle(
|
||||
title: "Kursus Lainnya",
|
||||
press: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
CustomNavigator(
|
||||
child: LihatSemuaKursus(),
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
: SizedBox()),
|
||||
SizedBox(height: getProportionateScreenHeight(30)),
|
||||
Consumer<OthersCourseProvider>(builder: (context, state, _) {
|
||||
if (state.state == ResultState.Loading) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
} else if (state.state == ResultState.HasData) {
|
||||
// state.result.shuffle();
|
||||
return GridView.builder(
|
||||
// controller: _controller,
|
||||
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(23),
|
||||
left: getProportionateScreenWidth(8),
|
||||
),
|
||||
physics: ScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 2.6 / 4,
|
||||
crossAxisSpacing: 15,
|
||||
mainAxisSpacing: 10,
|
||||
),
|
||||
itemCount: state.result.length,
|
||||
itemBuilder: (context, index) {
|
||||
var othersCourse = state.result[index];
|
||||
int price =
|
||||
int.tryParse(othersCourse.price.replaceAll('.', '')) ?? 0;
|
||||
int discountPrice = int.tryParse(
|
||||
othersCourse.discountPrice.replaceAll('.', '')) ??
|
||||
0;
|
||||
|
||||
int calculatedPrice = (othersCourse.discountPrice != '0')
|
||||
? price - discountPrice
|
||||
: price;
|
||||
|
||||
String displayedPrice = (calculatedPrice == 0)
|
||||
? othersCourse.price
|
||||
: calculatedPrice.toString();
|
||||
// var finalRating = double.parse(
|
||||
// (othersCourse.specificRating![0] / 20).toStringAsFixed(2));
|
||||
return Padding(
|
||||
padding:
|
||||
EdgeInsets.only(bottom: getProportionateScreenHeight(8)),
|
||||
child: Container(
|
||||
margin: EdgeInsets.only(
|
||||
bottom: getProportionateScreenHeight(12)),
|
||||
child: ProductCard(
|
||||
totalDiscount: othersCourse.totalDiscount ?? 0,
|
||||
students: othersCourse.students ?? '0',
|
||||
id: othersCourse.idCourse,
|
||||
thumbnail: othersCourse.thumbnail ??
|
||||
'$baseUrl/uploads/courses_thumbnail/course_thumbnail_default_57.jpg',
|
||||
title: othersCourse.title,
|
||||
instructorName: othersCourse.instructorName,
|
||||
specificRating: (othersCourse.rating.isNotEmpty &&
|
||||
othersCourse.rating[0]?.avgRating != null)
|
||||
? othersCourse.rating[0]!.avgRating.toString()
|
||||
: '0',
|
||||
rating: (othersCourse.rating.isNotEmpty &&
|
||||
othersCourse.rating[0]?.avgRating != null)
|
||||
? othersCourse.rating[0]!.avgRating.toString()
|
||||
: '5.0',
|
||||
numberOfRatings: (othersCourse.rating.isNotEmpty &&
|
||||
othersCourse.rating[0]?.totalReview != null)
|
||||
? othersCourse.rating[0]!.totalReview!
|
||||
: '0',
|
||||
isTopCourse: othersCourse.topCourse ?? '',
|
||||
price: (othersCourse.price == '0')
|
||||
? 'Gratis'
|
||||
: (othersCourse.promoPrice != '0')
|
||||
? numberFormat(othersCourse.promoPrice)
|
||||
: numberFormat(displayedPrice),
|
||||
realPrice: (othersCourse.price == '0')
|
||||
? ''
|
||||
: numberFormat(othersCourse.price),
|
||||
press: () {
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
CustomNavigator(
|
||||
child: DetailCourseScreen(
|
||||
idcourse: othersCourse.idCourse,
|
||||
isPromo:
|
||||
othersCourse.promoPrice != "0" ? true : null,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} else if (state.state == ResultState.NoData) {
|
||||
return Center(child: Text(state.message));
|
||||
} else if (state.state == ResultState.Error) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Center(child: Text(''));
|
||||
}
|
||||
})
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// courseProvider.course
|
||||
// .map(
|
||||
// (product) => ProductCard(
|
||||
// product: product,
|
||||
// ),
|
||||
// )
|
||||
// .toList(),
|
361
lib/screens/home/components/body_comp/populer_course.dart
Normal file
361
lib/screens/home/components/body_comp/populer_course.dart
Normal file
@ -0,0 +1,361 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_html/flutter_html.dart';
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/validator.dart';
|
||||
import 'package:initial_folder/providers/top_course_provider.dart';
|
||||
import 'package:initial_folder/screens/detail_course/detail_course_screen.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/product_card/product_card.dart';
|
||||
import 'package:initial_folder/widgets/custom_navigator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
|
||||
import '../../../../size_config.dart';
|
||||
import '../../../../theme.dart';
|
||||
|
||||
class PopulerCourse extends StatelessWidget {
|
||||
const PopulerCourse({Key? key, this.text}) : super(key: key);
|
||||
final String? text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(16)),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
text.toString(),
|
||||
textAlign: TextAlign.left,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontSize: getProportionateScreenWidth(15),
|
||||
fontWeight: semiBold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(10)),
|
||||
Consumer<TopCourseProvider>(
|
||||
builder: (context, state, _) {
|
||||
if (state.state == ResultState.Loading) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
} else if (state.state == ResultState.HasData) {
|
||||
return Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
margin: EdgeInsets.only(left: getProportionateScreenWidth(10)),
|
||||
height: getProportionateScreenHeight(220),
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
physics: ScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemCount: state.result.length,
|
||||
itemBuilder: (context, index) {
|
||||
var topCourse = state.result[index];
|
||||
// var finalRating = double.parse(
|
||||
// (topCourse.specificRating![0] / 20).toStringAsFixed(2));
|
||||
int price =
|
||||
int.tryParse(topCourse.price.replaceAll('.', '')) ?? 0;
|
||||
int discountPrice = int.tryParse(
|
||||
topCourse.discountPrice.replaceAll('.', '')) ??
|
||||
0;
|
||||
|
||||
int calculatedPrice = (topCourse.discountPrice != '0')
|
||||
? price - discountPrice
|
||||
: price;
|
||||
|
||||
String displayedPrice = (calculatedPrice == 0)
|
||||
? topCourse.price
|
||||
: calculatedPrice.toString();
|
||||
return Container(
|
||||
margin: EdgeInsets.only(
|
||||
top: getProportionateScreenHeight(10),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(18),
|
||||
bottom: getProportionateScreenWidth(18),
|
||||
),
|
||||
child: ProductCard(
|
||||
totalDiscount: topCourse.totalDiscount ?? 0,
|
||||
students: topCourse.students ?? '0',
|
||||
pad: 12,
|
||||
id: topCourse.idCourse,
|
||||
thumbnail: topCourse.thumbnail ??
|
||||
'$baseUrl/uploads/courses_thumbnail/course_thumbnail_default_57.jpg',
|
||||
title: topCourse.title,
|
||||
instructorName: topCourse.instructorName,
|
||||
specificRating: (topCourse.rating.isNotEmpty &&
|
||||
topCourse.rating[0]?.avgRating != null)
|
||||
? topCourse.rating[0]!.avgRating.toString()
|
||||
: '0',
|
||||
rating: (topCourse.rating.isNotEmpty &&
|
||||
topCourse.rating[0]?.avgRating != null)
|
||||
? topCourse.rating[0]!.avgRating.toString()
|
||||
: '5.0',
|
||||
numberOfRatings: (topCourse.rating.isNotEmpty &&
|
||||
topCourse.rating[0]?.totalReview != null)
|
||||
? topCourse.rating[0]!.totalReview!
|
||||
: '0',
|
||||
isTopCourse: topCourse.topCourse!,
|
||||
price: (topCourse.price == '0')
|
||||
? 'Gratis'
|
||||
: (topCourse.promoPrice != '0')
|
||||
? numberFormat(topCourse.promoPrice)
|
||||
: numberFormat(displayedPrice),
|
||||
realPrice: (topCourse.price == '0')
|
||||
? ''
|
||||
: numberFormat(topCourse.price),
|
||||
press: () {
|
||||
print(topCourse.idCourse);
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
CustomNavigator(
|
||||
child: DetailCourseScreen(
|
||||
idcourse: topCourse.idCourse,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
} else if (state.state == ResultState.NoData) {
|
||||
return Center(child: Text(state.message));
|
||||
} else if (state.state == ResultState.Error) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Center(child: Text(''));
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
243
lib/screens/home/components/body_comp/populer_course_big.dart
Normal file
243
lib/screens/home/components/body_comp/populer_course_big.dart
Normal file
@ -0,0 +1,243 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_html/flutter_html.dart';
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/validator.dart';
|
||||
import 'package:initial_folder/providers/top_course_provider.dart';
|
||||
import 'package:initial_folder/screens/detail_course/detail_course_screen.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/product_card/product_card.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/product_card/product_card_big.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
|
||||
import '../../../../size_config.dart';
|
||||
import '../../../../theme.dart';
|
||||
|
||||
class PopulerCourseBig extends StatelessWidget {
|
||||
const PopulerCourseBig({Key? key, this.text}) : super(key: key);
|
||||
final String? text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(16)),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
text!,
|
||||
textAlign: TextAlign.left,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontSize: getProportionateScreenWidth(15),
|
||||
fontWeight: semiBold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(10)),
|
||||
Consumer<TopCourseProvider>(
|
||||
builder: (context, state, _) {
|
||||
if (state.state == ResultState.Loading) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
} else if (state.state == ResultState.HasData) {
|
||||
return Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
margin: EdgeInsets.only(left: getProportionateScreenWidth(4)),
|
||||
height: getProportionateScreenHeight(270),
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
physics: ScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemCount: state.result.length,
|
||||
itemBuilder: (context, index) {
|
||||
var topCourse = state.result[index];
|
||||
// var finalRating = double.parse(
|
||||
// (topCourse.specificRating![0] / 20).toStringAsFixed(2));
|
||||
return Container(
|
||||
margin: EdgeInsets.only(
|
||||
top: getProportionateScreenHeight(10),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(13),
|
||||
bottom: getProportionateScreenWidth(18),
|
||||
),
|
||||
child: ProductCardBig(
|
||||
totalDiscount: topCourse.totalDiscount ?? 0,
|
||||
students: topCourse.students ?? '0',
|
||||
pad: 12,
|
||||
id: topCourse.idCourse,
|
||||
thumbnail: topCourse.thumbnail ??
|
||||
'$baseUrl/uploads/courses_thumbnail/course_thumbnail_default_57.jpg',
|
||||
title: topCourse.title,
|
||||
instructorName: topCourse.instructorName,
|
||||
specificRating: (topCourse.rating.isNotEmpty &&
|
||||
topCourse.rating[0]?.avgRating != null)
|
||||
? topCourse.rating[0]!.avgRating.toString()
|
||||
: '0',
|
||||
rating: (topCourse.rating.isNotEmpty &&
|
||||
topCourse.rating[0]?.avgRating != null)
|
||||
? topCourse.rating[0]!.avgRating.toString()
|
||||
: '5.0',
|
||||
numberOfRatings: (topCourse.rating.isNotEmpty &&
|
||||
topCourse.rating[0]?.totalReview != null)
|
||||
? topCourse.rating[0]!.totalReview!
|
||||
: '0',
|
||||
isTopCourse: topCourse.topCourse!,
|
||||
price: (topCourse.discountPrice == '0')
|
||||
? 'Gratis'
|
||||
: numberFormat(topCourse.discountPrice),
|
||||
realPrice: (topCourse.price == '0')
|
||||
? ''
|
||||
: numberFormat(topCourse.price),
|
||||
press: () {
|
||||
print(topCourse.idCourse);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => DetailCourseScreen(
|
||||
idcourse: topCourse.idCourse,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
} else if (state.state == ResultState.NoData) {
|
||||
return Center(child: Text(state.message));
|
||||
} else if (state.state == ResultState.Error) {
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
Text('Terjadi Kesalahan Coba Lagi'),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Center(child: Text(''));
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,328 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:initial_folder/providers/theme_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
import '../../../../../theme.dart';
|
||||
import '../../../../../size_config.dart';
|
||||
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
||||
|
||||
class ProductCard extends StatelessWidget {
|
||||
const ProductCard({
|
||||
Key? key,
|
||||
this.width = 120,
|
||||
this.pad = 16,
|
||||
this.padRight = 0,
|
||||
this.isHome,
|
||||
required this.thumbnail,
|
||||
required this.id,
|
||||
required this.isTopCourse,
|
||||
required this.title,
|
||||
required this.instructorName,
|
||||
required this.rating,
|
||||
required this.specificRating,
|
||||
required this.numberOfRatings,
|
||||
required this.price,
|
||||
required this.realPrice,
|
||||
required this.press,
|
||||
required this.students,
|
||||
required this.totalDiscount,
|
||||
}) : super(key: key);
|
||||
|
||||
final double width;
|
||||
final double pad, padRight;
|
||||
final String thumbnail,
|
||||
title,
|
||||
instructorName,
|
||||
price,
|
||||
realPrice,
|
||||
rating,
|
||||
specificRating,
|
||||
numberOfRatings,
|
||||
id,
|
||||
isTopCourse;
|
||||
final String students;
|
||||
final VoidCallback press;
|
||||
final int totalDiscount;
|
||||
final bool? isHome;
|
||||
// final VoidCallback? whislistPress;
|
||||
// final Widget? iconWishlist;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//CourseProvider courseProvider = Provider.of<CourseProvider>(context);
|
||||
// final formatCurrency =
|
||||
// new NumberFormat.simpleCurrency(decimalDigits: 0, locale: 'id_ID');
|
||||
bool isRatingValid = int.tryParse(rating) != null;
|
||||
bool isStudentsValid = int.tryParse(students) != null;
|
||||
final themeProvider = Provider.of<ThemeProvider>(context);
|
||||
|
||||
bool isPopular = false;
|
||||
if (isRatingValid && isStudentsValid) {
|
||||
int ratingValue = int.parse(rating);
|
||||
int studentsValue = int.parse(students);
|
||||
|
||||
bool isSpecificRatingValid = int.tryParse(specificRating) != null;
|
||||
bool isNumberOfRatingsValid = int.tryParse(numberOfRatings) != null;
|
||||
|
||||
if (isSpecificRatingValid && isNumberOfRatingsValid) {
|
||||
int specificRatingValue = int.parse(specificRating);
|
||||
int numberOfRatingsValue = int.parse(numberOfRatings);
|
||||
|
||||
isPopular = ratingValue > 4 &&
|
||||
studentsValue > 19 &&
|
||||
specificRatingValue > 4 &&
|
||||
numberOfRatingsValue > 4;
|
||||
}
|
||||
}
|
||||
return Stack(
|
||||
children: [
|
||||
Container(
|
||||
width: getProportionateScreenWidth(155),
|
||||
decoration: BoxDecoration(
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.1),
|
||||
spreadRadius: 1,
|
||||
blurRadius: 1,
|
||||
offset: Offset(7, 17),
|
||||
),
|
||||
],
|
||||
),
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(pad),
|
||||
right: getProportionateScreenWidth(padRight),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: press,
|
||||
child: Container(
|
||||
width: getProportionateScreenWidth(40),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
spreadRadius: 11,
|
||||
blurRadius: 0,
|
||||
offset: Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 1.7,
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: thumbnail,
|
||||
imageBuilder: (context, imageProvider) => Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
BorderRadius.vertical(top: Radius.circular(5)),
|
||||
image: DecorationImage(
|
||||
image: imageProvider,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
placeholder: (context, url) => Shimmer(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: ninthColor,
|
||||
borderRadius:
|
||||
BorderRadius.vertical(top: Radius.circular(5)),
|
||||
),
|
||||
),
|
||||
gradient: LinearGradient(
|
||||
stops: [0.2, 0.5, 0.6],
|
||||
colors: [ninthColor, fourthColor, ninthColor]),
|
||||
),
|
||||
errorWidget: (context, url, error) => Icon(Icons.error),
|
||||
fadeInDuration: Duration(milliseconds: 1),
|
||||
fadeOutDuration: Duration(milliseconds: 1),
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(4)),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 2),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontSize: getProportionateScreenWidth(12),
|
||||
fontWeight: bold),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
// Row(
|
||||
// children: [product.description],
|
||||
// ),
|
||||
RichText(
|
||||
text: new TextSpan(
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
color: Theme.of(context).dividerColor,
|
||||
),
|
||||
children: <TextSpan>[
|
||||
new TextSpan(
|
||||
text: '',
|
||||
style: TextStyle(
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
new TextSpan(
|
||||
text: instructorName,
|
||||
style: TextStyle(fontWeight: bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
specificRating,
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: getProportionateScreenWidth(2),
|
||||
),
|
||||
RatingBarIndicator(
|
||||
itemSize: getProportionateScreenWidth(11),
|
||||
rating: double.parse(rating),
|
||||
direction: Axis.horizontal,
|
||||
itemCount: 5,
|
||||
itemBuilder: (context, _) => FaIcon(
|
||||
FontAwesomeIcons.solidStar,
|
||||
color: thirteenColor,
|
||||
),
|
||||
),
|
||||
SizedBox(width: getProportionateScreenWidth(3)),
|
||||
Text(
|
||||
'(' + numberOfRatings + ')',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
price,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
fontSize: SizeConfig.blockHorizontal! * 3,
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
if (realPrice.isNotEmpty && realPrice != price)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(10)),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
realPrice,
|
||||
style: primaryTextStyle.copyWith(
|
||||
decoration: TextDecoration.lineThrough,
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
fontWeight: reguler,
|
||||
),
|
||||
),
|
||||
// IconButton(onPressed: whislistPress, icon: iconWishlist)
|
||||
],
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox.shrink(),
|
||||
if (isPopular)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(10),
|
||||
),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
width: getProportionateScreenWidth(48),
|
||||
height: getProportionateScreenHeight(17),
|
||||
child: Text(
|
||||
'Populer',
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
color: Colors.white,
|
||||
fontSize: SizeConfig.blockHorizontal! * 2.5,
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color:themeProvider.themeData == ThemeClass.darkmode
|
||||
?primaryColor : primaryColorligtmode,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox.shrink(),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (totalDiscount != 0)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: getProportionateScreenHeight(7)),
|
||||
child: Container(
|
||||
height: 20,
|
||||
alignment: Alignment.center,
|
||||
width: getProportionateScreenWidth(35),
|
||||
child: Text(
|
||||
'${totalDiscount.toString()}%',
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
color: baruTextutih,
|
||||
fontSize: SizeConfig.blockHorizontal! * 2.5,
|
||||
fontWeight: light,
|
||||
),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: themeProvider.themeData == ThemeClass.darkmode
|
||||
?primaryColor : primaryColorligtmode,
|
||||
borderRadius: BorderRadius.only(
|
||||
topRight: Radius.circular(4),
|
||||
bottomRight: Radius.circular(4),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox.shrink(),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Shimmer(
|
||||
// child: Container(
|
||||
// color: Colors.black,
|
||||
// ),
|
||||
// gradient: LinearGradient(
|
||||
// stops: [0.2, 0.5, 0.6],
|
||||
// colors: [ninthColor, fourthColor, ninthColor])),
|
@ -0,0 +1,329 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
import '../../../../../theme.dart';
|
||||
import '../../../../../size_config.dart';
|
||||
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
||||
|
||||
class ProductCardBig extends StatelessWidget {
|
||||
const ProductCardBig({
|
||||
Key? key,
|
||||
this.width = 120,
|
||||
this.pad = 16,
|
||||
this.padRight = 0,
|
||||
required this.thumbnail,
|
||||
required this.id,
|
||||
required this.isTopCourse,
|
||||
required this.title,
|
||||
required this.instructorName,
|
||||
required this.rating,
|
||||
required this.specificRating,
|
||||
required this.numberOfRatings,
|
||||
required this.price,
|
||||
required this.realPrice,
|
||||
required this.press,
|
||||
required this.students,
|
||||
required this.totalDiscount,
|
||||
}) : super(key: key);
|
||||
|
||||
final double width;
|
||||
final double pad, padRight;
|
||||
final String thumbnail,
|
||||
title,
|
||||
instructorName,
|
||||
price,
|
||||
realPrice,
|
||||
rating,
|
||||
specificRating,
|
||||
numberOfRatings,
|
||||
id,
|
||||
isTopCourse;
|
||||
final String students;
|
||||
final VoidCallback press;
|
||||
final int totalDiscount;
|
||||
// final VoidCallback? whislistPress;
|
||||
// final Widget? iconWishlist;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//CourseProvider courseProvider = Provider.of<CourseProvider>(context);
|
||||
// final formatCurrency =
|
||||
// new NumberFormat.simpleCurrency(decimalDigits: 0, locale: 'id_ID');
|
||||
bool isRatingValid = int.tryParse(rating) != null;
|
||||
bool isStudentsValid = int.tryParse(students) != null;
|
||||
|
||||
bool isPopular = false;
|
||||
if (isRatingValid && isStudentsValid) {
|
||||
int ratingValue = int.parse(rating);
|
||||
int studentsValue = int.parse(students);
|
||||
|
||||
bool isSpecificRatingValid = int.tryParse(specificRating) != null;
|
||||
bool isNumberOfRatingsValid = int.tryParse(numberOfRatings) != null;
|
||||
|
||||
if (isSpecificRatingValid && isNumberOfRatingsValid) {
|
||||
int specificRatingValue = int.parse(specificRating);
|
||||
int numberOfRatingsValue = int.parse(numberOfRatings);
|
||||
|
||||
isPopular = ratingValue > 4 &&
|
||||
studentsValue > 19 &&
|
||||
specificRatingValue > 4 &&
|
||||
numberOfRatingsValue > 4;
|
||||
}
|
||||
}
|
||||
return Stack(
|
||||
children: [
|
||||
Container(
|
||||
height: getProportionateScreenHeight(500),
|
||||
width: getProportionateScreenWidth(250),
|
||||
decoration: BoxDecoration(
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.1),
|
||||
spreadRadius: 1,
|
||||
blurRadius: 1,
|
||||
offset: Offset(7, 17),
|
||||
),
|
||||
],
|
||||
),
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(pad),
|
||||
right: getProportionateScreenWidth(padRight),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: press,
|
||||
child: Container(
|
||||
width: getProportionateScreenWidth(40),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
spreadRadius: 11,
|
||||
blurRadius: 0,
|
||||
offset: Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 1.7,
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: thumbnail,
|
||||
imageBuilder: (context, imageProvider) => Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
BorderRadius.vertical(top: Radius.circular(5)),
|
||||
image: DecorationImage(
|
||||
image: imageProvider,
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
),
|
||||
),
|
||||
placeholder: (context, url) => Shimmer(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: ninthColor,
|
||||
borderRadius:
|
||||
BorderRadius.vertical(top: Radius.circular(5)),
|
||||
),
|
||||
),
|
||||
gradient: LinearGradient(
|
||||
stops: [0.2, 0.5, 0.6],
|
||||
colors: [ninthColor, fourthColor, ninthColor]),
|
||||
),
|
||||
errorWidget: (context, url, error) => Icon(Icons.error),
|
||||
fadeInDuration: Duration(milliseconds: 1),
|
||||
fadeOutDuration: Duration(milliseconds: 1),
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(4)),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 2),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontSize: getProportionateScreenWidth(13),
|
||||
fontWeight: bold),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
// Row(
|
||||
// children: [product.description],
|
||||
// ),
|
||||
RichText(
|
||||
text: new TextSpan(
|
||||
style: primaryTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(11),
|
||||
color: Theme.of(context).dividerColor,
|
||||
),
|
||||
children: [
|
||||
new TextSpan(
|
||||
text: '',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontWeight: reguler,
|
||||
),
|
||||
),
|
||||
new TextSpan(
|
||||
text: instructorName,
|
||||
style: TextStyle(fontWeight: bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
specificRating,
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(11),
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: getProportionateScreenWidth(2),
|
||||
),
|
||||
RatingBarIndicator(
|
||||
itemSize: getProportionateScreenWidth(12),
|
||||
rating: double.parse(rating),
|
||||
direction: Axis.horizontal,
|
||||
itemCount: 1,
|
||||
itemBuilder: (context, _) => FaIcon(
|
||||
FontAwesomeIcons.solidStar,
|
||||
color: thirteenColor,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: getProportionateScreenWidth(3),
|
||||
),
|
||||
Text(
|
||||
'(' + numberOfRatings + ' Reviews)',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(11),
|
||||
fontWeight: light,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: getProportionateScreenWidth(6),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
price,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
fontSize: SizeConfig.blockHorizontal! * 3,
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
(realPrice != price)
|
||||
? Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(10)),
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
realPrice,
|
||||
style: thirdTextStyle.copyWith(
|
||||
decoration: TextDecoration.lineThrough,
|
||||
fontSize:
|
||||
getProportionateScreenWidth(10),
|
||||
fontWeight: reguler,
|
||||
),
|
||||
),
|
||||
|
||||
// IconButton(
|
||||
// onPressed: whislistPress,
|
||||
// icon: iconWishlist)
|
||||
],
|
||||
),
|
||||
)
|
||||
: SizedBox(height: 13, width: 1),
|
||||
if (isPopular)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(10)),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
width: getProportionateScreenWidth(48),
|
||||
height: getProportionateScreenHeight(17),
|
||||
child: Text(
|
||||
'Populer',
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
color: Colors.white,
|
||||
fontSize: SizeConfig.blockHorizontal! * 2.5,
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: primaryColor,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox(height: 0, width: 0),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (totalDiscount != 0)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: getProportionateScreenHeight(7)),
|
||||
child: Container(
|
||||
height: 20,
|
||||
alignment: Alignment.center,
|
||||
width: getProportionateScreenWidth(35),
|
||||
child: Text(
|
||||
'${totalDiscount.toString()}%',
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
color: baruTextutih,
|
||||
fontSize: SizeConfig.blockHorizontal! * 2.5,
|
||||
fontWeight: light,
|
||||
),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: primaryColor,
|
||||
borderRadius: BorderRadius.only(
|
||||
topRight: Radius.circular(4),
|
||||
bottomRight: Radius.circular(4),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox(height: 0, width: 0),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Shimmer(
|
||||
// child: Container(
|
||||
// color: Colors.black,
|
||||
// ),
|
||||
// gradient: LinearGradient(
|
||||
// stops: [0.2, 0.5, 0.6],
|
||||
// colors: [ninthColor, fourthColor, ninthColor])),
|
@ -0,0 +1,320 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
import '../../../../../theme.dart';
|
||||
import '../../../../../size_config.dart';
|
||||
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
||||
|
||||
class ProductCardCoupon extends StatelessWidget {
|
||||
const ProductCardCoupon({
|
||||
Key? key,
|
||||
this.width = 120,
|
||||
this.pad = 16,
|
||||
this.padRight = 0,
|
||||
required this.thumbnail,
|
||||
required this.id,
|
||||
required this.isTopCourse,
|
||||
required this.title,
|
||||
required this.instructorName,
|
||||
required this.rating,
|
||||
required this.specificRating,
|
||||
required this.numberOfRatings,
|
||||
required this.price,
|
||||
required this.realPrice,
|
||||
required this.press,
|
||||
required this.students,
|
||||
required this.totalDiscount,
|
||||
}) : super(key: key);
|
||||
|
||||
final double width;
|
||||
final double pad, padRight;
|
||||
final String thumbnail,
|
||||
title,
|
||||
instructorName,
|
||||
price,
|
||||
realPrice,
|
||||
rating,
|
||||
specificRating,
|
||||
numberOfRatings,
|
||||
id,
|
||||
isTopCourse;
|
||||
final String students;
|
||||
final VoidCallback press;
|
||||
final int totalDiscount;
|
||||
// final VoidCallback? whislistPress;
|
||||
// final Widget? iconWishlist;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//CourseProvider courseProvider = Provider.of<CourseProvider>(context);
|
||||
// final formatCurrency =
|
||||
// new NumberFormat.simpleCurrency(decimalDigits: 0, locale: 'id_ID');
|
||||
bool isRatingValid = int.tryParse(rating) != null;
|
||||
bool isStudentsValid = int.tryParse(students) != null;
|
||||
|
||||
bool isPopular = false;
|
||||
if (isRatingValid && isStudentsValid) {
|
||||
int ratingValue = int.parse(rating);
|
||||
int studentsValue = int.parse(students);
|
||||
|
||||
bool isSpecificRatingValid = int.tryParse(specificRating) != null;
|
||||
bool isNumberOfRatingsValid = int.tryParse(numberOfRatings) != null;
|
||||
|
||||
if (isSpecificRatingValid && isNumberOfRatingsValid) {
|
||||
int specificRatingValue = int.parse(specificRating);
|
||||
int numberOfRatingsValue = int.parse(numberOfRatings);
|
||||
|
||||
isPopular = ratingValue > 4 &&
|
||||
studentsValue > 19 &&
|
||||
specificRatingValue > 4 &&
|
||||
numberOfRatingsValue > 4;
|
||||
}
|
||||
}
|
||||
return Stack(
|
||||
children: [
|
||||
Container(
|
||||
width: getProportionateScreenWidth(165),
|
||||
decoration: BoxDecoration(
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.1),
|
||||
spreadRadius: 1,
|
||||
blurRadius: 1,
|
||||
offset: Offset(7, 17),
|
||||
),
|
||||
],
|
||||
),
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(pad),
|
||||
right: getProportionateScreenWidth(padRight),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: press,
|
||||
child: Container(
|
||||
width: getProportionateScreenWidth(40),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
spreadRadius: 11,
|
||||
blurRadius: 0,
|
||||
offset: Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 1.7,
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: thumbnail,
|
||||
imageBuilder: (context, imageProvider) => Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
BorderRadius.vertical(top: Radius.circular(5)),
|
||||
image: DecorationImage(
|
||||
image: imageProvider,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
placeholder: (context, url) => Shimmer(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: ninthColor,
|
||||
borderRadius:
|
||||
BorderRadius.vertical(top: Radius.circular(5)),
|
||||
),
|
||||
),
|
||||
gradient: LinearGradient(
|
||||
stops: [0.2, 0.5, 0.6],
|
||||
colors: [ninthColor, fourthColor, ninthColor]),
|
||||
),
|
||||
errorWidget: (context, url, error) => Icon(Icons.error),
|
||||
fadeInDuration: Duration(milliseconds: 1),
|
||||
fadeOutDuration: Duration(milliseconds: 1),
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(4)),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 2),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontSize: getProportionateScreenWidth(12),
|
||||
fontWeight: bold),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
// Row(
|
||||
// children: [product.description],
|
||||
// ),
|
||||
RichText(
|
||||
text: new TextSpan(
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
color: Theme.of(context).dividerColor,
|
||||
),
|
||||
children: <TextSpan>[
|
||||
new TextSpan(
|
||||
text: '',
|
||||
style: TextStyle(
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
new TextSpan(
|
||||
text: instructorName,
|
||||
style: TextStyle(fontWeight: bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
specificRating,
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: getProportionateScreenWidth(2),
|
||||
),
|
||||
RatingBarIndicator(
|
||||
itemSize: getProportionateScreenWidth(11),
|
||||
rating: double.parse(rating),
|
||||
direction: Axis.horizontal,
|
||||
itemCount: 5,
|
||||
itemBuilder: (context, _) => FaIcon(
|
||||
FontAwesomeIcons.solidStar,
|
||||
color: thirteenColor,
|
||||
),
|
||||
),
|
||||
SizedBox(width: getProportionateScreenWidth(3)),
|
||||
Text(
|
||||
'(' + numberOfRatings + ')',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
price,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
fontSize: SizeConfig.blockHorizontal! * 3,
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
if (realPrice.isNotEmpty && realPrice != price)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(10)),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
realPrice,
|
||||
style: primaryTextStyle.copyWith(
|
||||
decoration: TextDecoration.lineThrough,
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
fontWeight: reguler,
|
||||
),
|
||||
),
|
||||
// IconButton(onPressed: whislistPress, icon: iconWishlist)
|
||||
],
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox.shrink(),
|
||||
if (isPopular)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(10)),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
width: getProportionateScreenWidth(48),
|
||||
height: getProportionateScreenHeight(17),
|
||||
child: Text(
|
||||
'Populer',
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
color: Colors.white,
|
||||
fontSize: SizeConfig.blockHorizontal! * 2.5,
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: primaryColor,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox(height: 0, width: 0),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (totalDiscount != 0)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: getProportionateScreenHeight(7)),
|
||||
child: Container(
|
||||
height: 20,
|
||||
alignment: Alignment.center,
|
||||
width: getProportionateScreenWidth(35),
|
||||
child: Text(
|
||||
'${totalDiscount.toString()}%',
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
color: baruTextutih,
|
||||
fontSize: SizeConfig.blockHorizontal! * 2.5,
|
||||
fontWeight: light,
|
||||
),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: primaryColor,
|
||||
borderRadius: BorderRadius.only(
|
||||
topRight: Radius.circular(4),
|
||||
bottomRight: Radius.circular(4),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox(height: 0, width: 0),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Shimmer(
|
||||
// child: Container(
|
||||
// color: Colors.black,
|
||||
// ),
|
||||
// gradient: LinearGradient(
|
||||
// stops: [0.2, 0.5, 0.6],
|
||||
// colors: [ninthColor, fourthColor, ninthColor])),
|
@ -0,0 +1,328 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
import '../../../../../providers/theme_provider.dart';
|
||||
import '../../../../../theme.dart';
|
||||
import '../../../../../size_config.dart';
|
||||
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
|
||||
|
||||
class ProductCardNew extends StatelessWidget {
|
||||
const ProductCardNew({
|
||||
Key? key,
|
||||
this.width = 120,
|
||||
this.pad = 16,
|
||||
this.padRight = 0,
|
||||
required this.thumbnail,
|
||||
required this.id,
|
||||
required this.isTopCourse,
|
||||
required this.title,
|
||||
required this.instructorName,
|
||||
required this.rating,
|
||||
required this.specificRating,
|
||||
required this.numberOfRatings,
|
||||
required this.price,
|
||||
required this.realPrice,
|
||||
required this.press,
|
||||
required this.students,
|
||||
required this.totalDiscount,
|
||||
}) : super(key: key);
|
||||
|
||||
final double width;
|
||||
final double pad, padRight;
|
||||
final String thumbnail,
|
||||
title,
|
||||
instructorName,
|
||||
price,
|
||||
realPrice,
|
||||
rating,
|
||||
specificRating,
|
||||
numberOfRatings,
|
||||
id,
|
||||
isTopCourse;
|
||||
final String students;
|
||||
final VoidCallback press;
|
||||
final int totalDiscount;
|
||||
// final VoidCallback? whislistPress;
|
||||
// final Widget? iconWishlist;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//CourseProvider courseProvider = Provider.of<CourseProvider>(context);
|
||||
// final formatCurrency =
|
||||
// new NumberFormat.simpleCurrency(decimalDigits: 0, locale: 'id_ID');
|
||||
bool isRatingValid = int.tryParse(rating) != null;
|
||||
bool isStudentsValid = int.tryParse(students) != null;
|
||||
final themeProvider = Provider.of<ThemeProvider>(context);
|
||||
|
||||
bool isPopular = false;
|
||||
if (isRatingValid && isStudentsValid) {
|
||||
int ratingValue = int.parse(rating);
|
||||
int studentsValue = int.parse(students);
|
||||
|
||||
bool isSpecificRatingValid = int.tryParse(specificRating) != null;
|
||||
bool isNumberOfRatingsValid = int.tryParse(numberOfRatings) != null;
|
||||
|
||||
if (isSpecificRatingValid && isNumberOfRatingsValid) {
|
||||
int specificRatingValue = int.parse(specificRating);
|
||||
int numberOfRatingsValue = int.parse(numberOfRatings);
|
||||
|
||||
isPopular = ratingValue > 4 &&
|
||||
studentsValue > 19 &&
|
||||
specificRatingValue > 4 &&
|
||||
numberOfRatingsValue > 4;
|
||||
}
|
||||
}
|
||||
return Stack(
|
||||
children: [
|
||||
Container(
|
||||
width: getProportionateScreenWidth(155),
|
||||
height: getProportionateScreenHeight(200),
|
||||
decoration: BoxDecoration(
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.1),
|
||||
spreadRadius: 1,
|
||||
blurRadius: 1,
|
||||
offset: Offset(7, 17),
|
||||
),
|
||||
],
|
||||
),
|
||||
padding: EdgeInsets.only(
|
||||
left: getProportionateScreenWidth(pad),
|
||||
right: getProportionateScreenWidth(padRight),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: press,
|
||||
child: Container(
|
||||
width: getProportionateScreenWidth(40),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
spreadRadius: 11,
|
||||
blurRadius: 0,
|
||||
offset: Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 1.7,
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: thumbnail,
|
||||
imageBuilder: (context, imageProvider) => Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius:
|
||||
BorderRadius.vertical(top: Radius.circular(5)),
|
||||
image: DecorationImage(
|
||||
image: imageProvider,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
placeholder: (context, url) => Shimmer(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: ninthColor,
|
||||
borderRadius:
|
||||
BorderRadius.vertical(top: Radius.circular(5)),
|
||||
),
|
||||
),
|
||||
gradient: LinearGradient(
|
||||
stops: [0.2, 0.5, 0.6],
|
||||
colors: [ninthColor, fourthColor, ninthColor]),
|
||||
),
|
||||
errorWidget: (context, url, error) => Icon(Icons.error),
|
||||
fadeInDuration: Duration(milliseconds: 1),
|
||||
fadeOutDuration: Duration(milliseconds: 1),
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(4)),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 2),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontSize: getProportionateScreenWidth(12),
|
||||
fontWeight: bold),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
// Row(
|
||||
// children: [product.description],
|
||||
// ),
|
||||
RichText(
|
||||
text: new TextSpan(
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
color: Theme.of(context).dividerColor,
|
||||
),
|
||||
children: <TextSpan>[
|
||||
new TextSpan(
|
||||
text: '',
|
||||
style: TextStyle(
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
new TextSpan(
|
||||
text: instructorName,
|
||||
style: TextStyle(fontWeight: bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
Row(
|
||||
children: [
|
||||
if (specificRating.isNotEmpty && specificRating != '0') ...[
|
||||
Text(
|
||||
specificRating,
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: getProportionateScreenWidth(2),
|
||||
),],
|
||||
RatingBarIndicator(
|
||||
itemSize: getProportionateScreenWidth(11),
|
||||
rating: (rating.isEmpty || double.tryParse(rating) == 0)
|
||||
? 5.0
|
||||
: double.parse(rating), // Jika rating kosong atau 0, tampilkan bintang 5
|
||||
direction: Axis.horizontal,
|
||||
itemCount: 5,
|
||||
itemBuilder: (context, _) => FaIcon(
|
||||
FontAwesomeIcons.solidStar,
|
||||
color: thirteenColor,
|
||||
),
|
||||
),
|
||||
SizedBox(width: getProportionateScreenWidth(3)),
|
||||
if (numberOfRatings.isNotEmpty && numberOfRatings != '0') ...[
|
||||
Text(
|
||||
'(' + numberOfRatings + ')',
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
price,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
fontSize: SizeConfig.blockHorizontal! * 3,
|
||||
fontWeight: bold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: getProportionateScreenWidth(6)),
|
||||
if (realPrice.isNotEmpty && realPrice != price)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(10)),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
realPrice,
|
||||
style: primaryTextStyle.copyWith(
|
||||
decoration: TextDecoration.lineThrough,
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
fontWeight: reguler,
|
||||
),
|
||||
),
|
||||
// IconButton(onPressed: whislistPress, icon: iconWishlist)
|
||||
],
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox.shrink(),
|
||||
Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(10)),
|
||||
child: Container(
|
||||
alignment: Alignment.center,
|
||||
width: getProportionateScreenWidth(48),
|
||||
height: getProportionateScreenHeight(17),
|
||||
child: Text(
|
||||
'NEW',
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
color: Colors.white,
|
||||
fontSize: SizeConfig.blockHorizontal! * 3,
|
||||
fontWeight: reguler,
|
||||
),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: themeProvider.themeData == ThemeClass.darkmode
|
||||
?primaryColor : primaryColorligtmode,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (totalDiscount != 0)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(top: getProportionateScreenHeight(7)),
|
||||
child: Container(
|
||||
height: 20,
|
||||
alignment: Alignment.center,
|
||||
width: getProportionateScreenWidth(35),
|
||||
child: Text(
|
||||
'${totalDiscount.toString()}%',
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
color: baruTextutih,
|
||||
fontSize: SizeConfig.blockHorizontal! * 2.5,
|
||||
fontWeight: light,
|
||||
),
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: themeProvider.themeData == ThemeClass.darkmode
|
||||
?primaryColor : primaryColorligtmode,
|
||||
borderRadius: BorderRadius.only(
|
||||
topRight: Radius.circular(4),
|
||||
bottomRight: Radius.circular(4),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
SizedBox(height: 0, width: 0),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Shimmer(
|
||||
// child: Container(
|
||||
// color: Colors.black,
|
||||
// ),
|
||||
// gradient: LinearGradient(
|
||||
// stops: [0.2, 0.5, 0.6],
|
||||
// colors: [ninthColor, fourthColor, ninthColor])),
|
@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/models/ProductProgram.dart';
|
||||
import '../../../../../theme.dart';
|
||||
import '../../../../../size_config.dart';
|
||||
|
||||
class ProductCardProgram extends StatelessWidget {
|
||||
const ProductCardProgram({
|
||||
Key? key,
|
||||
this.width = 150,
|
||||
this.aspectRetio = 1.02,
|
||||
required this.product,
|
||||
}) : super(key: key);
|
||||
|
||||
final double width, aspectRetio;
|
||||
final ProductProgram product;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.fromLTRB(0, getProportionateScreenWidth(10),
|
||||
getProportionateScreenWidth(10), getProportionateScreenWidth(10)),
|
||||
child: SizedBox(
|
||||
width: getProportionateScreenWidth(width),
|
||||
child: GestureDetector(
|
||||
onTap: () {},
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 1.7,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: tenthColor.withOpacity(0),
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
),
|
||||
child: Hero(
|
||||
tag: product.id.toString(),
|
||||
child: Image.asset(product.images[0], scale: 0.000000001),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
44
lib/screens/home/components/body_comp/program.dart
Normal file
44
lib/screens/home/components/body_comp/program.dart
Normal file
@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'product_card/product_card_program.dart';
|
||||
import 'package:initial_folder/models/ProductProgram.dart';
|
||||
|
||||
import '../../../../size_config.dart';
|
||||
import '../../../../theme.dart';
|
||||
|
||||
class Program extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(20)),
|
||||
child: Row(mainAxisAlignment: MainAxisAlignment.start, children: [
|
||||
Text('Promo Terkini',
|
||||
textAlign: TextAlign.left,
|
||||
style: secondaryTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
color: tenthColor,
|
||||
fontSize: getProportionateScreenWidth(14),
|
||||
fontWeight: semiBold)),
|
||||
]),
|
||||
),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(20)),
|
||||
child: Row(
|
||||
children: [
|
||||
...List.generate(
|
||||
demoProducts.length,
|
||||
(index) => ProductCardProgram(product: demoProducts[index]),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
364
lib/screens/home/components/body_comp/promo_course.dart
Normal file
364
lib/screens/home/components/body_comp/promo_course.dart
Normal file
@ -0,0 +1,364 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_html/flutter_html.dart';
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/helper/validator.dart';
|
||||
import 'package:initial_folder/providers/promo_course_provider.dart';
|
||||
// import 'package:initial_folder/providers/top_course_provider.dart';
|
||||
import 'package:initial_folder/screens/detail_course/detail_course_screen.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/product_card/product_card.dart';
|
||||
import 'package:initial_folder/widgets/custom_navigator.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
|
||||
import '../../../../size_config.dart';
|
||||
import '../../../../theme.dart';
|
||||
|
||||
class PromoCourse extends StatelessWidget {
|
||||
const PromoCourse({Key? key, this.text}) : super(key: key);
|
||||
final String? text;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding:
|
||||
EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(16)),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
text.toString(),
|
||||
textAlign: TextAlign.left,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontSize: getProportionateScreenWidth(15),
|
||||
fontWeight: semiBold,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(10)),
|
||||
Consumer<PromoCourseProvider>(
|
||||
builder: (context, state, _) {
|
||||
if (state.state == ResultState.Loading) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
} else if (state.state == ResultState.HasData) {
|
||||
return Container(
|
||||
alignment: Alignment.centerLeft,
|
||||
margin: EdgeInsets.only(left: getProportionateScreenWidth(10)),
|
||||
height: getProportionateScreenHeight(220),
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
physics: ScrollPhysics(),
|
||||
shrinkWrap: true,
|
||||
itemCount: state.result.length,
|
||||
itemBuilder: (context, index) {
|
||||
var promoCourse = state.result[index];
|
||||
// var finalRating = double.parse(
|
||||
// (promoCourse.specificRating![0] / 20).toStringAsFixed(2));
|
||||
int price =
|
||||
int.tryParse(promoCourse.price.replaceAll('.', '')) ??
|
||||
0;
|
||||
int discountPrice = int.tryParse(
|
||||
promoCourse.discountPrice.replaceAll('.', '')) ??
|
||||
0;
|
||||
|
||||
int calculatedPrice = (promoCourse.discountPrice != '0')
|
||||
? price - discountPrice
|
||||
: price;
|
||||
|
||||
String displayedPrice = (calculatedPrice == 0)
|
||||
? promoCourse.price
|
||||
: calculatedPrice.toString();
|
||||
return Container(
|
||||
margin: EdgeInsets.only(
|
||||
top: getProportionateScreenHeight(10),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(
|
||||
right: getProportionateScreenWidth(18),
|
||||
bottom: getProportionateScreenWidth(18),
|
||||
),
|
||||
child: ProductCard(
|
||||
totalDiscount: promoCourse.totalDiscount ?? 0,
|
||||
students: promoCourse.students ?? '0',
|
||||
pad: 12,
|
||||
id: promoCourse.idCourse,
|
||||
thumbnail: promoCourse.thumbnail ??
|
||||
'$baseUrl/uploads/courses_thumbnail/course_thumbnail_default_57.jpg',
|
||||
title: promoCourse.title,
|
||||
instructorName: promoCourse.instructorName,
|
||||
specificRating: (promoCourse.rating.isNotEmpty &&
|
||||
promoCourse.rating[0]?.avgRating != null)
|
||||
? promoCourse.rating[0]!.avgRating.toString()
|
||||
: '0',
|
||||
rating: (promoCourse.rating.isNotEmpty &&
|
||||
promoCourse.rating[0]?.avgRating != null)
|
||||
? promoCourse.rating[0]!.avgRating.toString()
|
||||
: '5.0',
|
||||
numberOfRatings: (promoCourse.rating.isNotEmpty &&
|
||||
promoCourse.rating[0]?.totalReview != null)
|
||||
? promoCourse.rating[0]!.totalReview!
|
||||
: '0',
|
||||
isTopCourse: promoCourse.topCourse!,
|
||||
price: (promoCourse.price == '0')
|
||||
? 'Gratis'
|
||||
: (promoCourse.promoPrice != '0')
|
||||
? numberFormat(promoCourse.promoPrice)
|
||||
: numberFormat(displayedPrice),
|
||||
realPrice: (promoCourse.price == '0')
|
||||
? ''
|
||||
: numberFormat(promoCourse.price),
|
||||
press: () {
|
||||
print(promoCourse.idCourse);
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
CustomNavigator(
|
||||
child: DetailCourseScreen(
|
||||
isPromo: true,
|
||||
idcourse: promoCourse.idCourse,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
} else if (state.state == ResultState.NoData) {
|
||||
return Center(child: Text(state.message));
|
||||
} else if (state.state == ResultState.Error) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(20, 0, 0, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 105,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 190,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 10),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 120,
|
||||
color: Colors.white,
|
||||
)),
|
||||
SizedBox(height: 8),
|
||||
Shimmer.fromColors(
|
||||
baseColor: Colors.white,
|
||||
highlightColor: Colors.grey,
|
||||
child: Container(
|
||||
height: 15,
|
||||
width: 85,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
],
|
||||
);
|
||||
} else {
|
||||
return Center(child: Text(''));
|
||||
}
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
41
lib/screens/home/components/body_comp/recommendation.dart
Normal file
41
lib/screens/home/components/body_comp/recommendation.dart
Normal file
@ -0,0 +1,41 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'product_card/product_card.dart';
|
||||
// import 'package:initial_folder/models/Product.dart';
|
||||
|
||||
// import '../../../../size_config.dart';
|
||||
// import 'section_title.dart';
|
||||
|
||||
// class Recommendation extends StatelessWidget {
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Column(
|
||||
// children: [
|
||||
// Padding(
|
||||
// padding:
|
||||
// EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(20)),
|
||||
// child: SectionTitle(title: "Rekomendasi Khusus", press: () {}),
|
||||
// ),
|
||||
// SizedBox(height: 10),
|
||||
// SingleChildScrollView(
|
||||
// scrollDirection: Axis.horizontal,
|
||||
// child: Row(
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: [
|
||||
// ...List.generate(
|
||||
// demoProducts.length,
|
||||
// (index) {
|
||||
// if (demoProducts[index].isPopular)
|
||||
// return ProductCard(product: demoProducts[index]);
|
||||
|
||||
// return SizedBox
|
||||
// .shrink(); // here by default width and height is 0
|
||||
// },
|
||||
// ),
|
||||
// SizedBox(width: getProportionateScreenWidth(200)),
|
||||
// ],
|
||||
// ),
|
||||
// )
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
// }
|
61
lib/screens/home/components/body_comp/search_field.dart
Normal file
61
lib/screens/home/components/body_comp/search_field.dart
Normal file
@ -0,0 +1,61 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/widgets/search_and_filter_course.dart';
|
||||
import '../../../../theme.dart';
|
||||
import '../../../../size_config.dart';
|
||||
|
||||
class SearchField extends StatelessWidget {
|
||||
const SearchField({
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// width: SizeConfig.screenWidth * 0.9,
|
||||
// height: 33,
|
||||
// decoration: BoxDecoration(
|
||||
// color: Colors.white,
|
||||
// borderRadius: BorderRadius.circular(15),
|
||||
// border: Border.all(
|
||||
// color: kSecondaryColor.withOpacity(0.5),
|
||||
// width: 2,
|
||||
//print(SizeConfig.screenWidth);
|
||||
return GestureDetector(
|
||||
onTap: () => Navigator.push(context,
|
||||
MaterialPageRoute(builder: (context) => SearchAndFilterCourse())),
|
||||
child: Container(
|
||||
margin:
|
||||
EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(16)),
|
||||
height: 35,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: secondaryColor)),
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 13),
|
||||
child: Icon(
|
||||
Icons.search,
|
||||
size: 20,
|
||||
color: secondaryColor,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: getProportionateScreenWidth(10),
|
||||
),
|
||||
Text(
|
||||
'Cari kursus',
|
||||
style: secondaryTextStyle.copyWith(
|
||||
color: secondaryColor, fontSize: 12),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
41
lib/screens/home/components/body_comp/section_title.dart
Normal file
41
lib/screens/home/components/body_comp/section_title.dart
Normal file
@ -0,0 +1,41 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../../size_config.dart';
|
||||
import '../../../../theme.dart';
|
||||
|
||||
class SectionTitle extends StatelessWidget {
|
||||
const SectionTitle({
|
||||
Key? key,
|
||||
required this.title,
|
||||
required this.press,
|
||||
}) : super(key: key);
|
||||
|
||||
final String title;
|
||||
final GestureTapCallback press;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontSize: getProportionateScreenWidth(15),
|
||||
fontWeight: semiBold),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: press,
|
||||
child: Text(
|
||||
"Lihat Semua",
|
||||
style: thirdTextStyle.copyWith(
|
||||
letterSpacing: 0.5,
|
||||
fontSize: getProportionateScreenWidth(11),
|
||||
fontWeight: reguler),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
279
lib/screens/home/components/home_page.dart
Normal file
279
lib/screens/home/components/home_page.dart
Normal file
@ -0,0 +1,279 @@
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/providers/banners_provider.dart';
|
||||
import 'package:initial_folder/providers/carts_provider.dart';
|
||||
import 'package:initial_folder/providers/categories_provider.dart';
|
||||
import 'package:initial_folder/providers/course_by_category_provider.dart';
|
||||
import 'package:initial_folder/providers/detail_course_provider.dart';
|
||||
import 'package:initial_folder/providers/latest_course_provider.dart';
|
||||
import 'package:initial_folder/providers/lesson_course_provider.dart';
|
||||
import 'package:initial_folder/providers/others_course_provider.dart';
|
||||
import 'package:initial_folder/providers/promo_course_provider.dart';
|
||||
import 'package:initial_folder/providers/promo_course_provider.dart' as promo;
|
||||
import 'package:initial_folder/providers/top_course_provider.dart';
|
||||
import 'package:initial_folder/screens/cart/cart_page.dart';
|
||||
import 'package:initial_folder/screens/course/play_course_page.dart';
|
||||
import 'package:initial_folder/screens/home/components/appBar/home_header.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/certificate_voucher.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/course_by_category.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/home_categories.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/latest_course.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/lihat_semua_kategori.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/populer_course.dart';
|
||||
import 'package:initial_folder/screens/home/components/body_comp/promo_course.dart';
|
||||
import 'package:initial_folder/services/categories_service.dart';
|
||||
import 'package:initial_folder/services/course_by_category_service.dart';
|
||||
import 'package:initial_folder/services/course_service.dart';
|
||||
import 'package:initial_folder/services/lesson_course_service.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../size_config.dart';
|
||||
import '../../../theme.dart';
|
||||
import 'body_comp/others_course.dart';
|
||||
import 'body_comp/carousel.dart';
|
||||
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
static String routeName = "/homepage";
|
||||
HomePage({
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<HomePage> createState() => _HomePageState();
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> {
|
||||
ScrollController _controller = ScrollController();
|
||||
GlobalKey<NavigatorState> homeKey = GlobalKey<NavigatorState>();
|
||||
@override
|
||||
void initState() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
Provider.of<CartsProvider>(context, listen: false).getCarts();
|
||||
});
|
||||
_controller.addListener(() {
|
||||
onScrol();
|
||||
});
|
||||
super.initState();
|
||||
|
||||
FirebaseMessaging.instance.getInitialMessage().then((message) {
|
||||
if (message?.data['route'] == "/cart") {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => CartPage(),
|
||||
));
|
||||
} else if (message?.data['route'] == "/play_course") {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(
|
||||
create: (context) => LessonCourseProvider(
|
||||
lessonCourseService: LessonCourseService(),
|
||||
id: int.parse(message?.data['id_course'] ?? '0'),
|
||||
),
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create: (context) => DetailCourseProvider(
|
||||
courseService: CourseService(),
|
||||
id: message?.data['id_course'] ?? '1'))
|
||||
],
|
||||
child: PlayCourse(
|
||||
judul: message?.data['title'] ?? '',
|
||||
instruktur: message?.data['instructur_name'] ?? '',
|
||||
thumbnail: message?.data['thumbnail'] ??
|
||||
'$baseUrl/uploads/courses_thumbnail/course_thumbnail_default_57.jpg',
|
||||
courseeid: message?.data['id_course'] ?? '',
|
||||
isQna: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void onScrol() async {
|
||||
double maxScroll = _controller.position.maxScrollExtent;
|
||||
double currentScroll = _controller.position.pixels;
|
||||
if (maxScroll == currentScroll) {
|
||||
await Provider.of<OthersCourseProvider>(context, listen: false)
|
||||
.getOthersCourses();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void onRefresh() async {
|
||||
Provider.of<OthersCourseProvider>(context, listen: false)
|
||||
.getOthersCourses();
|
||||
Provider.of<BannersProvider>(context, listen: false).getAllBanners();
|
||||
Provider.of<PromoCourseProvider>(context, listen: false).getPromoCourse();
|
||||
Provider.of<TopCourseProvider>(context, listen: false).getTopCourse();
|
||||
Provider.of<LatestCourseProvider>(context, listen: false).getLatestCourse();
|
||||
Provider.of<OthersCourseProvider>(context, listen: false).getOthersCourse();
|
||||
setState(() {
|
||||
print('Reloading page...');
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (_controller.hasClients) {
|
||||
if (_controller.position.pixels != _controller.position.maxScrollExtent) {
|
||||
_controller.animateTo(0,
|
||||
duration: Duration(milliseconds: 900), curve: Curves.linear);
|
||||
}
|
||||
}
|
||||
return Navigator(
|
||||
key: homeKey,
|
||||
onGenerateRoute: (RouteSettings settings) {
|
||||
return MaterialPageRoute(
|
||||
settings: settings,
|
||||
builder: (BuildContext context) {
|
||||
if (settings.name == '/lihatSemuaKategori') {
|
||||
return LihatSemuaKategori();
|
||||
}
|
||||
|
||||
return Container(
|
||||
color: Theme.of(context).colorScheme.background,
|
||||
child: SafeArea(
|
||||
child: Scaffold(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
appBar: PreferredSize(
|
||||
preferredSize:
|
||||
Size.fromHeight(getProportionateScreenHeight(60)),
|
||||
child: HomeHeader(),
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
setState(() {
|
||||
print('loding test');
|
||||
onRefresh();
|
||||
});
|
||||
},
|
||||
child: ListView(
|
||||
controller: _controller,
|
||||
children: [
|
||||
SizedBox(height: getProportionateScreenHeight(10)),
|
||||
// Stack(
|
||||
// children: [
|
||||
// // Container(
|
||||
// // height: getProportionateScreenWidth(140),
|
||||
// // decoration: BoxDecoration(
|
||||
// // image: DecorationImage(
|
||||
// // image: AssetImage('assets/images/VectorBG.png'),
|
||||
// // fit: BoxFit.fill,
|
||||
// // alignment: AlignmentDirectional.topCenter,
|
||||
// // ),
|
||||
// // ),
|
||||
// // ),
|
||||
// Container(
|
||||
// padding: EdgeInsets.fromLTRB(
|
||||
// getProportionateScreenWidth(18.0),
|
||||
// getProportionateScreenWidth(11.5),
|
||||
// 0,
|
||||
// 0),
|
||||
// child: Begin()),
|
||||
// SizedBox(height: getProportionateScreenWidth(24)),
|
||||
// Container(
|
||||
// // padding:
|
||||
// // EdgeInsets.only(top: getProportionateScreenWidth(110)),
|
||||
// //height: getProportionateScreenWidth(33),
|
||||
// alignment: Alignment.bottomCenter,
|
||||
// child: SearchField(),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// Container(
|
||||
// padding: EdgeInsets.fromLTRB(getProportionateScreenWidth(18.0),
|
||||
// getProportionateScreenWidth(11.5), 0, 0),
|
||||
// child: Begin()),
|
||||
// SizedBox(height: getProportionateScreenWidth(36)),
|
||||
|
||||
//SearchField(),
|
||||
|
||||
// SizedBox(height: getProportionateScreenWidth(12)),
|
||||
CarouselWithIndicatorDemo(),
|
||||
|
||||
// Padding(
|
||||
// padding: EdgeInsets.symmetric(
|
||||
// horizontal: getProportionateScreenWidth(14)),
|
||||
// child: Center(child: GopayVoucher()),
|
||||
// ),
|
||||
// SizedBox(height: 18),
|
||||
// Program(),
|
||||
HomeCategories(),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: getProportionateScreenWidth(14)),
|
||||
child: CertificateVoucher(),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(19)),
|
||||
// Padding(
|
||||
// padding: EdgeInsets.symmetric(
|
||||
// horizontal: getProportionateScreenWidth(20)),
|
||||
// child:
|
||||
// Row(mainAxisAlignment: MainAxisAlignment.start, children: [
|
||||
// Text('Pencarian Terpopuler',
|
||||
// textAlign: TextAlign.left,
|
||||
// style: secondaryTextStyle.copyWith(
|
||||
// letterSpacing: 1,
|
||||
// color: tenthColor,
|
||||
// fontSize: getProportionateScreenWidth(14),
|
||||
// fontWeight: semiBold)),
|
||||
// ]),
|
||||
// ),
|
||||
// SizedBox(height: 10),
|
||||
// Categories(),
|
||||
Consumer<PromoCourseProvider>(
|
||||
builder: (context, promoState, _) {
|
||||
SizedBox(height: 20);
|
||||
return promoState.state == promo.ResultState.HasData
|
||||
? PromoCourse(text: "Promo")
|
||||
: SizedBox();
|
||||
},
|
||||
),
|
||||
|
||||
SizedBox(height: 20),
|
||||
|
||||
PopulerCourse(text: "Kursus Teratas"),
|
||||
LatestCourse(text: "Kursus Terbaru"),
|
||||
SizedBox(height: getProportionateScreenHeight(25)),
|
||||
OthersCourse(),
|
||||
Provider.of<OthersCourseProvider>(context).loading
|
||||
? Center(
|
||||
child: SizedBox(
|
||||
height: 30,
|
||||
width: 30,
|
||||
child: CircularProgressIndicator(
|
||||
color: secondaryColor,
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
)
|
||||
: SizedBox(height: 30),
|
||||
SizedBox(height: 25),
|
||||
// ChangeNotifierProvider<CourseProvider>.value(
|
||||
// value: CourseProvider(courseService: CourseService()),
|
||||
// child: Course()),
|
||||
|
||||
// Recommendation(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
429
lib/screens/home/components/notification.dart
Normal file
429
lib/screens/home/components/notification.dart
Normal file
@ -0,0 +1,429 @@
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:initial_folder/base_service.dart';
|
||||
import 'package:initial_folder/models/notification.dart';
|
||||
import 'package:initial_folder/providers/detail_course_provider.dart';
|
||||
import 'package:initial_folder/providers/lesson_course_provider.dart';
|
||||
import 'package:initial_folder/providers/notification_provider.dart';
|
||||
import 'package:initial_folder/screens/course/play_course_page.dart';
|
||||
import 'package:initial_folder/services/course_service.dart';
|
||||
import 'package:initial_folder/services/lesson_course_service.dart';
|
||||
import 'package:initial_folder/services/notification_service.dart';
|
||||
import 'package:initial_folder/size_config.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
|
||||
class Notifikasi extends StatelessWidget {
|
||||
const Notifikasi({Key? key}) : super(key: key);
|
||||
static String routeName = "/notifikasi";
|
||||
|
||||
initNotif(BuildContext context) async {
|
||||
FirebaseMessaging.onMessage.listen((event) async {
|
||||
if (event.data.isNotEmpty) {
|
||||
await Provider.of<NotificationProvider>(context, listen: false)
|
||||
.getMyNotification();
|
||||
await Provider.of<NotificationProvider>(context, listen: false)
|
||||
.getNotificationCount();
|
||||
}
|
||||
});
|
||||
Future.delayed(const Duration(seconds: 0), () async {
|
||||
await Provider.of<NotificationProvider>(context, listen: false)
|
||||
.getMyNotification();
|
||||
await Provider.of<NotificationProvider>(context, listen: false)
|
||||
.getNotificationCount();
|
||||
});
|
||||
}
|
||||
|
||||
readAllHandler(
|
||||
BuildContext context,
|
||||
) async {
|
||||
await Provider.of<NotificationProvider>(context, listen: false)
|
||||
.markAsRead();
|
||||
if (!context.mounted) return;
|
||||
Provider.of<NotificationProvider>(context, listen: false).changeAllRead();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Brightness brightnessValue =
|
||||
MediaQuery.of(context).platformBrightness;
|
||||
bool isDarkMode = brightnessValue == Brightness.dark;
|
||||
initNotif(context);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: Theme.of(context).colorScheme.background,
|
||||
scrolledUnderElevation: 0.0,
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: "Mark as Read",
|
||||
onPressed: () => readAllHandler(
|
||||
context,
|
||||
),
|
||||
icon: const Icon(Icons.drafts),
|
||||
),
|
||||
],
|
||||
centerTitle: true,
|
||||
title: Text(
|
||||
'Notifikasi',
|
||||
style: secondaryTextStyle.copyWith(
|
||||
letterSpacing: 1,
|
||||
fontWeight: semiBold,
|
||||
fontSize: getProportionateScreenWidth(14),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
displacement: 40,
|
||||
onRefresh: () async {
|
||||
await Provider.of<NotificationProvider>(context, listen: false)
|
||||
.getMyNotification();
|
||||
},
|
||||
child: Consumer<NotificationProvider>(
|
||||
builder: (context, value, child) {
|
||||
if (value.state == resultState.Loading) {
|
||||
return Shimmer.fromColors(
|
||||
baseColor: Colors.grey,
|
||||
highlightColor: Colors.white,
|
||||
child: ListView.builder(
|
||||
itemCount: 6,
|
||||
itemBuilder: (context, index) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: getProportionateScreenHeight(10)),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding:
|
||||
EdgeInsets.all(getProportionateScreenWidth(10)),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
border: Border(
|
||||
bottom: BorderSide(color: Colors.white))),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: getProportionateScreenHeight(50),
|
||||
child: Container(
|
||||
color: Colors.white,
|
||||
width: getProportionateScreenWidth(100),
|
||||
),
|
||||
),
|
||||
SizedBox(width: getProportionateScreenWidth(10)),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
color: Colors.white,
|
||||
height: getProportionateScreenHeight(2),
|
||||
),
|
||||
SizedBox(
|
||||
height: getProportionateScreenHeight(15),
|
||||
),
|
||||
Container(
|
||||
color: Colors.white,
|
||||
height: getProportionateScreenHeight(15),
|
||||
),
|
||||
SizedBox(
|
||||
height: getProportionateScreenHeight(5),
|
||||
),
|
||||
Container(
|
||||
color: Colors.white,
|
||||
height: getProportionateScreenHeight(15),
|
||||
),
|
||||
SizedBox(
|
||||
height: getProportionateScreenHeight(5),
|
||||
),
|
||||
Container(
|
||||
color: Colors.white,
|
||||
height: getProportionateScreenHeight(15),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
} else if (value.state == resultState.Error) {
|
||||
return Center(
|
||||
child: ListView(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
constraints: BoxConstraints(
|
||||
minHeight: MediaQuery.of(context).size.height / 1.5),
|
||||
child: Center(
|
||||
child: Text('Terjadi Kesalahan'),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
} else if (value.state == resultState.NoData) {
|
||||
return Center(
|
||||
child: ListView(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
constraints: BoxConstraints(
|
||||
minHeight: MediaQuery.of(context).size.height / 1.5),
|
||||
child: Center(
|
||||
child: Text('Notifikasi Kosong'),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
var allResults = [...value.result, ...value.resultAnnouncement];
|
||||
return ListView.builder(
|
||||
itemCount: allResults.length,
|
||||
itemBuilder: (context, index) {
|
||||
return GestureDetector(
|
||||
onTap: () async {
|
||||
Provider.of<NotificationProvider>(context,
|
||||
listen: false)
|
||||
.changeIsRead(value.result, index);
|
||||
await NotificationServices().readNotification(
|
||||
value.result[index].idRead!,
|
||||
value.result[index].ket!);
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(context, rootNavigator: true).push(
|
||||
MaterialPageRoute(
|
||||
builder: (context) => MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider(
|
||||
create: (context) => LessonCourseProvider(
|
||||
lessonCourseService: LessonCourseService(),
|
||||
id: int.parse(
|
||||
value.result[index].idCourse ?? '0'),
|
||||
),
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create: (context) => DetailCourseProvider(
|
||||
courseService: CourseService(),
|
||||
id: value.result[index].idCourse ?? '1',
|
||||
),
|
||||
)
|
||||
],
|
||||
child: PlayCourse(
|
||||
judul: value.result[index].titleCourse ?? '',
|
||||
instruktur:
|
||||
value.result[index].instructor ?? '',
|
||||
thumbnail: value.result[index].thumbnail ??
|
||||
'$baseUrl/uploads/courses_thumbnail/course_thumbnail_default_57.jpg',
|
||||
courseeid: value.result[index].idCourse ?? '',
|
||||
isQna: (value.result[index].subject ==
|
||||
"Q&A Kursus")
|
||||
? true
|
||||
: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
getProportionateScreenWidth(20),
|
||||
getProportionateScreenHeight(5),
|
||||
getProportionateScreenWidth(20),
|
||||
getProportionateScreenHeight(5)),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding:
|
||||
EdgeInsets.all(getProportionateScreenWidth(10)),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color:
|
||||
isDarkMode ? Colors.black : Colors.grey,
|
||||
spreadRadius: 0.01,
|
||||
blurRadius: 2,
|
||||
offset: Offset(0, 1), // Shadow position
|
||||
),
|
||||
],
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primaryContainer,
|
||||
border: Border(
|
||||
bottom: BorderSide(color: Colors.white12))),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
height: getProportionateScreenHeight(60),
|
||||
child: (value.result[index].thumbnail == "" ||
|
||||
value.result[index].thumbnail == null)
|
||||
? Image.network(
|
||||
'https://api.vokasia.id/images/default-thumbnail.png',
|
||||
fit: BoxFit.fill,
|
||||
width:
|
||||
getProportionateScreenWidth(120),
|
||||
)
|
||||
: Image.network(
|
||||
value.result[index].thumbnail!,
|
||||
fit: BoxFit.fill,
|
||||
width:
|
||||
getProportionateScreenWidth(120),
|
||||
)),
|
||||
SizedBox(width: getProportionateScreenWidth(10)),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceAround,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
value.result[index].subject!,
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: 12,
|
||||
fontWeight: reguler,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: getProportionateScreenHeight(15),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
DateFormat('dd MMMM yyyy ').format(
|
||||
DateTime
|
||||
.fromMillisecondsSinceEpoch(
|
||||
int.parse(value
|
||||
.result[index]
|
||||
.timestamps!) *
|
||||
1000),
|
||||
),
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: 12,
|
||||
fontWeight: reguler,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimary,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal:
|
||||
getProportionateScreenWidth(
|
||||
5)),
|
||||
child: Icon(Icons.lens_rounded,
|
||||
color: Color(0xffc4c4c4),
|
||||
size:
|
||||
getProportionateScreenWidth(
|
||||
7)),
|
||||
),
|
||||
Text(
|
||||
value.result[index].date!
|
||||
.substring(
|
||||
value.result[index].date!
|
||||
.length -
|
||||
8,
|
||||
value.result[index].date!
|
||||
.length -
|
||||
3),
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: 12,
|
||||
fontWeight: reguler,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimary,
|
||||
)),
|
||||
SizedBox(
|
||||
width:
|
||||
getProportionateScreenWidth(
|
||||
10)),
|
||||
notificationPing(value.result[index])
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 2,
|
||||
text: TextSpan(
|
||||
text: (value.result[index].messages !=
|
||||
null)
|
||||
? value.result[index].messages!
|
||||
: "",
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: 12,
|
||||
fontWeight: reguler,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimary,
|
||||
),
|
||||
)),
|
||||
// Text(
|
||||
// (value.result[index].messages != null)
|
||||
// ? value.result[index].messages!
|
||||
// : "",
|
||||
// style: thirdTextStyle.copyWith(
|
||||
// fontSize: 12,
|
||||
// fontWeight: reguler,
|
||||
// color: Theme.of(context)
|
||||
// .colorScheme
|
||||
// .onPrimary,
|
||||
// ),
|
||||
// ),
|
||||
SizedBox(
|
||||
height:
|
||||
getProportionateScreenHeight(5)),
|
||||
RichText(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 2,
|
||||
text: TextSpan(
|
||||
text:
|
||||
value.result[index].titleCourse!,
|
||||
style: thirdTextStyle.copyWith(
|
||||
fontSize: 12,
|
||||
fontWeight: reguler,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimary,
|
||||
),
|
||||
)),
|
||||
// Text(
|
||||
// value.result[index].titleCourse!,
|
||||
// style: thirdTextStyle.copyWith(
|
||||
// fontSize:
|
||||
// getProportionateScreenHeight(10)),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget notificationPing(NotificationData data) {
|
||||
if (data.isRead == "0") {
|
||||
return Icon(Icons.lens_rounded,
|
||||
color: Color(0xffCD2228), size: getProportionateScreenWidth(10));
|
||||
} else {
|
||||
return SizedBox();
|
||||
}
|
||||
}
|
||||
}
|
68
lib/screens/home/components/notifikasi.dart
Normal file
68
lib/screens/home/components/notifikasi.dart
Normal file
@ -0,0 +1,68 @@
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:initial_folder/providers/history_transactions_provider.dart';
|
||||
// import 'package:initial_folder/services/notification_service.dart';
|
||||
// import 'package:initial_folder/size_config.dart';
|
||||
// import 'package:initial_folder/theme.dart';
|
||||
// import 'package:initial_folder/widgets/notifikasi_list.dart';
|
||||
// import 'package:provider/provider.dart';
|
||||
//
|
||||
// class Notifikasi extends StatelessWidget {
|
||||
// const Notifikasi({Key? key}) : super(key: key);
|
||||
//
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// NotificationServices().getNotification();
|
||||
// return SafeArea(
|
||||
// child: Scaffold(
|
||||
// appBar: AppBar(
|
||||
// centerTitle: true,
|
||||
// title: Text(
|
||||
// 'Notifikasi',
|
||||
// style: secondaryTextStyle.copyWith(
|
||||
// letterSpacing: 2,
|
||||
// fontWeight: semiBold,
|
||||
// fontSize: getProportionateScreenWidth(14)),
|
||||
// )),
|
||||
// body: Consumer<HistoryTranscationsProvider>(
|
||||
// builder: (context, state, _) {
|
||||
// if (state.state == ResultState.loading) {
|
||||
// return Center(
|
||||
// child: CircularProgressIndicator(
|
||||
// color: primaryColor,
|
||||
// ),
|
||||
// );
|
||||
// } else if (state.state == ResultState.error) {
|
||||
// return Center(
|
||||
// child: Text('Terjadi Kesalahan'),
|
||||
// );
|
||||
// } else if (state.state == ResultState.noData) {
|
||||
// return Center(
|
||||
// child: Text('Terjadi Kesalahan'),
|
||||
// );
|
||||
// } else {
|
||||
// // var data = state.historyPayment!
|
||||
// // .where((item) =>
|
||||
// // // item.statusPayment == 'Success' ||
|
||||
// // item.statusPayment != 'Failed')
|
||||
// // .toList();
|
||||
// var pending = state.paymentPending!;
|
||||
// var success = state.historyPayment!
|
||||
// .where((element) => element.statusPayment == 'Success')
|
||||
// .toList();
|
||||
// var data = pending + success;
|
||||
// // var datas = state.historyPayment.removeWhere((element) => element.statusPayment != 'Success')
|
||||
// return ListView.builder(
|
||||
// itemCount: data.length > 10 ? 10 : data.length,
|
||||
// itemBuilder: (context, index) {
|
||||
// return NotifikasiList(
|
||||
// data: data[index],
|
||||
// baru: index < 3 ? true : false,
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
// },
|
||||
// )),
|
||||
// );
|
||||
// }
|
||||
// }
|
174
lib/screens/home/home_screen.dart
Normal file
174
lib/screens/home/home_screen.dart
Normal file
@ -0,0 +1,174 @@
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:initial_folder/helper/user_info.dart';
|
||||
import 'package:initial_folder/providers/page_provider.dart';
|
||||
import 'package:initial_folder/screens/course/my_course_page.dart';
|
||||
import 'package:initial_folder/screens/profile/profile_page.dart';
|
||||
import 'package:initial_folder/screens/search_course/search_page.dart';
|
||||
import 'package:initial_folder/screens/whislist/my_whislist_page.dart';
|
||||
import 'package:initial_folder/size_config.dart';
|
||||
import 'package:initial_folder/theme.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'components/home_page.dart';
|
||||
|
||||
class HomeScreen extends StatefulWidget {
|
||||
const HomeScreen({Key? key}) : super(key: key);
|
||||
static String routeName = "/home";
|
||||
|
||||
@override
|
||||
State<HomeScreen> createState() => _HomeScreenState();
|
||||
}
|
||||
|
||||
class _HomeScreenState extends State<HomeScreen> {
|
||||
Widget buildNavItem(int index, String icon, String activeIcon, String title) {
|
||||
PageProvider pageProvider = Provider.of<PageProvider>(context);
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
pageProvider.currentIndex = index;
|
||||
},
|
||||
child: Container(
|
||||
width: getProportionateScreenWidth(360) / 5,
|
||||
decoration: BoxDecoration(
|
||||
color: pageProvider.currentIndex == index
|
||||
? Theme.of(context).brightness == Brightness.light
|
||||
? primaryColorligtmode
|
||||
: primaryColor
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(5),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
AnimatedContainer(
|
||||
duration: Duration(milliseconds: 300),
|
||||
height: getProportionateScreenHeight(22),
|
||||
width: getProportionateScreenWidth(22),
|
||||
child: SvgPicture.asset(
|
||||
pageProvider.currentIndex == index ? activeIcon : icon,
|
||||
color: pageProvider.currentIndex == index
|
||||
? baruTextutih
|
||||
: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: getProportionateScreenHeight(2)),
|
||||
Text(
|
||||
title,
|
||||
style: thirdTextStyle.copyWith(
|
||||
color: pageProvider.currentIndex == index
|
||||
? baruTextutih
|
||||
: Theme.of(context).colorScheme.secondary,
|
||||
fontSize: getProportionateScreenWidth(10),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
UsersInfo().getIdUser().then((value) {
|
||||
print(value);
|
||||
FirebaseMessaging.instance.subscribeToTopic("payment-before-paid-$value");
|
||||
FirebaseMessaging.instance.subscribeToTopic("payment-after-paid-$value");
|
||||
FirebaseMessaging.instance.subscribeToTopic("qna-new-qna-$value");
|
||||
FirebaseMessaging.instance.subscribeToTopic("qna-reply-qna-$value");
|
||||
FirebaseMessaging.instance.subscribeToTopic("alert-carts-$value");
|
||||
});
|
||||
UsersInfo().getToken().then((value) => print(value));
|
||||
PageProvider pageProvider = Provider.of<PageProvider>(context);
|
||||
DateTime backButtonPressTime = DateTime.now();
|
||||
|
||||
SizeConfig().init(context);
|
||||
Future<bool> handleWillPop(BuildContext context) async {
|
||||
final now = DateTime.now();
|
||||
final backButtonHasNotBeenPressedOrSnackBarHasBeenClosed =
|
||||
DateTime.now().difference(backButtonPressTime) >=
|
||||
Duration(milliseconds: 500);
|
||||
|
||||
if (backButtonHasNotBeenPressedOrSnackBarHasBeenClosed) {
|
||||
backButtonPressTime = now;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
width: 240,
|
||||
duration: Duration(seconds: 2),
|
||||
backgroundColor: secondaryColor,
|
||||
content: Text(
|
||||
'Tekan sekali lagi untuk keluar',
|
||||
style: primaryTextStyle.copyWith(
|
||||
color: backgroundColor, fontSize: 12),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
),
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Widget customBottomNavigation() {
|
||||
return Container(
|
||||
color: Theme.of(context).brightness == Brightness.dark
|
||||
? twelveColor
|
||||
: baruTextutih,
|
||||
height: getProportionateScreenHeight(48),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
buildNavItem(0, 'assets/icons/featured.svg',
|
||||
'assets/icons/featured_click.svg', 'Home'),
|
||||
buildNavItem(1, 'assets/icons/search.svg',
|
||||
'assets/icons/search_click.svg', 'Search'),
|
||||
buildNavItem(2, 'assets/icons/my_course.svg',
|
||||
'assets/icons/my_course_click.svg', 'My Course'),
|
||||
buildNavItem(3, 'assets/icons/wishlist.svg',
|
||||
'assets/icons/wishlist_click.svg', 'Wishlist'),
|
||||
buildNavItem(4, 'assets/icons/profile.svg',
|
||||
'assets/icons/profile_click.svg', 'Profile'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget body() {
|
||||
switch (pageProvider.currentIndex) {
|
||||
case 0:
|
||||
return HomePage();
|
||||
case 1:
|
||||
return SearchPage();
|
||||
case 2:
|
||||
return MyCoursePage();
|
||||
case 3:
|
||||
return WishlistPage();
|
||||
case 4:
|
||||
return ProfilePage();
|
||||
default:
|
||||
return HomePage();
|
||||
}
|
||||
}
|
||||
|
||||
return WillPopScope(
|
||||
onWillPop: () => handleWillPop(context),
|
||||
child: Scaffold(
|
||||
backgroundColor: pageProvider.currentIndex == 1
|
||||
? Theme.of(context).brightness == Brightness.dark
|
||||
? twelveColor
|
||||
: baruTextutih
|
||||
: Theme.of(context).brightness == Brightness.dark
|
||||
? backgroundColor
|
||||
: baruTextutih,
|
||||
body: body(),
|
||||
bottomNavigationBar: customBottomNavigation(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user