Created
November 20, 2020 16:41
-
-
Save Zaryob/bd5bd1092ffac86bbfac84d63b46b2a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/material.dart'; | |
| void main() => runApp(MyApp()); | |
| class MyApp extends StatelessWidget { | |
| final appTitle = 'Main Page'; | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| title: appTitle, | |
| home: MyHomePage(title: appTitle), | |
| ); | |
| } | |
| } | |
| class StarDisplayWidget extends StatelessWidget { | |
| final int value; | |
| final Widget filledStar; | |
| final Widget unfilledStar; | |
| const StarDisplayWidget({ | |
| Key key, | |
| this.value = 0, | |
| @required this.filledStar, | |
| @required this.unfilledStar, | |
| }) : assert(value != null), | |
| super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Row( | |
| mainAxisSize: MainAxisSize.min, | |
| children: List.generate(5, (index) { | |
| return index < value ? filledStar : unfilledStar; | |
| }), | |
| ); | |
| } | |
| } | |
| class StarDisplay extends StarDisplayWidget { | |
| const StarDisplay({Key key, int value = 0}) | |
| : super( | |
| key: key, | |
| value: value, | |
| filledStar: const Icon(Icons.star), | |
| unfilledStar: const Icon(Icons.star_border), | |
| ); | |
| } | |
| class IMBDListItem extends StatelessWidget { | |
| const IMBDListItem({ | |
| this.thumbnail, | |
| this.title, | |
| this.user, | |
| this.starCount, | |
| }); | |
| final Widget thumbnail; | |
| final String title; | |
| final String user; | |
| final int starCount; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Padding( | |
| padding: const EdgeInsets.symmetric(vertical: 5.0), | |
| child: Row( | |
| crossAxisAlignment: CrossAxisAlignment.start, | |
| children: <Widget>[ | |
| Expanded( | |
| flex: 2, | |
| child: thumbnail, | |
| ), | |
| Expanded( | |
| flex: 3, | |
| child: _IMBDItemDescription( | |
| title: title, | |
| user: user, | |
| starCount: starCount, | |
| ), | |
| ), | |
| const Icon( | |
| Icons.more_vert, | |
| size: 16.0, | |
| ), | |
| ], | |
| ), | |
| ); | |
| } | |
| } | |
| class _IMBDItemDescription extends StatelessWidget { | |
| const _IMBDItemDescription({ | |
| Key key, | |
| this.title, | |
| this.user, | |
| this.starCount, | |
| }) : super(key: key); | |
| final String title; | |
| final String user; | |
| final int starCount; | |
| @override | |
| Widget build(BuildContext context) { | |
| final color = Theme.of(context).accentColor; | |
| return Padding( | |
| padding: const EdgeInsets.fromLTRB(5.0, 0.0, 0.0, 0.0), | |
| child: Column( | |
| crossAxisAlignment: CrossAxisAlignment.start, | |
| children: <Widget>[ | |
| Text( | |
| title, | |
| style: const TextStyle( | |
| fontWeight: FontWeight.w500, | |
| fontSize: 14.0, | |
| ), | |
| ), | |
| const Padding(padding: EdgeInsets.symmetric(vertical: 2.0)), | |
| Text( | |
| user, | |
| style: const TextStyle(fontSize: 10.0), | |
| ), | |
| const Padding(padding: EdgeInsets.symmetric(vertical: 1.0)), | |
| StarDisplayWidget( | |
| value: 2, | |
| filledStar: Icon(Icons.star, color: Colors.orange, size: 28), | |
| unfilledStar: Icon(Icons.star_border, color: Colors.orangeAccent), | |
| ), | |
| ], | |
| ), | |
| ); | |
| } | |
| } | |
| class AppBody extends StatelessWidget { | |
| AppBody({Key key}) : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return ListView( | |
| padding: const EdgeInsets.all(8.0), | |
| itemExtent: 106.0, | |
| children: <IMBDListItem>[ | |
| IMBDListItem( | |
| user: 'Flutter', | |
| starCount: 3, | |
| thumbnail: Container( | |
| decoration: const BoxDecoration(color: Colors.blue), | |
| ), | |
| title: 'The Flutter YouTube Channel', | |
| ), | |
| IMBDListItem( | |
| user: 'Dash', | |
| starCount: 4, | |
| thumbnail: Container( | |
| decoration: const BoxDecoration(color: Colors.yellow), | |
| ), | |
| title: 'Announcing Flutter 1.0', | |
| ), | |
| ], | |
| ); | |
| } | |
| } | |
| class AppDrawer extends StatelessWidget{ | |
| @override | |
| Widget build(BuildContext context) { | |
| return Drawer( | |
| child: ListView( | |
| padding: EdgeInsets.zero, | |
| children: <Widget>[ | |
| SizedBox( | |
| height: 100.0, //with changing that place, we can change header | |
| child: DrawerHeader( | |
| child: Text('Menu Header'), | |
| decoration: BoxDecoration( | |
| color: Colors.blue, | |
| ), | |
| ), | |
| ), | |
| ListTile( | |
| title: Text('Item1'), | |
| onTap: () { | |
| Navigator.pop(context); | |
| }, | |
| ), | |
| ListTile( | |
| title: Text('Item 2'), | |
| onTap: () { | |
| Navigator.pop(context); | |
| }, | |
| ), | |
| ListTile( | |
| title: Text('Item 3'), | |
| onTap: () { | |
| Navigator.pop(context); | |
| }, | |
| ), | |
| ListTile( | |
| title: Text('Item 4'), | |
| onTap: () { | |
| Navigator.pop(context); | |
| }, | |
| ), | |
| ], | |
| ), | |
| ); | |
| } | |
| } | |
| class AppBottomNavigationBar extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return BottomNavigationBar( | |
| unselectedItemColor: Colors.black45, | |
| selectedItemColor: Colors.black, | |
| backgroundColor: Colors.blue, | |
| items: [ | |
| new BottomNavigationBarItem( | |
| icon: new Icon(Icons.comment), | |
| title: new Text("Home"), | |
| ), | |
| new BottomNavigationBarItem( | |
| icon: new Icon(Icons.home), | |
| title: new Text("Comments"), | |
| ), | |
| new BottomNavigationBarItem( | |
| icon: new Icon(Icons.comment), | |
| title: new Text("Comments"), | |
| ), | |
| ], | |
| ); | |
| } | |
| } | |
| class MyHomePage extends StatelessWidget { | |
| final String title; | |
| MyHomePage({Key key, this.title}) : super(key: key); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar(title: Text(title)), | |
| body: AppBody(), | |
| drawer: AppDrawer(), | |
| bottomNavigationBar: AppBottomNavigationBar(), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment