import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.dart'; import 'package:manager_api_new/api.dart'; import 'package:manager_app/Components/rounded_button.dart'; import 'package:manager_app/Screens/Configurations/Section/SubSection/Map/category_list.dart'; import 'package:manager_app/constants.dart'; class CategoryInputContainer extends StatefulWidget { final Color color; final String label; List initialValue; final ValueChanged> onChanged; CategoryInputContainer({ Key? key, this.color = kSecond, required this.label, required this.initialValue, required this.onChanged, }) : super(key: key); @override _CategoryInputContainerState createState() => _CategoryInputContainerState(); } class _CategoryInputContainerState extends State { @override void initState() { super.initState(); } @override Widget build(BuildContext context) { Size size = MediaQuery.of(context).size; return Container( child: Row( children: [ Align( alignment: AlignmentDirectional.centerStart, child: Text(widget.label, style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300)) ), Padding( padding: const EdgeInsets.all(8.0), child: Container( width: size.width *0.15, child: InkWell( onTap: () { List newValues = []; List initials = widget.initialValue; showCreateOrUpdateCategories("Catégories", initials, newValues, (value) { widget.onChanged(value); widget.initialValue = value; }, context); }, child: Container( decoration: BoxDecoration( color: kPrimaryColor, borderRadius: BorderRadius.circular(50), ), child: Padding( padding: const EdgeInsets.only(left: 5, right: 5, top: 15, bottom: 15), child: Center( child: AutoSizeText( "Changer", style: TextStyle(color: kWhite), maxLines: 2, ) ), ) ), ), ), ), ], ), ); } } showCreateOrUpdateCategories(String modalLabel, List values, List newValues, Function onGetResult, BuildContext context) { showDialog( builder: (BuildContext context) { Size size = MediaQuery.of(context).size; return AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(20.0)) ), title: Center(child: Text(modalLabel)), content: SingleChildScrollView( child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(20), border: Border.all(width: 0.75, color: kSecond) ), height: size.height * 0.7, width: size.width * 0.65, child: CategoryList(categories: values, onChanged: (result) { newValues = result; onGetResult(result); }), ) ), actions: [ Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Container( width: 180, height: 70, child: RoundedButton( text: "Annuler", icon: Icons.undo, color: kSecond, press: () { onGetResult(values); Navigator.of(context).pop(); }, fontSize: 20, ), ), Container( width: 180, height: 70, child: RoundedButton( text: "Valider", icon: Icons.check, color: kPrimaryColor, textColor: kWhite, press: () { /*Function deepEq = const DeepCollectionEquality().equals; if (!deepEq(values, newValues)) { onGetResult(newValues); }*/ Navigator.of(context).pop(); }, fontSize: 20, ), ), ], ), ], ); }, context: context ); }