avatarRicha S

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

6856

Abstract

edFileExtension = selectedFileName.split(‘.’).last; <span class="hljs-keyword">if</span>(allowedFormats != <span class="hljs-literal">null</span> || allowedFormats.isNotEmpty) { <span class="hljs-keyword">if</span>(!allowedFormats.contains(‘selectedFileExtension’)) { print(selectedFileName); message = ‘<span class="hljs-type">Selected</span> file format { selectedFileExtension } isn\’ allowed’; <span class="hljs-keyword">return</span> <span class="hljs-type">FilePickerWrapperFailedResult</span>(errorMessage: message,code: <span class="hljs-number">0</span>); } }

<span class="hljs-keyword">if</span> ( maxFileSizeAllowed < file.lengthSync() / <span class="hljs-number">1024</span>) { message = ‘<span class="hljs-type">File</span> size exceed, maximum file size allowed($maxFileSizeAllowed kB)’; <span class="hljs-keyword">return</span> <span class="hljs-type">FilePickerWrapperFailedResult</span>(errorMessage: message,code: <span class="hljs-number">0</span>); } <span class="hljs-keyword">return</span> <span class="hljs-type">FilePickerWrapperSuccessResult</span>(code: <span class="hljs-number">1</span>,filePath: file.path, fileName: selectedFileName); } }

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">FilePickerWrapperResult</span> </span>{ int code; <span class="hljs-comment">// 1 means success result, 0 means failed or error result </span> }

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">FilePickerWrapperSuccessResult</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FilePickerWrapperResult</span> </span>{ <span class="hljs-type">FilePickerWrapperSuccessResult</span>({<span class="hljs-meta">@required</span> <span class="hljs-keyword">this</span>.filePath, <span class="hljs-meta">@required</span> <span class="hljs-keyword">this</span>.fileName, <span class="hljs-meta">@required</span> int code}) { <span class="hljs-keyword">this</span>.code = code; } <span class="hljs-type">String</span> filePath; <span class="hljs-type">String</span> fileName; }

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">FilePickerWrapperFailedResult</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">FilePickerWrapperResult</span> </span>{ <span class="hljs-type">FilePickerWrapperFailedResult</span>({<span class="hljs-meta">@required</span> <span class="hljs-keyword">this</span>.errorMessage, <span class="hljs-meta">@required</span> int code}) { <span class="hljs-keyword">this</span>.code = code; } <span class="hljs-type">String</span> errorMessage; }</pre></div><p id="bb4a">In this helper class, we added functionality to select the image from the gallery app on the device. Now create a new file and name it <b>image_picker_wrapper.dart.</b></p><h1 id="c228">Enabling image selection</h1><p id="d038">Add the following code to this file:</p><div id="ef30"><pre>import ‘dart:io’; import ‘package:facerecognition/supporting_files/file_picker_wrapper.dart’; import ‘package:flutter/cupertino.dart’; import ‘package:flutter/material.dart’; import ‘package:image_picker/image_picker.dart’;

