|
| 1 | +import 'package:flutter/gestures.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:inkino/assets.dart'; |
| 4 | +import 'package:url_launcher/url_launcher.dart'; |
| 5 | + |
| 6 | +class InKinoDrawerHeader extends StatefulWidget { |
| 7 | + @override |
| 8 | + _InKinoDrawerHeaderState createState() => new _InKinoDrawerHeaderState(); |
| 9 | +} |
| 10 | + |
| 11 | +class _InKinoDrawerHeaderState extends State<InKinoDrawerHeader> { |
| 12 | + static const String flutterUrl = 'https://flutter.io/'; |
| 13 | + static const String githubUrl = 'https://github.com/roughike/inKino'; |
| 14 | + static final TextStyle linkStyle = new TextStyle( |
| 15 | + color: Colors.blue, |
| 16 | + decoration: TextDecoration.underline, |
| 17 | + ); |
| 18 | + |
| 19 | + TapGestureRecognizer _flutterTapRecognizer; |
| 20 | + TapGestureRecognizer _githubTapRecognizer; |
| 21 | + |
| 22 | + @override |
| 23 | + void initState() { |
| 24 | + super.initState(); |
| 25 | + _flutterTapRecognizer = new TapGestureRecognizer() |
| 26 | + ..onTap = () => _openUrl(flutterUrl); |
| 27 | + _githubTapRecognizer = new TapGestureRecognizer() |
| 28 | + ..onTap = () => _openUrl(githubUrl); |
| 29 | + } |
| 30 | + |
| 31 | + @override |
| 32 | + void dispose() { |
| 33 | + _flutterTapRecognizer.dispose(); |
| 34 | + _githubTapRecognizer.dispose(); |
| 35 | + super.dispose(); |
| 36 | + } |
| 37 | + |
| 38 | + void _openUrl(String url) async { |
| 39 | + // Close the about dialog. |
| 40 | + Navigator.pop(context); |
| 41 | + |
| 42 | + if (await canLaunch(url)) { |
| 43 | + await launch(url); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + Widget _buildAppNameAndVersion(BuildContext context) { |
| 48 | + var textTheme = Theme.of(context).textTheme; |
| 49 | + |
| 50 | + return new Padding( |
| 51 | + padding: const EdgeInsets.all(16.0), |
| 52 | + child: new Column( |
| 53 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 54 | + mainAxisAlignment: MainAxisAlignment.end, |
| 55 | + children: <Widget>[ |
| 56 | + new Text( |
| 57 | + 'inKino', |
| 58 | + style: textTheme.display1.copyWith(color: Colors.white70), |
| 59 | + ), |
| 60 | + new Text( |
| 61 | + 'v1.0.1', // TODO: figure out a way to get this dynamically |
| 62 | + style: textTheme.body2.copyWith(color: Colors.white), |
| 63 | + ), |
| 64 | + ], |
| 65 | + ), |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + Widget _buildAboutButton(BuildContext context) { |
| 70 | + var content = new Row( |
| 71 | + mainAxisAlignment: MainAxisAlignment.end, |
| 72 | + children: <Widget>[ |
| 73 | + new Icon( |
| 74 | + Icons.info_outline, |
| 75 | + color: Colors.white70, |
| 76 | + size: 18.0, |
| 77 | + ), |
| 78 | + new Padding( |
| 79 | + padding: const EdgeInsets.only(left: 8.0), |
| 80 | + child: new Text( |
| 81 | + 'About', |
| 82 | + textAlign: TextAlign.end, |
| 83 | + style: new TextStyle( |
| 84 | + color: Colors.white70, |
| 85 | + fontSize: 12.0, |
| 86 | + ), |
| 87 | + ), |
| 88 | + ), |
| 89 | + ], |
| 90 | + ); |
| 91 | + |
| 92 | + return new Material( |
| 93 | + color: Colors.transparent, |
| 94 | + child: new InkWell( |
| 95 | + onTap: () { |
| 96 | + showDialog( |
| 97 | + context: context, |
| 98 | + child: _buildAboutDialog(context), |
| 99 | + ); |
| 100 | + }, |
| 101 | + child: new Padding( |
| 102 | + padding: const EdgeInsets.all(16.0), |
| 103 | + child: content, |
| 104 | + ), |
| 105 | + ), |
| 106 | + ); |
| 107 | + } |
| 108 | + |
| 109 | + Widget _buildAboutDialog(BuildContext context) { |
| 110 | + return new AlertDialog( |
| 111 | + title: new Text('About inKino'), |
| 112 | + content: new Column( |
| 113 | + mainAxisSize: MainAxisSize.min, |
| 114 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 115 | + children: <Widget>[ |
| 116 | + _buildAboutText(), |
| 117 | + _buildTMDBAttribution(), |
| 118 | + ], |
| 119 | + ), |
| 120 | + actions: <Widget>[ |
| 121 | + new FlatButton( |
| 122 | + onPressed: () { |
| 123 | + Navigator.of(context).pop(); |
| 124 | + }, |
| 125 | + textColor: Theme.of(context).primaryColor, |
| 126 | + child: new Text('Okay, got it!'), |
| 127 | + ), |
| 128 | + ], |
| 129 | + ); |
| 130 | + } |
| 131 | + |
| 132 | + Widget _buildAboutText() { |
| 133 | + return new RichText( |
| 134 | + text: new TextSpan( |
| 135 | + text: 'inKino is the unofficial Finnkino client that ' |
| 136 | + 'is minimalistic, fast, and delightful to use.\n\n', |
| 137 | + style: new TextStyle(color: Colors.black87), |
| 138 | + children: <TextSpan>[ |
| 139 | + new TextSpan(text: 'The app was developed with '), |
| 140 | + new TextSpan( |
| 141 | + text: 'Flutter', |
| 142 | + recognizer: _flutterTapRecognizer, |
| 143 | + style: linkStyle, |
| 144 | + ), |
| 145 | + new TextSpan( |
| 146 | + text: ' and it\'s open source; check out the source ' |
| 147 | + 'code yourself from ', |
| 148 | + ), |
| 149 | + new TextSpan( |
| 150 | + text: 'the GitHub repo', |
| 151 | + recognizer: _githubTapRecognizer, |
| 152 | + style: linkStyle, |
| 153 | + ), |
| 154 | + new TextSpan(text: '.'), |
| 155 | + ], |
| 156 | + ), |
| 157 | + ); |
| 158 | + } |
| 159 | + |
| 160 | + Widget _buildTMDBAttribution() { |
| 161 | + return new Padding( |
| 162 | + padding: const EdgeInsets.only(top: 16.0), |
| 163 | + child: new Row( |
| 164 | + children: <Widget>[ |
| 165 | + new Padding( |
| 166 | + padding: const EdgeInsets.only(top: 8.0), |
| 167 | + child: new Image.asset( |
| 168 | + ImageAssets.poweredByTMDBLogo, |
| 169 | + width: 32.0, |
| 170 | + ), |
| 171 | + ), |
| 172 | + new Expanded( |
| 173 | + child: new Padding( |
| 174 | + padding: const EdgeInsets.only(left: 12.0), |
| 175 | + child: new Text( |
| 176 | + 'This product uses the TMDb API but is not endorsed or certified by TMDb.', |
| 177 | + style: new TextStyle(fontSize: 12.0), |
| 178 | + ), |
| 179 | + ), |
| 180 | + ), |
| 181 | + ], |
| 182 | + ), |
| 183 | + ); |
| 184 | + } |
| 185 | + |
| 186 | + @override |
| 187 | + Widget build(BuildContext context) { |
| 188 | + return new Container( |
| 189 | + color: Theme.of(context).primaryColor, |
| 190 | + constraints: new BoxConstraints.expand(height: 175.0), |
| 191 | + child: new Row( |
| 192 | + mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 193 | + crossAxisAlignment: CrossAxisAlignment.end, |
| 194 | + children: <Widget>[ |
| 195 | + _buildAppNameAndVersion(context), |
| 196 | + _buildAboutButton(context), |
| 197 | + ], |
| 198 | + ), |
| 199 | + ); |
| 200 | + } |
| 201 | +} |
0 commit comments