Skip to content

Instantly share code, notes, and snippets.

@samuchakraborty
Created July 4, 2023 08:57
Show Gist options
  • Save samuchakraborty/ff0219961539ce93da37ce3eb025354d to your computer and use it in GitHub Desktop.
Save samuchakraborty/ff0219961539ce93da37ce3eb025354d to your computer and use it in GitHub Desktop.
riverpod
import '../widgets/change_vehicle_card_widget.dart';
import '../widgets/continue_button.dart';
class ChangeVehicleScreen extends StatefulWidget {
const ChangeVehicleScreen({
super.key,
});
@override
State<ChangeVehicleScreen> createState() => _ChangeVehicleScreenState();
}
class _ChangeVehicleScreenState extends State<ChangeVehicleScreen> {
bool isCheck = false;
List<int> selected = [];
@override
Widget build(BuildContext context) {
return Material(
child: Consumer(builder: (context, ref, child) {
final getVehicleTypeProvider = ref.watch(getVehicleTypeListProvider);
return getVehicleTypeProvider.when(
skipLoadingOnRefresh: false,
data: (data) {
VehicleTypeListModel vehicleTypeListModel =
VehicleTypeListModel.fromJson(data);
return ListView(
padding: const EdgeInsets.symmetric(horizontal: 10),
physics: const BouncingScrollPhysics(),
children: [
const SizedBox(
height: 50,
),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
GestureDetector(
onTap: () => Navigator.pop(context),
child: const Icon(
Icons.close_outlined,
size: 24,
),
),
],
),
Text(
"Change Your Vehicle",
style: TextStyle(
color: ColorCode.mainColor,
fontSize: 20.sp,
fontFamily: "Montserrat",
fontWeight: FontWeight.w600,
),
),
SizedBox(
height: 10.h,
),
ListView.separated(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: vehicleTypeListModel.data!.length,
itemBuilder: (context, i) {
return Stack(
children: [
ChangeVehicleCard(
vehicleTypeList: vehicleTypeListModel.data![i],
),
Positioned(
top: 40,
right: 10,
child: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
if (selected.contains(i)) {
setState(() {
selected = [];
selected.remove(i);
});
} else {
setState(() {
selected = [];
selected.add(i);
});
}
},
child: selected.contains(i)
? SizedBox(
width: 30,
height: 30,
child: SvgPicture.asset(
AssetImages.rightIconImage,
fit: BoxFit.cover,
),
)
: Container(
width: 30,
height: 30,
decoration: ShapeDecoration(
shape: OvalBorder(
side: BorderSide(
width: 1.50,
color: ColorCode.mainColor),
),
),
),
),
)
],
);
},
separatorBuilder: (BuildContext context, int index) =>
SizedBox(
height: 20.h,
),
),
SizedBox(
height: 30.h,
),
if (selected.isEmpty) ...[
ContinueButton(
text: "Save",
backgroundColor: Colors.white,
borderColor: ColorCode.mainColor,
textColor: ColorCode.greyBlackColor,
onPressed: () {},
),
],
if (selected.isNotEmpty) ...[
ContinueButton(
text: "Save",
backgroundColor: ColorCode.mainColor,
borderColor: ColorCode.mainColor,
textColor: Colors.white,
onPressed: () {
Navigator.pop(context, selected);
},
),
],
],
);
},
error: (error, statTrace) {
return NetWorkErrorWidget(
error: error.toString(),
onPressed: () => ref.refresh(getVehicleTypeListProvider),
);
},
loading: () => const Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
children: [
LoaderWidget(),
],
),
);
}),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment