rsflutterapp

Bahnhofsfoto-App for Android and iOS using Flutter
git clone git://archive.git.mtrnord.blog/MTRNord/rsflutterapp.git
Log | Files | Refs | README

DetailsPage.dart (4636B)


      1 import 'dart:io';
      2 
      3 import 'package:flutter/gestures.dart';
      4 import 'package:flutter/material.dart';
      5 import 'package:maps_launcher/maps_launcher.dart';
      6 import 'package:multi_image_picker/multi_image_picker.dart';
      7 import 'package:url_launcher/url_launcher.dart';
      8 
      9 import '../models/models.dart';
     10 import '../repos/repositories.dart';
     11 
     12 class DetailsPage extends StatelessWidget {
     13   final Station station;
     14   final RailwayStationsRepository railwayStationsRepository;
     15 
     16   const DetailsPage(
     17       {Key key,
     18       @required this.station,
     19       @required this.railwayStationsRepository})
     20       : assert(railwayStationsRepository != null),
     21         super(key: key);
     22 
     23   Future<List<Asset>> _pickImages() async {
     24     List<Asset> resultList;
     25 
     26     try {
     27       resultList = await MultiImagePicker.pickImages(
     28         maxImages: 1,
     29         enableCamera: true,
     30         materialOptions: MaterialOptions(
     31           actionBarTitle: "Albums",
     32           allViewTitle: "All images",
     33           actionBarColor: "#c71c4d",
     34           actionBarTitleColor: "#ffffff",
     35           lightStatusBar: false,
     36           statusBarColor: '#c71c4d',
     37           startInAllView: false,
     38           selectCircleStrokeColor: "#000000",
     39           selectionLimitReachedText: "You can only upload one image at a time.",
     40           autoCloseOnSelectionLimit: true,
     41         ),
     42       );
     43     } on NoImagesSelectedException catch (e) {
     44       debugPrint("User selected nothing");
     45     } on Exception catch (e) {
     46       debugPrint(e.toString());
     47     }
     48 
     49     debugPrint(resultList.toString());
     50 
     51     return resultList;
     52   }
     53 
     54   @override
     55   Widget build(BuildContext context) {
     56     return Scaffold(
     57       appBar: AppBar(
     58         title: Text("Bahnhofs-Details"),
     59         actions: <Widget>[
     60           IconButton(
     61             icon: Icon(Icons.directions),
     62             onPressed: () {
     63               MapsLauncher.launchCoordinates(station.lat, station.lon);
     64             },
     65           ),
     66           IconButton(
     67             icon: Icon(Icons.list),
     68             onPressed: () async {
     69               Country country = (await railwayStationsRepository.getCountries())
     70                   .firstWhere((element) => element.code == station.country);
     71               await launch(country.timetableUrlTemplate
     72                   .replaceAll("{id}", station.idStr)
     73                   .replaceAll("{title}", station.title)
     74                   .replaceAll("{DS100}", station.ds100));
     75             },
     76           ),
     77         ],
     78       ),
     79       body: Column(
     80         mainAxisSize: MainAxisSize.max,
     81         mainAxisAlignment: MainAxisAlignment.spaceBetween,
     82         children: <Widget>[
     83           Text(
     84             station.title,
     85             style: Theme.of(context)
     86                 .primaryTextTheme
     87                 .headline3
     88                 .copyWith(color: Colors.black),
     89           ),
     90           station.photoUrl != null
     91               ? Image.network(station.photoUrl)
     92               : Container(),
     93           Expanded(
     94             child: Align(
     95               alignment: Alignment.bottomCenter,
     96               child: IconButton(
     97                 iconSize: 50,
     98                 icon: Icon(
     99                   Icons.camera_alt,
    100                   color: Theme.of(context).primaryColor,
    101                 ),
    102                 onPressed: () {
    103                   _pickImages();
    104                 },
    105               ),
    106             ),
    107           ),
    108           Padding(
    109             padding: EdgeInsets.all(24),
    110             child: Row(
    111               children: <Widget>[
    112                 Text(station.license != "" ? "Urheber: " : ""),
    113                 RichText(
    114                   text: TextSpan(
    115                     text: station.photographer,
    116                     style: TextStyle(
    117                       color: Theme.of(context).primaryColor,
    118                       decoration: TextDecoration.underline,
    119                     ),
    120                     recognizer: TapGestureRecognizer()
    121                       ..onTap = () {
    122                         launch(station.photographerUrl);
    123                       },
    124                   ),
    125                 ),
    126                 Text(station.license != "" ? ", " : ""),
    127                 RichText(
    128                   text: TextSpan(
    129                     text: station.license,
    130                     style: TextStyle(
    131                       color: Theme.of(context).primaryColor,
    132                       decoration: TextDecoration.underline,
    133                     ),
    134                     recognizer: TapGestureRecognizer()
    135                       ..onTap = () {
    136                         launch(station.licenseUrl);
    137                       },
    138                   ),
    139                 ),
    140               ],
    141             ),
    142           ),
    143         ],
    144       ),
    145     );
    146   }
    147 }