You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
6.1 KiB
Dart
164 lines
6.1 KiB
Dart
import 'package:car_provider_app/api/client/branch_api_client.dart';
|
|
import 'package:car_provider_app/api/client/user_api_client.dart';
|
|
import 'package:car_provider_app/classes/utils.dart';
|
|
import 'package:car_provider_app/extensions/int_extensions.dart';
|
|
import 'package:car_provider_app/models/m_response.dart';
|
|
import 'package:car_provider_app/models/user/cities.dart';
|
|
import 'package:car_provider_app/models/user/country.dart';
|
|
import 'package:car_provider_app/pages/location/pick_location_page.dart';
|
|
import 'package:car_provider_app/utils/utils.dart';
|
|
import 'package:car_provider_app/widgets/dropdown/dropdow_field.dart';
|
|
import 'package:car_provider_app/widgets/show_fill_button.dart';
|
|
import 'package:car_provider_app/widgets/txt_field.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class DefineBranchPage extends StatefulWidget {
|
|
@override
|
|
State<DefineBranchPage> createState() => _DefineBranchPageState();
|
|
}
|
|
|
|
class _DefineBranchPageState extends State<DefineBranchPage> {
|
|
String countryCode = "", address = "", branchName = "", branchDescription = "";
|
|
double latitude = 0, longitude = 0;
|
|
int role = -1, countryId = -1, cityId = -1;
|
|
|
|
List<DropValue> countryDropList = [];
|
|
List<DropValue> citiesDropList = [];
|
|
|
|
Country? country;
|
|
Cities? cities;
|
|
|
|
@override
|
|
void initState() {
|
|
// TODO: implement initState
|
|
super.initState();
|
|
fetchCountry();
|
|
}
|
|
|
|
fetchCountry() async {
|
|
country = await UserApiClent().getAllCountries();
|
|
setState(() {
|
|
country!.data?.forEach((element) {
|
|
countryDropList.add(new DropValue(element.id ?? 0, (element.countryName ?? "") + " " + (element.countryCode ?? ""), element.countryCode ?? ""));
|
|
});
|
|
});
|
|
}
|
|
|
|
fetchCites() async {
|
|
cities = await UserApiClent().getAllCites(countryId.toString());
|
|
setState(() {
|
|
cities!.data?.forEach((element) {
|
|
citiesDropList.add(new DropValue(element.id ?? 0, (element.cityName ?? ""), element.id.toString() ?? ""));
|
|
});
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text(
|
|
"Define Branch",
|
|
),
|
|
),
|
|
body: Container(
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: Column(
|
|
children: [
|
|
country != null
|
|
? DropdownField((DropValue value) {
|
|
setState(() {
|
|
countryCode = value.subValue;
|
|
countryId = value.id;
|
|
fetchCites();
|
|
});
|
|
}, list: countryDropList, hint: "Chosse Country")
|
|
: CircularProgressIndicator(),
|
|
12.height,
|
|
if (countryId != -1)
|
|
cities != null
|
|
? DropdownField((DropValue value) {
|
|
setState(() {
|
|
// countryCode = value.subValue;
|
|
cityId = value.id;
|
|
});
|
|
}, list: citiesDropList, hint: "Chosse City")
|
|
: CircularProgressIndicator(),
|
|
12.height,
|
|
if (cityId != -1)
|
|
Column(
|
|
children: [
|
|
TxtField(
|
|
hint: "Branch Name",
|
|
value: branchName,
|
|
onChanged: (v) {
|
|
branchName = v;
|
|
},
|
|
),
|
|
12.height,
|
|
TxtField(
|
|
hint: "Branch Description",
|
|
value: branchDescription,
|
|
onChanged: (v) {
|
|
branchDescription = v;
|
|
},
|
|
),
|
|
12.height,
|
|
TxtField(
|
|
hint: "Address",
|
|
isNeedClickAll: true,
|
|
maxLines: 5,
|
|
value: address,
|
|
// onChanged: (v) {},
|
|
),
|
|
12.height,
|
|
ShowFillButton(
|
|
title: "Pick Address",
|
|
onPressed: () {
|
|
navigateTo(
|
|
context,
|
|
PickLocationPage(
|
|
onPickAddress: (double latitude, double longitude, String address) {
|
|
setState(() {
|
|
this.latitude = latitude;
|
|
this.longitude = longitude;
|
|
this.address = address;
|
|
});
|
|
},
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.all(12.0),
|
|
child: ShowFillButton(
|
|
title: "Create Branch",
|
|
onPressed: () async {
|
|
Utils.showLoading(context);
|
|
MResponse res = await BranchApiClent().createBranch(branchName, branchDescription, cityId.toString(), address, latitude.toString(), longitude.toString());
|
|
Utils.hideLoading(context);
|
|
Utils.showToast(res.message ?? "");
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|