import 'package:flutter/material.dart'; import 'package:android_intent/android_intent.dart'; import 'package:share/share.dart'; import 'global_helper_functions.dart'; class Location extends StatefulWidget { final String mapLocation; Location({ Key key, this.mapLocation, }) : super(key: key); @override _LocationState createState() => _LocationState(); } class _LocationState extends State { @override Widget build(BuildContext context) { final double textHeight = 1.5; List locationStringList = _getlocationStringList(widget.mapLocation); Future _launchUrl() async{ AndroidIntent intent = AndroidIntent( action: 'action_view', data: Uri.encodeFull(locationStringList[locationStringList.length - 1]), ); await intent.launch(); } List createLocation(List location) { return location.map((line) { line = (line.length < 25) ? line : (line.substring(0,20) + '.....' ); return Container( child: Text( line, style: TextStyle( height: textHeight, fontSize: 16.0, ), ), ); }).toList(); } try { return Row( children: [ Expanded( flex: 3, child: IconButton( icon: Icon(Icons.share), tooltip: 'share link to another app', iconSize: 48, onPressed: () { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( backgroundColor: ivory, shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(6.0)), ), title: Text( 'Sharing Options', textAlign: TextAlign.center, style: TextStyle( color: candyApple, ), ), content: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ IconButton( icon: Icon(Icons.share), tooltip: 'share link to another app', iconSize: 48, onPressed: () { Navigator.of(context).pop(); Share.share(widget.mapLocation); }, ), IconButton( icon: Icon(Icons.map), tooltip: 'share link to maps', iconSize: 48, onPressed: () { Navigator.of(context).pop(); _launchUrl(); }, ), ], ), ); } ); }, ), ), Expanded( flex: 7, child: InkWell( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: createLocation(locationStringList), ), onTap: () { showDialog( context: context, builder: (BuildContext context) { return AlertDialog( backgroundColor: ivory, shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(6.0)), ), content: Column( mainAxisSize: MainAxisSize.min, children: [ Container( margin: EdgeInsets.only( bottom: 25, ), child: Text( widget.mapLocation, textAlign: TextAlign.center, ), ), RaisedButton( shape: RoundedRectangleBorder( borderRadius: BorderRadius.all(Radius.circular(6.0)), ), color: peacockBlue, child: Container( margin: EdgeInsets.only( top: 12, bottom: 20, ), child: Text( 'ok', style: TextStyle( height: textHeight, color: Colors.white, fontSize: 24, ), ), ), onPressed: () { Navigator.of(context).pop(); } ), ], ), ); } ); }, ), ), ], ); } catch(e) { print('$e, probably could not call createLocation(locationStringList)'); return Wrap( spacing: 20.0, children: [ Text( 'Pending...', style: TextStyle(height: textHeight), ), ], ); } } List _getlocationStringList(String mapLocation) { List stringList; try { stringList = mapLocation.split('\n'); } catch(e) { print('$e in source file location.dart._getlocationStringList::first_try'); } if (stringList.length < 2) { return ['','pending...','']; } else { try { if (stringList[1].contains(stringList[0])) { stringList.removeAt(0); } } catch(e) { print('$e in source file location.dart._getlocationStringList::second_try'); } // split up long address lines on the second to last comma for (int i=0; i 1) { String currentLine = stringList[i]; stringList.removeAt(i); int commaCount = 0; for (int j=0; j