typedef ImagePickerResult = <span class="hljs-keyword">void</span> <span class="hljs-title function_ invoke__">Function</span>(FilePickerWrapperResult result);

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ImagePickerWrapper</span> </span>{ <span class="hljs-title function_ invoke__">ImagePickerWrapper</span>({ @required ImagePickerResult imagePickerResult, <span class="hljs-keyword">double</span> maxFileSizeAllowed = <span class="hljs-number">2024</span> //size in kb }) { this._imagePickerResult = imagePickerResult; this._maxFileSizeAllowed = maxFileSizeAllowed; } ImagePickerResult _imagePickerResult; <span class="hljs-keyword">double</span> _maxFileSizeAllowed;

<span class="hljs-keyword">void</span> <span class="hljs-title function_ invoke__">openImagePickerActionSheet</span>({@required BuildContext buildContext}) { <span class="hljs-keyword">if</span>(buildContext == <span class="hljs-literal">null</span>) { <span class="hljs-keyword">print</span>(‘build content can’’\’t be <span class="hljs-keyword">empty</span>’); <span class="hljs-keyword">return</span>; } <span class="hljs-keyword">if</span> (Platform.isIOS) { <span class="hljs-title function_ invoke__">_actionSheet</span>(buildContext); } <span class="hljs-keyword">else</span> { <span class="hljs-title function_ invoke__">_androidBottomSheet</span>(buildContext); } }

<span class="hljs-comment">//For ios </span> <span class="hljs-keyword">void</span> <span class="hljs-title function_ invoke__">_actionSheet</span>(BuildContext context) { _containerForSheet<String>( context: context, child: <span class="hljs-title function_ invoke__">CupertinoActionSheet</span>( <span class="hljs-attr">title</span>: <span class="hljs-title function_ invoke__">Text</span>(‘’), <span class="hljs-attr">message</span>: <span class="hljs-title function_ invoke__">Text</span>(‘’), <span class="hljs-attr">actions</span>: <Widget>[ <span class="hljs-title function_ invoke__">CupertinoActionSheetAction</span>( <span class="hljs-attr">child</span>: <span class="hljs-title function_ invoke__">Text</span>(‘Camera’), <span class="hljs-attr">onPressed</span>: () { <span class="hljs-title function_ invoke__">_openCamera</span>(ImageSource.camera); }, ), <span class="hljs-title function_ invoke__">CupertinoActionSheetAction</span>( <span class="hljs-attr">child</span>: <span class="hljs-title function_ invoke__">Text</span>(‘Gallery’), <span class="hljs-attr">onPressed</span>: () async { <span class="hljs-title function_ invoke__">_openFileExplorer</span>(); }, ), ], cancelButton: <span class="hljs-title function_ invoke__">CupertinoActionSheetAction</span>( <span class="hljs-attr">child</span>: <span class="hljs-title function_ invoke__">Text</span>(‘Cancel’), <span class="hljs-attr">isDefaultAction</span>: <span class="hljs-literal">true</span>, <span class="hljs-attr">onPressed</span>: () { Navigator.<span class="hljs-title function_ invoke__">pop</span>(context, ‘Cancel’); }, ))); }

<span class="hljs-keyword">void</span> _containerForSheet<T>({BuildContext context, Widget child}) { showCupertinoModalPopup<T>( context: context, builder: (BuildContext context) => child, ).then<<span class="hljs-keyword">void</span>>((T value) { }); }

<span class="hljs-comment">//For Android </span> <span class="hljs-keyword">void</span> <span class="hljs-title function_ invoke__">_androidBottomSheet</span>(BuildContext context) { show

Options

ModalBottomSheet<<span class="hljs-keyword">void</span>>( context: context, builder: (BuildContext context) { <span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">Container</span>( <span class="hljs-attr">margin</span>: <span class="hljs-keyword">const</span> EdgeInsets.<span class="hljs-title function_ invoke__">only</span>(<span class="hljs-attr">left</span>: <span class="hljs-number">20.0</span>, <span class="hljs-attr">right</span>: <span class="hljs-number">20.0</span>), <span class="hljs-attr">child</span>: <span class="hljs-title function_ invoke__">Wrap</span>( <span class="hljs-attr">children</span>: <Widget>[ <span class="hljs-title function_ invoke__">ListTile</span>( <span class="hljs-attr">leading</span>: <span class="hljs-title function_ invoke__">Icon</span>(Icons.camera), <span class="hljs-attr">title</span>: <span class="hljs-title function_ invoke__">Text</span>(‘Camera’), <span class="hljs-attr">onTap</span>: () { <span class="hljs-title function_ invoke__">_openCamera</span>(ImageSource.camera); }), <span class="hljs-title function_ invoke__">ListTile</span>( <span class="hljs-attr">leading</span>: <span class="hljs-keyword">const</span> <span class="hljs-title function_ invoke__">Icon</span>(Icons.landscape), <span class="hljs-attr">title</span>: <span class="hljs-title function_ invoke__">Text</span>(‘Gallery’), <span class="hljs-attr">onTap</span>: () { // <span class="hljs-title function_ invoke__">_openFileExplorer</span>(); <span class="hljs-title function_ invoke__">_openCamera</span>(ImageSource.gallery); }, ), ], ), ); }); }

Future<<span class="hljs-keyword">void</span>> <span class="hljs-title function_ invoke__">_openCamera</span>(ImageSource source) async { File imageSelected = await ImagePicker.<span class="hljs-title function_ invoke__">pickImage</span>( <span class="hljs-attr">source</span>: source, <span class="hljs-attr">maxHeight</span>: <span class="hljs-number">400</span>, <span class="hljs-attr">maxWidth</span>: <span class="hljs-number">400</span>); <span class="hljs-keyword">if</span> (imageSelected != <span class="hljs-literal">null</span>) { <span class="hljs-keyword">final</span> String fileName = imageSelected.path.<span class="hljs-title function_ invoke__">split</span>(‘/’).last; <span class="hljs-keyword">if</span> ( _maxFileSizeAllowed < imageSelected.<span class="hljs-title function_ invoke__">lengthSync</span>() / <span class="hljs-number">1024</span>) { String message = ‘File size exceed, maximum file size <span class="hljs-title function_ invoke__">allowed</span>(<span class="hljs-variable">$_maxFileSizeAllowed</span> kB)’; <span class="hljs-title function_ invoke__">_imagePickerResult</span>(<span class="hljs-title function_ invoke__">FilePickerWrapperFailedResult</span>(<span class="hljs-attr">errorMessage</span>: message,<span class="hljs-attr">code</span>: <span class="hljs-number">0</span>)); } <span class="hljs-title function_ invoke__">_imagePickerResult</span>(<span class="hljs-title function_ invoke__">FilePickerWrapperSuccessResult</span>(<span class="hljs-attr">code</span>: <span class="hljs-number">1</span>,<span class="hljs-attr">filePath</span>: imageSelected.path, <span class="hljs-attr">fileName</span>: fileName)); } <span class="hljs-keyword">else</span> { <span class="hljs-title function_ invoke__">_imagePickerResult</span>(<span class="hljs-title function_ invoke__">FilePickerWrapperFailedResult</span>(<span class="hljs-attr">errorMessage</span>: ‘Failed to get the image’,<span class="hljs-attr">code</span>: <span class="hljs-number">0</span>)); } }

Future<<span class="hljs-keyword">void</span>> <span class="hljs-title function_ invoke__">_openFileExplorer</span>() async { <span class="hljs-keyword">final</span> FilePickerWrapperResult wrapperResult = await <span class="hljs-title function_ invoke__">FilePickerWrapper</span>() .<span class="hljs-title function_ invoke__">openFileExplorer</span>( <span class="hljs-attr">maxFileSizeAllowed</span>: <span class="hljs-number">2048</span>, <span class="hljs-attr">fileFormatsAllowed</span>: [‘jpeg’, ‘png’, ‘jpg’]); <span class="hljs-title function_ invoke__">_imagePickerResult</span>(wrapperResult); } }</pre></div><p id="f671">This helper class will provide the functionality to pick an image from the device’s gallery app or take a new one using the device’s camera. The alerts style will be as per the platform (i.e., on iOS, it will be shown in Cupertino style, and, on the Android platform, it will be displayed using Material style).</p><p id="4867">In this blog, we have examined the steps needed to create a UI in Flutter to allow users to pick images from their phones for use with Amazon Rekognition.</p><p id="2179">Next, we design a UI to allow the user to pick images and implement the functionality to pick image/s either from the camera or mobile storage. In the next part of this blog, we will focus on:</p><ul><li>Initiating the action of comparison.</li><li>Convert the raw result into a model.</li><li>Display the result of the comparison.</li></ul><p id="9c29">Read the next part of the blog on implementing facial recognition where we cover these topics:</p><div id="eb9f" class="link-block"> <a href="https://readmedium.com/implementing-facial-recognition-in-flutter-apps-1e99a23ac9c4"> <div> <div> <h2>Implementing Facial Recognition in Flutter Apps</h2> <div><h3>Read our blog to learn how to implement Facial Recognition in Flutter Apps using Amazon Rekognition.</h3></div> <div><p>DLT Labs on medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/1*aGrAV7khLCz6_oKQmAG29w.png)"></div> </div> </div> </a> </div><p id="ca73"><i>Amazon Rekognition is the intellectual property of Amazon Inc. Flutter is a trademark of Google LLC.</i></p><p id="e5a4"><i>Author — Suhail Shabir, DLT Labs</i></p><p id="0f4a"><b>About the Author: </b><i>Suhail </i>is an application development professional who has worked on different platforms and technologies. He has completed his Bachelors in Computer Application from Kashmir University.</p><p id="e3ea">Disclaimer: This article was originally published on the DLT Labs Blog page: <a href="https://www.dltlabs.com/blog/enabling-facial-recognition-in-flutterapps-764220">https://www.dltlabs.com/blog/enabling-facial-recognition-in-flutterapps-764220</a></p><figure id="2629"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*0Rjo1bW8T-fHbjiq.png"><figcaption></figcaption></figure></article></body>

How P&G Improved Culture to Engage Employees

And kept the innovation engines churning…

Photo by Thành ‎ on Unsplash

This one is close to my heart as it comes from the 8+ years’ experience observing different facets of one of the larger FMCG company, P&G when I worked there.

My work exposed me to businesses and people in Asia, Middle East, Europe and North America.

Consider this a perspective of a mid-level management on how culture affects everything we do and why it’s important everyone contributes in building it.

I saw both the best and the worst examples of culture in my time there.

You may treat this as an opportunity to study human response to changes in external environment. These are the stories we read about in college case studies. This one I got to be a part of.

Here it is.

I joined P&G as a Plant Operations Manager in July 2010 after finishing my MBA from IIT Delhi, India. What attracted me was everything that’s on the wishlist of a fresh employee.

The range of benefits such as exceptional home loan and car loan policies, instant business travel opportunities (what could a globetrotter in spirit like me want more) and bonus, freedom to find who you are.

The huge manufacturing converter lines stretching over miles of space fascinated my engineer brain beyond words.

‘You are a product of the environment, but you also contribute to it.’ — Richa Singh

An early view of Pros & Cons

The first two years went by quickly.

Strengths I observed

  • P&G was an Innovation engine churning out ideas with a 50% success rate in all businesses.

They were either Number 1 or 2 in every business they had and in every country they were in. Their strategy was to hire the best people, focus on core capabilities, and have a solid leadership development model.

  • They dreamt big and always kept pushing for more and more. We learned to consider how what we do affects end consumer. We learned to experience walk through customer journeys.

‘If it wasn’t big enough, it wasn’t interesting.’

  • Strong ethics and code formed the backbone. P&G lived and breathed its code of conduct.

Shortcomings

  • Promote from within : You would join only at entry level. The company promoted all senior roles from within and did not hire externally.

This also made me feel like I signed up for a cult without meaning to. It often led to a closed-minded circle. Everything external seemed to be mistrusted, and internal methodologies glorified.

  • Slow decision making caused a long time to action — whether it was a business decision or a personnel one, it took months and sometimes years to decide.

When I requested to be moved from a plant to head office in Mumbai, it took over a year. It took me a similar time to move to Europe from India.

  • Talking only about wins (the pile of mess kept growing) ! — It surprised me how people only spoke about the big wins.

Often no one was interested in looking at the mess that accompanies all work. Result being the pile of mess kept growing year on year.

Fortunes turned

Before 2012, P&G strategies and innovation worked. They did well globally; nothing seemed like a barrier to this giant.

Things started changing from 2012.

This time, it was different. Initially, I heard our senior leaders say we always go through cycles, but then this cycle seemed unlike any other when nothing changed or improved in 2 years.

Markets like India and China, which used to see double digit growth, seemed dry. There were new competitors emerging who were becoming profitable quickly with newer models and newer ways of thinking.

There was no growth in US and EU, the more stable markets for business. The changes seemed irreversible and too complex to do anything about.

Everyone was asking one question- why did we stop growing?

The New Normal

Silos became prominent. The dual country and global reporting structure was failing. People questioned if P&G was a marketing company or a manufacturing company?

The influence was in Marketing, all ex-CEOs belonged to ‘Marketing’.

It was ‘Marketing’ which came up with revolutionary and sexy strategies. However, the bread and butter or the unsexy part of the core was ‘Manufacturing’.

The core was slow, tardy and failed to move. It rejected major innovation ideas that R&D and marketing brought forward. The gap was increasing.

Productivity cuts of 50% over two years from top to bottom affected morale.

People started losing hope. P&G wasn’t growing, and they weren’t too, and it looked like it wasn’t just a cycle this time. The opportunities for growth had dried up. It took a while to acknowledge culture was the problem.

New low-key CEO joins

This was when David Taylor joined as the CEO in 2015.

Leadership set the tone of ‘Straight talk’, as senior leaders recognized communication was so indirect that they weren’t understanding what the actual issues on ground were. This started improving the culture.

David was a very different guy from what P&G had before as a CEO. Introverted, underselling. Most remarkable thing about him was he started his career from scratch after he had risen as an executive in Operations.

He went to Marketing and started from scratch as an ‘Assistant Brand Manager’ after years in Operations. Something which was unheard of.

This made him understand both the worlds of ‘Manufacturing’ and ‘Marketing’ accurately. Something which was needed to turn the tide.

He didn’t get a warm welcome. In fact, people remained sceptical. He re-emphasized the focus on the core and started being more real, rather than braggy.

After a few months, the Board fights turned hostile and came to light. An investor called Nelson Peltz wanted to break up P&G into 2–3 companies.

The Ugly Fighting Period

Peltz forced himself in. David had the job of managing him and improving the relationship. While also taking care of what the employees wanted.

As solutions are being considered, the infighting continued.

P&G tried to hire new people in technology at the senior levels. People questioned, ‘Will P&G change who they are — hire externally instead of growing from within?

Can you imagine being in this company as a new senior person where you have all 20+ experienced veterans who have a certain way of working?

David’s guidance was to keep the core running and experiment on the side. He knew he couldn’t change P&G completely else it would lose its essence.

They could change slowly with time, but not overnight. So they sought to buy new companies who could grow. Somewhat similar to what Indra Nooyi did at Pepsico a few years ago.

The best part was they made the conscious choice that we won’t change the culture of the new companies we buy, and let them operate independently.

The Dawn Comes Yet Again

Slowly, P&G started winning by the end of 2018, after 6 long years. Employees’ confidence came back and P&G started growing like before.

The new companies started doing well, and motivated the older P&G business to innovate with fresh energy.

David, well supported by an entire team brought a huge cultural revolution where new methods gained acceptance.

  • There was transparent communication from the get-go
  • Escalations became normal
  • Walking the talk by noting inconsistencies between communication and action. Then reducing them by promoting healthy debates.
  • Fewer silos
  • Being open to diverse talents and ideas.

All these tactics helped P&G gain back its glory and move on even strongly than before.

‘Leadership is absolutely about inspiring action, but it is also about guarding against mis-action.’ — Simon Sinek

Unfortunately, I quit because of moving to another location with my family around late 2018. But, I still feel proud of P&G’s journey of resilience, leadership and teamwork.

Download my free e-book on navigating international career transitions successfully here :

Ideas
Future
Diversity
Culture
Culture Change
Recommended from ReadMedium