Add isSmall in image container

This commit is contained in:
Thomas Fransolet 2021-07-27 17:39:52 +02:00
parent b4a4d21c56
commit 9872eeb0e9

View File

@ -1,7 +1,6 @@
import 'package:auto_size_text/auto_size_text.dart'; import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:manager_app/Components/loading.dart'; import 'package:manager_app/Components/loading.dart';
import 'package:manager_app/Screens/Resources/fetch_image_for_resource.dart';
import 'package:manager_app/app_context.dart'; import 'package:manager_app/app_context.dart';
import 'package:manager_app/constants.dart'; import 'package:manager_app/constants.dart';
import 'package:manager_app/Screens/Resources/select_resource_modal.dart'; import 'package:manager_app/Screens/Resources/select_resource_modal.dart';
@ -14,6 +13,7 @@ class ImageInputContainer extends StatefulWidget {
final String initialValue; final String initialValue;
final ValueChanged<ResourceDTO> onChanged; final ValueChanged<ResourceDTO> onChanged;
final BoxFit imageFit; final BoxFit imageFit;
final bool isSmall;
const ImageInputContainer({ const ImageInputContainer({
Key key, Key key,
this.color = kSecond, this.color = kSecond,
@ -21,6 +21,7 @@ class ImageInputContainer extends StatefulWidget {
this.initialValue, this.initialValue,
this.onChanged, this.onChanged,
this.imageFit = BoxFit.cover, this.imageFit = BoxFit.cover,
this.isSmall = false,
}) : super(key: key); }) : super(key: key);
@override @override
@ -47,25 +48,26 @@ class _ImageInputContainerState extends State<ImageInputContainer> {
child: Text(widget.label, style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300)) child: Text(widget.label, style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300))
), ),
Padding( Padding(
padding: const EdgeInsets.all(10.0), padding: EdgeInsets.only(left: widget.isSmall ? 15 : 50, top: 10, bottom: 10),
child: Container( child: Container(
width: size.width *0.08, width: size.width *0.08,
child: InkWell( child: InkWell(
onTap: () { onTap: () async {
showSelectResourceModal( var result = await showSelectResourceModal(
"Sélectionner une ressource", "Sélectionner une ressource",
(ResourceDTO resource) {
widget.onChanged(resource);
setState(() {
resourceIdToShow = resource.id;
});
},
1, 1,
true, true,
context context
); );
if (result != null) {
setState(() {
resourceIdToShow = result.id;
});
widget.onChanged(result);
}
}, },
child: getElement(widget.initialValue, context), child: getElement(widget.initialValue, context, widget.isSmall),
), ),
), ),
), ),
@ -74,7 +76,7 @@ class _ImageInputContainerState extends State<ImageInputContainer> {
); );
} }
getElement(String initialValue, BuildContext context) { getElement(String initialValue, BuildContext context, bool isSmall) {
if (resourceIdToShow != null) { if (resourceIdToShow != null) {
Size size = MediaQuery.of(context).size; Size size = MediaQuery.of(context).size;
final appContext = Provider.of<AppContext>(context); final appContext = Provider.of<AppContext>(context);
@ -83,7 +85,7 @@ class _ImageInputContainerState extends State<ImageInputContainer> {
builder: (context, AsyncSnapshot<dynamic> snapshot) { builder: (context, AsyncSnapshot<dynamic> snapshot) {
if (snapshot.connectionState == ConnectionState.done) { if (snapshot.connectionState == ConnectionState.done) {
return Transform.scale( return Transform.scale(
scale: size.aspectRatio * 0.3, scale: isSmall ? size.aspectRatio * 0.5: size.aspectRatio,
child: AspectRatio( child: AspectRatio(
aspectRatio: 4/4, aspectRatio: 4/4,
child: Container( child: Container(