From 9872eeb0e9cc53a61685567779f82d3b1ed37a21 Mon Sep 17 00:00:00 2001 From: Thomas Fransolet Date: Tue, 27 Jul 2021 17:39:52 +0200 Subject: [PATCH] Add isSmall in image container --- lib/Components/image_input_container.dart | 28 ++++++++++++----------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/Components/image_input_container.dart b/lib/Components/image_input_container.dart index fbfd5a2..81ca685 100644 --- a/lib/Components/image_input_container.dart +++ b/lib/Components/image_input_container.dart @@ -1,7 +1,6 @@ import 'package:auto_size_text/auto_size_text.dart'; import 'package:flutter/material.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/constants.dart'; import 'package:manager_app/Screens/Resources/select_resource_modal.dart'; @@ -14,6 +13,7 @@ class ImageInputContainer extends StatefulWidget { final String initialValue; final ValueChanged onChanged; final BoxFit imageFit; + final bool isSmall; const ImageInputContainer({ Key key, this.color = kSecond, @@ -21,6 +21,7 @@ class ImageInputContainer extends StatefulWidget { this.initialValue, this.onChanged, this.imageFit = BoxFit.cover, + this.isSmall = false, }) : super(key: key); @override @@ -47,25 +48,26 @@ class _ImageInputContainerState extends State { child: Text(widget.label, style: TextStyle(fontSize: 25, fontWeight: FontWeight.w300)) ), Padding( - padding: const EdgeInsets.all(10.0), + padding: EdgeInsets.only(left: widget.isSmall ? 15 : 50, top: 10, bottom: 10), child: Container( width: size.width *0.08, child: InkWell( - onTap: () { - showSelectResourceModal( + onTap: () async { + var result = await showSelectResourceModal( "Sélectionner une ressource", - (ResourceDTO resource) { - widget.onChanged(resource); - setState(() { - resourceIdToShow = resource.id; - }); - }, 1, true, 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 { ); } - getElement(String initialValue, BuildContext context) { + getElement(String initialValue, BuildContext context, bool isSmall) { if (resourceIdToShow != null) { Size size = MediaQuery.of(context).size; final appContext = Provider.of(context); @@ -83,7 +85,7 @@ class _ImageInputContainerState extends State { builder: (context, AsyncSnapshot snapshot) { if (snapshot.connectionState == ConnectionState.done) { return Transform.scale( - scale: size.aspectRatio * 0.3, + scale: isSmall ? size.aspectRatio * 0.5: size.aspectRatio, child: AspectRatio( aspectRatio: 4/4, child: Container(