1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| class MyPage extends StatelessWidget { MyPage({Key? key}) : super(key: key); Widget titleSection = Container( padding: const EdgeInsets.all(32), child: Row( children: [ Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text( "Hello,this is Alice!", style: TextStyle( fontWeight: FontWeight.bold, ), ), Text( "Good evening!", style: TextStyle( color: Colors.grey[500], ), ) ], ), ), const LikeWidget(), ], ), ); Widget options=Container( margin: const EdgeInsets.only(top: 10), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ Column( children: const [ Icon( Icons.call, color: Colors.blue, ), Text( "CALL", style: TextStyle( color: Colors.blue, ), ) ], ), Column( children: const [ Icon( Icons.route, color: Colors.blue, ), Text( "ROUTE", style: TextStyle( color: Colors.blue, ), ) ], ), Column( children: const [ Icon( Icons.share, color: Colors.blue, ), Text( "SHARE", style: TextStyle( color: Colors.blue, ), ) ], ), ], ), ); Widget text=Container( margin: const EdgeInsets.only(top: 10), padding: const EdgeInsets.all(30), child: const Text( "Something exciting happened when I got up this day. Maybe, but I am not sure about the time." ), ); @override Widget build(BuildContext context) { return Column( children: [ Image.asset( 'images/Alice.jpg', height: 300, fit: BoxFit.cover, ), titleSection, options, text ], ) ; } }
class LikeWidget extends StatefulWidget { const LikeWidget({Key? key}) : super(key: key);
@override State<LikeWidget> createState() => _LikeWidgetState(); }
class _LikeWidgetState extends State<LikeWidget> { bool _like=true; int _count=41;
void _clickLike(){ setState(() { if(_like){ _like=false; _count--; } else{ _like=true; _count++; } }); }
@override Widget build(BuildContext context) { return Row( children: [ IconButton( icon: _like?const Icon(Icons.star,color: Colors.red,):const Icon(Icons.star_border,color: Colors.red,), onPressed: _clickLike, ), Text( "$_count" ) ], ); } }
|