Skip to content

Commit

Permalink
Code Refactoring.(Dependency)
Browse files Browse the repository at this point in the history
  • Loading branch information
FatihBaycu committed Sep 9, 2021
1 parent cc2ba7b commit f2fea3c
Show file tree
Hide file tree
Showing 21 changed files with 296 additions and 259 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

# Web related
lib/generated_plugin_registrant.dart
lib/globalVariables.dart

# Symbolication related
app.*.symbols
Expand Down
2 changes: 0 additions & 2 deletions lib/controllers/auth_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import 'package:flutter_http_demo2/models/users/token.dart';
import 'package:flutter_http_demo2/models/users/user_for_login.dart';
import 'package:flutter_http_demo2/services/auth_service.dart';
import 'package:get/get.dart';

class AuthController extends GetxController{
Expand Down
5 changes: 3 additions & 2 deletions lib/controllers/card_controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';

import 'package:flutter_http_demo2/controllers/user_controller.dart';
import 'package:flutter_http_demo2/models/card.dart';
import 'package:flutter_http_demo2/services/card_service.dart';
import 'package:get/get.dart';
Expand All @@ -9,11 +10,11 @@ class CardController extends GetxController {
var cardList = <CardModel>[].obs;

CardService cardService=new CardService();

UserController userController=Get.put(UserController());

@override
void onInit() {
getCardsByCustomerId(2);
getCardsByCustomerId(userController.user().customerId!);
super.onInit();
}

Expand Down
4 changes: 2 additions & 2 deletions lib/controllers/color_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:get/get.dart';

class ColorController extends GetxController{
var isLoading=true.obs;
var colorList=<Color>[].obs;
var colorList=<Color>[Color(1, "Kırmızı", "#FFF000")].obs;


ColorService colorService=new ColorService();
Expand All @@ -18,7 +18,7 @@ class ColorController extends GetxController{
}


Future<void> getAll() async{
Future<void> getAll() async{
try{
isLoading(true);
await colorService.getAll().then((response){
Expand Down
18 changes: 9 additions & 9 deletions lib/controllers/rental_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ class RentalController extends GetxController {
super.onInit();
}


void tryMethod(){
print("Çalışyor TRYMETHOD");
getRentalsByCustomerId(userController.user().customerId!);}

void getRentalsByCustomerId(int customerId) async {
try {
await RentalService().getRentalsByCustomerId(customerId).then((response) {
isLoading(true);
var result = (jsonDecode(response.body)["data"] as List)
.map((e) => RentalDetails.fromJson(e))
.toList();
if (result != null) {
rentalDetail.assignAll(result);
}
if (result != null) { rentalDetail.assignAll(result);}
});
} finally {
isLoading(false);
}
} finally { isLoading(false);}
}

Future<void>addRental(Rental rental)async {
await RentalService().addRental(rental);
}
Future<void>addRental(Rental rental)async {await RentalService().addRental(rental);}

}
1 change: 1 addition & 0 deletions lib/controllers/user_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class UserController extends GetxController{
await UserService.getUserByEmail(email).then((response) {
isLoading(true);
var result = (jsonDecode(response.body)["data"]);
print(response.body);
var userResponse=UserDetail.fromJson(result);
if (result != null) { user(userResponse);}
else{
Expand Down
2 changes: 0 additions & 2 deletions lib/core/services/HttpGenericService.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import 'package:flutter_http_demo2/controllers/auth_controller.dart';
import 'package:get/get.dart';
import 'package:http/http.dart' as http;

import '../ResponseService.dart';

AuthController authController = Get.put(AuthController());

class HttpGenericService {
Expand Down
12 changes: 6 additions & 6 deletions lib/lang/en_us.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@
"CarRented":"Car Rented",
"pay":"Pay",

"paymentBrand":"Brand",
"paymentModel":"Model",
"paymentRentDate":"Rent Date",
"paymentReturnDate":"Return Date",
"paymentTotalDay":"Total Day",
"paymentTotalPrice":"Total Price",
"paymentBrand":"Brand :",
"paymentModel":"Model :",
"paymentRentDate":"Rent Date :",
"paymentReturnDate":"Return Date :",
"paymentTotalDay":"Total Day :",
"paymentTotalPrice":"Total Price :",

//Login
"loginScreen":"Login Screen",
Expand Down
1 change: 0 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:io';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_http_demo2/screens/brand/brand_screen.dart';
import 'package:flutter_http_demo2/screens/car/car_add_screen.dart';
Expand Down
4 changes: 0 additions & 4 deletions lib/models/rental.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import 'dart:io';

import 'package:flutter/material.dart';

class Rental{
int? id;
int? carId;
Expand Down
2 changes: 1 addition & 1 deletion lib/models/users/token.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Token {
String? token;
String? expiration;
Token.withEmpty() {}
Token.withEmpty();
Token({
this.token,
this.expiration});
Expand Down
21 changes: 11 additions & 10 deletions lib/screens/brand/brand_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class _BrandScreenState extends State<BrandScreen> {
brandName: "default",
);

BrandController brandController = Get.put(BrandController());
//BrandController brandController = Get.put(BrandController());

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -50,20 +50,17 @@ class _BrandScreenState extends State<BrandScreen> {
}

buildNewBrandListWidget() {
return Obx(() {
if (brandController.isLoading.value)
return Center(
child: CircularProgressIndicator(),
);
else
return SingleChildScrollView(
return GetX<BrandController>(
init: BrandController(),
builder: (_brandController){
return SingleChildScrollView(
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
padding: EdgeInsets.only(left: 20, right: 20),
itemCount: brandController.brandList.length,
itemCount: _brandController.brandList.length,
itemBuilder: (context, int index) {
var brands = brandController.brandList;
var brands = _brandController.brandList;
return ListTile(
title: Text(brands[index].brandName.toString()),
onTap: () {},
Expand All @@ -74,6 +71,9 @@ class _BrandScreenState extends State<BrandScreen> {
});
}




buildPopupMenu(Brand brand) {
return PopupMenuButton<Options>(
onSelected: (value) => selectProcess(value, brand),
Expand Down Expand Up @@ -137,6 +137,7 @@ class _BrandScreenState extends State<BrandScreen> {
if (formKey.currentState!.validate()) {
formKey.currentState!.save();
BrandService().brandAdd(this.brand);
BrandController().getAll().then((value) => Get.toNamed("/car-list"));
}
},
),
Expand Down
91 changes: 51 additions & 40 deletions lib/screens/brand/brand_update_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,43 @@ import 'package:flutter_http_demo2/models/brand.dart';
import 'package:flutter_http_demo2/services/brand_service.dart';
import 'package:get/get.dart';

// ignore: must_be_immutable
class BrandUpdateScreen extends StatefulWidget {
Brand brand;
BrandUpdateScreen(this.brand);
Brand brand;
BrandUpdateScreen(this.brand);

@override
_BrandUpdateScreenState createState() => _BrandUpdateScreenState();
}

class _BrandUpdateScreenState extends State<BrandUpdateScreen> {


var formKey = GlobalKey<FormState>();
var brandName=TextEditingController();
var brandId=TextEditingController();
var brandName = TextEditingController();
var brandId = TextEditingController();

@override
@override
void initState() {
brandName.text=widget.brand.brandName!;
brandId.text=widget.brand.brandId.toString();
brandName.text = widget.brand.brandName!;
brandId.text = widget.brand.brandId.toString();
print("widget.brand!.brandName");
super.initState();
super.initState();
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("${widget.brand.brandName} "+'brand'.tr),),
appBar: AppBar(
title: Text("${widget.brand.brandName} " + 'brand'.tr),
),
body: SingleChildScrollView(
child: Center(
child: buildFormField(),
child: buildFormField(),
),
),
);
}




buildFormField(){
buildFormField() {
return ListView(
padding: EdgeInsets.all(20),
shrinkWrap: true,
Expand All @@ -51,60 +49,73 @@ class _BrandUpdateScreenState extends State<BrandUpdateScreen> {
child: Column(
children: [
buildBrandIdField(),
SizedBox(height: 10,),
SizedBox(
height: 10,
),
buildBrandNameField(),
buildBrandSubmitField(),
],
),
),
],
);

}

buildBrandIdField() {
return TextFormField(
decoration: InputDecoration(hintText: "enterBrandName".tr,border: OutlineInputBorder()),
decoration: InputDecoration(
hintText: "enterBrandName".tr, border: OutlineInputBorder()),
controller: brandId,
readOnly: true,
validator: (val){
if(val!.isEmpty){return "brandNameErrorEmpty".tr;}
else {return null;}
validator: (val) {
if (val!.isEmpty) {
return "brandNameErrorEmpty".tr;
} else {
return null;
}
},
onSaved: (String? value) {
widget.brand.brandName = value!;
},
onSaved:(String? value){widget.brand.brandName=value!;},
);
}

buildBrandNameField() {
return TextFormField(
decoration: InputDecoration(hintText: "enterBrandName".tr,border: OutlineInputBorder(),labelText: "brandName".tr),
decoration: InputDecoration(
hintText: "enterBrandName".tr,
border: OutlineInputBorder(),
labelText: "brandName".tr),
controller: brandName,
validator: (val){
if(val!.isEmpty){return "brandNameErrorEmpty".tr;}
else {return null;}
},
onSaved:(String? value){widget.brand.brandName=value!;},
validator: (val) {
if (val!.isEmpty) {
return "brandNameErrorEmpty".tr;
} else {
return null;
}
},
onSaved: (String? value) {
widget.brand.brandName = value!;
},
);
}





buildBrandSubmitField() {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: ElevatedButton(
child:Text("update".tr),
onPressed: (){
if(formKey.currentState!.validate()){
child: Text("update".tr),
onPressed: () {
if (formKey.currentState!.validate()) {
formKey.currentState!.save();
widget.brand.brandName=brandName.text;
widget.brand.brandId=int.parse(brandId.text);
BrandService().brandUpdate(widget.brand).then((value) =>Get.offNamed("/brand"));
widget.brand.brandName = brandName.text;
widget.brand.brandId = int.parse(brandId.text);
BrandService()
.brandUpdate(widget.brand)
.then((value) => Get.offNamed("/brand"));
}
},
),
);
}

}

0 comments on commit f2fea3c

Please sign in to comment.