Created
July 19, 2025 11:59
-
-
Save Arpit723/6f2e3eba930041257d694f92664d5a6a to your computer and use it in GitHub Desktop.
First Flutter Layout Example
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(const MyApp()); | |
| } | |
| class MyApp extends StatelessWidget { | |
| const MyApp({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| const String appTitle = 'Flutter layout demo'; | |
| return MaterialApp( | |
| title: appTitle, | |
| home: Scaffold( | |
| appBar: AppBar(title: const Text(appTitle)), | |
| body: SingleChildScrollView( | |
| child: Center( | |
| child: Column( | |
| children: [ | |
| ImageSection( | |
| image: | |
| 'https://raw.githubusercontent.com/flutter/website/main/examples/layout/lakes/step5/images/lake.jpg', | |
| ), | |
| TitleSection(name: 'Baba', location: 'Hello World'), | |
| ButtonSection(), | |
| TextSection( | |
| description: | |
| 'Take seschinen lies at the foot of the Blüemlisalp in the ' | |
| 'Bernese Alps. Situated 1,578 meters above sea level, it ' | |
| 'is one of the larger Alpine Lakes. A gondola ride from ' | |
| 'Kandersteg, followed by a half-hour walk through pastures ' | |
| 'and pine forest, leads you to the lake, which warms to 20 ' | |
| 'degrees Celsius in the summer. Activities enjoyed here ' | |
| 'include rowing, and riding the summer toboggan run.', | |
| ), | |
| ], | |
| ), | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| } | |
| class TitleSection extends StatelessWidget { | |
| const TitleSection({super.key, required this.name, required this.location}); | |
| final String name; | |
| final String location; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Padding( | |
| padding: const EdgeInsets.all(32), | |
| child: Row( | |
| children: [ | |
| Expanded( | |
| /*1*/ | |
| child: Column( | |
| crossAxisAlignment: CrossAxisAlignment.start, | |
| children: [ | |
| /*2*/ | |
| Padding( | |
| padding: const EdgeInsets.only(bottom: 8), | |
| child: Text( | |
| name, | |
| style: const TextStyle(fontWeight: FontWeight.bold), | |
| ), | |
| ), | |
| Text(location, style: TextStyle(color: Colors.grey[500])), | |
| ], | |
| ), | |
| ), | |
| /*3*/ | |
| Icon(Icons.star, color: Colors.red[500]), | |
| const Text('41'), | |
| ], | |
| ), | |
| ); | |
| } | |
| } | |
| class ButtonWithText extends StatelessWidget { | |
| const ButtonWithText({ | |
| super.key, | |
| required this.color, | |
| required this.icon, | |
| required this.label, | |
| }); | |
| final Color color; | |
| final IconData icon; | |
| final String label; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Column( | |
| mainAxisSize: MainAxisSize.min, | |
| mainAxisAlignment: MainAxisAlignment.center, | |
| children: [ | |
| Icon(icon, color: color), | |
| Padding( | |
| padding: const EdgeInsets.only(top: 8), | |
| child: Text( | |
| label, | |
| style: TextStyle( | |
| fontSize: 12, | |
| fontWeight: FontWeight.w400, | |
| color: color, | |
| ), | |
| ), | |
| ), | |
| ], | |
| ); | |
| } | |
| } | |
| class ButtonSection extends StatelessWidget { | |
| const ButtonSection({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| final Color color = Theme.of(context).primaryColor; | |
| return SizedBox( | |
| child: Row( | |
| mainAxisAlignment: MainAxisAlignment.spaceEvenly, | |
| children: [ | |
| ButtonWithText(color: color, icon: Icons.call, label: 'CALL'), | |
| ButtonWithText(color: color, icon: Icons.near_me, label: 'ROUTE'), | |
| ButtonWithText(color: color, icon: Icons.share, label: 'SHARE'), | |
| ], | |
| ), | |
| ); | |
| } | |
| } | |
| class TextSection extends StatelessWidget { | |
| const TextSection({super.key, required this.description}); | |
| final String description; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Padding( | |
| padding: const EdgeInsets.all(32), | |
| child: Text(description, softWrap: true), | |
| ); | |
| } | |
| } | |
| class ImageSection extends StatelessWidget { | |
| const ImageSection({super.key, required this.image}); | |
| final String image; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Container( | |
| child: Image.network(image, width: 600, height: 200, fit: BoxFit.cover), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment