Advertisement
rajath_pai

UI 2 - place info

Aug 7th, 2021
1,446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 4.28 KB | None | 0 0
  1. // https://imgur.com/bQ7isDj
  2.  
  3. import 'package:flutter/material.dart';
  4.  
  5. void main() => runApp(MyApp());
  6.  
  7. class MyApp extends StatelessWidget {
  8.   const MyApp({Key? key}) : super(key: key);
  9.  
  10.   @override
  11.   Widget build(BuildContext context) {
  12.     Color color = Theme.of(context).primaryColor;
  13.  
  14.     Widget buttonSection = Row(
  15.       mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  16.       children: [
  17.         _buildButtonColumn(color, Icons.call, "CALL"),
  18.         _buildButtonColumn(color, Icons.near_me, "ROUTE"),
  19.         _buildButtonColumn(color, Icons.share, "SHARE"),
  20.       ],
  21.     );
  22.  
  23.     return MaterialApp(
  24.       title: "Flutter layout demo",
  25.       home: Scaffold(
  26.         appBar: AppBar(
  27.           title: const Text("Flutter layout demo"),
  28.         ),
  29.         body: ListView(
  30.           children: [
  31.             Image.network(
  32.               "https://raw.githubusercontent.com/flutter/website/master/examples/layout/lakes/step5/images/lake.jpg",
  33.               width: 600,
  34.               height: 240,
  35.               fit: BoxFit.cover,
  36.             ),
  37.             titleSection,
  38.             buttonSection,
  39.             textSection,
  40.           ],
  41.         ),
  42.       ),
  43.     );
  44.   }
  45.  
  46.   Column _buildButtonColumn(Color color, IconData icon, String label) {
  47.     return Column(
  48.       mainAxisSize: MainAxisSize.min,
  49.       mainAxisAlignment: MainAxisAlignment.center,
  50.       children: [
  51.         Icon(
  52.           icon,
  53.           color: color,
  54.         ),
  55.         Container(
  56.           margin: EdgeInsets.only(top: 8),
  57.           child: Text(
  58.             label,
  59.             style: TextStyle(
  60.               fontSize: 12.0,
  61.               fontWeight: FontWeight.w400,
  62.               color: color,
  63.             ),
  64.           ),
  65.         ),
  66.       ],
  67.     );
  68.   }
  69. }
  70.  
  71. Widget textSection = const Padding(
  72.   padding: EdgeInsets.all(32),
  73.   child: Text(
  74.     'Lake Oeschinen lies at the foot of the Blüemlisalp in the Bernese '
  75.     'Alps. Situated 1,578 meters above sea level, it is one of the '
  76.     'larger Alpine Lakes. A gondola ride from Kandersteg, followed by a '
  77.     'half-hour walk through pastures and pine forest, leads you to the '
  78.     'lake, which warms to 20 degrees Celsius in the summer. Activities '
  79.     'enjoyed here include rowing, and riding the summer toboggan run.',
  80.     softWrap: true,
  81.   ),
  82. );
  83.  
  84. Widget titleSection = Container(
  85.   padding: const EdgeInsets.all(32.0),
  86.   child: Row(
  87.     children: [
  88.       Expanded(
  89.         child: Column(
  90.           crossAxisAlignment: CrossAxisAlignment.start,
  91.           children: [
  92.             Container(
  93.               padding: const EdgeInsets.only(bottom: 8),
  94.               child: const Text(
  95.                 "Oeschinen Lake Campground",
  96.                 style: TextStyle(
  97.                   fontWeight: FontWeight.bold,
  98.                 ),
  99.               ),
  100.             ),
  101.             Text(
  102.               "Kandersteg, Switzerland",
  103.               style: TextStyle(
  104.                 color: Colors.grey[500],
  105.               ),
  106.             ),
  107.           ],
  108.         ),
  109.       ),
  110.       FavoriteWidget(),
  111.     ],
  112.   ),
  113. );
  114.  
  115. class FavoriteWidget extends StatefulWidget {
  116.   const FavoriteWidget({Key? key}) : super(key: key);
  117.  
  118.   @override
  119.   _FavoriteWidgetState createState() => _FavoriteWidgetState();
  120. }
  121.  
  122. class _FavoriteWidgetState extends State<FavoriteWidget> {
  123.   bool _isFavorited = true;
  124.   int _favoriteCount = 41;
  125.  
  126.   @override
  127.   Widget build(BuildContext context) {
  128.     return Row(
  129.       mainAxisSize: MainAxisSize.min,
  130.       children: [
  131.         Container(
  132.           padding: const EdgeInsets.all(0),
  133.           child: IconButton(
  134.             padding: const EdgeInsets.all(0),
  135.             alignment: Alignment.centerRight,
  136.             icon: (_isFavorited
  137.                 ? const Icon(Icons.star)
  138.                 : const Icon(Icons.star_border)),
  139.             color: Colors.red[500],
  140.             onPressed: _toggleFavorite,
  141.           ),
  142.         ),
  143.         SizedBox(
  144.           width: 18,
  145.           child: SizedBox(
  146.             child: Text("$_favoriteCount"),
  147.           ),
  148.         ),
  149.       ],
  150.     );
  151.   }
  152.  
  153.   void _toggleFavorite() {
  154.     setState(() {
  155.       if (_isFavorited) {
  156.         _favoriteCount -= 1;
  157.         _isFavorited = false;
  158.       } else {
  159.         _favoriteCount += 1;
  160.         _isFavorited = true;
  161.       }
  162.     });
  163.   }
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement