Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some errors and update to flutter v3.13.4 #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
69 changes: 38 additions & 31 deletions lib/layout/home_layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,52 @@ import '../shared/components/components.dart';
import '../shared/cubits/home_cubit/home_cubit.dart';

class HomeLayout extends StatelessWidget {
const HomeLayout({super.key});

@override
Widget build(BuildContext context) {
return BlocConsumer<HomeCubit, HomeStates>(
listener: (context, state) {},
builder: (context, state) {
var cubit = HomeCubit.get(context);
listener: (context, state) {},
builder: (context, state) {
var cubit = HomeCubit.get(context);

return Scaffold(
appBar: AppBar(
title: logo,
actions: [
IconButton(
onPressed: (){
navigateTo(context, SearchScreen());
},
icon: Icon(CupertinoIcons.search, size: 24.0.sp,),
return Scaffold(
appBar: AppBar(
title: logo,
actions: [
IconButton(
onPressed: () {
navigateTo(context, const SearchScreen());
},
icon: Icon(
CupertinoIcons.search,
size: 24.0.sp,
),
],
),
body: cubit.screens[cubit.currentIndex],
bottomNavigationBar: ClipRRect(
borderRadius: BorderRadius.only(topRight: Radius.circular(10.0), topLeft: Radius.circular(10.0),),
child: SizedBox(
height: MediaQuery.of(context).size.height / 12.8,
child: BottomNavigationBar(
onTap: (index){
cubit.changeNavIndex(index);
},
unselectedFontSize: 11.0.sp,
selectedFontSize: 12.0.sp,
currentIndex: cubit.currentIndex,
items: cubit.navItems,
iconSize: MediaQuery.of(context).size.height / 30.0,
),
],
),
body: cubit.screens[cubit.currentIndex],
bottomNavigationBar: ClipRRect(
borderRadius: const BorderRadius.only(
topRight: Radius.circular(10.0),
topLeft: Radius.circular(10.0),
),
child: SizedBox(
height: MediaQuery.of(context).size.height / 12.8,
child: BottomNavigationBar(
onTap: (index) {
cubit.changeNavIndex(index);
},
unselectedFontSize: 11.0.sp,
selectedFontSize: 12.0.sp,
currentIndex: cubit.currentIndex,
items: cubit.navItems,
iconSize: MediaQuery.of(context).size.height / 30.0,
),
),
);
},
);
),
);
},
);
}
}
66 changes: 32 additions & 34 deletions lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:io';
import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -15,57 +14,55 @@ import 'package:shop_app/shared/network/local/cache_helper.dart';
import 'package:shop_app/shared/network/remote/dio.dart';
import 'package:shop_app/shared/network/styles/styles.dart';

void main() async{
void main() async {
WidgetsFlutterBinding.ensureInitialized();
ByteData data = await PlatformAssetBundle().load('assets/ca/lets-encrypt-r3.pem');
SecurityContext.defaultContext.setTrustedCertificatesBytes(data.buffer.asUint8List(),);
ByteData data =
await PlatformAssetBundle().load('assets/ca/lets-encrypt-r3.pem');
SecurityContext.defaultContext.setTrustedCertificatesBytes(
data.buffer.asUint8List(),
);
DioHelper.init();
await CacheHelper.init();
String token = CacheHelper.getData(key: 'token') ?? '';
bool onboardingIsSeen = CacheHelper.getData(key: 'onboardingIsSeen') ?? false;
Widget startWidget = OnboardingScreen();

if(onboardingIsSeen)
{
if(token != '')
{
startWidget = HomeLayout();
}
else
{
startWidget = LoginScreen();
}
if (onboardingIsSeen) {
if (token != '') {
startWidget = const HomeLayout();
} else {
startWidget = const LoginScreen();
}
}

runApp(MyApp(startWidget));
runApp(MyApp(startWidget: startWidget));
}

// ignore: must_be_immutable
class MyApp extends StatelessWidget {
Widget startWidget;
Widget? startWidget;

MyApp(this.startWidget);
MyApp({super.key, this.startWidget});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations(
[
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]
);
return MultiBlocProvider(
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
return MultiBlocProvider(
providers: [
BlocProvider<OnBoardingCubit>(
create: (context) => OnBoardingCubit()
),
BlocProvider<OnBoardingCubit>(create: (context) => OnBoardingCubit()),
BlocProvider<LoginCubit>(
create: (context) => LoginCubit(),
),
BlocProvider<HomeCubit>(
create: (context) => HomeCubit()..getHomeData()
..getCategoryData()
..getFavorites()
..getProfileData(),
create: (context) => HomeCubit()
..getHomeData()
..getCategoryData()
..getFavorites()
..getProfileData(),
)
],
child: BlocConsumer<HomeCubit, HomeStates>(
Expand All @@ -75,12 +72,13 @@ class MyApp extends StatelessWidget {
designSize: const Size(360, 690),
minTextAdapt: true,
splitScreenMode: true,
builder: (context , child)
{
builder: (context, child) {
return MaterialApp(
debugShowCheckedModeBanner: false,
theme: lightTheme,
themeMode: HomeCubit.get(context).isDark ? ThemeMode.dark : ThemeMode.light,
themeMode: HomeCubit.get(context).isDark
? ThemeMode.dark
: ThemeMode.light,
darkTheme: darkTheme,
home: startWidget,
);
Expand Down
26 changes: 10 additions & 16 deletions lib/models/category_model.dart
Original file line number Diff line number Diff line change
@@ -1,39 +1,33 @@
class CategoryModel
{
class CategoryModel {
late bool status;
late CategoryDataModel data;

CategoryModel.fromJson(Map<String, dynamic> json)
{
CategoryModel.fromJson(Map<String, dynamic> json) {
status = json['status'];
data = CategoryDataModel.fromJson(json["data"]);
}
}

class CategoryDataModel
{
class CategoryDataModel {
late int currentPage;
List<DataModel_C>? data = [];
List<DataModelC>? data = [];

CategoryDataModel.fromJson(Map<String, dynamic>json)
{
CategoryDataModel.fromJson(Map<String, dynamic> json) {
currentPage = json['current_page'];
json['data'].forEach((element){
data?.add(DataModel_C.fromJson(element));
json['data'].forEach((element) {
data?.add(DataModelC.fromJson(element));
});
}
}

class DataModel_C
{
class DataModelC {
late int id;
late String name;
late String image;

DataModel_C.fromJson(Map<String, dynamic>json)
{
DataModelC.fromJson(Map<String, dynamic> json) {
id = json['id'];
name = json['name'];
image = json['image'];
}
}
}
10 changes: 3 additions & 7 deletions lib/models/favorite_model.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import 'package:shop_app/models/home_data_model.dart';

class FavoriteModel
{
class FavoriteModel {
late bool status;
late String message;

FavoriteModel.fromJson(Map<String, dynamic> json)
{
FavoriteModel.fromJson(Map<String, dynamic> json) {
status = json['status'];
message = json['message'];
}
}
}
21 changes: 11 additions & 10 deletions lib/models/get_favorites_model.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import 'package:shop_app/models/home_data_model.dart';

class GetFavoriteModel
{
class GetFavoriteModel {
late bool status;
List<Product> products = [];
List<Product>? products;

GetFavoriteModel.fromJson(Map<String, dynamic> json)
{
status = json['status'];
json['data']['data'].forEach((product){
products.add(Product.fromJsonFav(product['product']));
});
GetFavoriteModel.fromJson(Map<String, dynamic> json) {
try {
status = json['status'];
json['data']['data'].forEach((product) {
products?.add(Product.fromJsonFav(product['product']));
});
// ignore: empty_catches
} catch (e) {}
}
}
}
13 changes: 7 additions & 6 deletions lib/models/profile_model.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import '../modules/login_model.dart';

class ProfileModel
{
class ProfileModel {
late bool status;
late UserData data;

ProfileModel.fromJson(Map<String, dynamic> json)
{
ProfileModel.fromJson(Map<String, dynamic> json) {
status = json['status'];
data = UserData.fromJson(json['data']);
try {
data = UserData.fromJson(json['data']);
// ignore: empty_catches
} catch (e) {}
}
}
}
Loading