0% found this document useful (0 votes)
26 views7 pages

Flutter Exp3

The document provides a Flutter application that demonstrates how to create a responsive UI that adapts to different screen sizes using LayoutBuilder. It includes two implementations: one for narrow and wide layouts, and another that incorporates media queries for mobile, tablet, and desktop layouts. Each layout features a Flutter logo, a text label indicating the layout type, and a button.

Uploaded by

vikaspithala2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views7 pages

Flutter Exp3

The document provides a Flutter application that demonstrates how to create a responsive UI that adapts to different screen sizes using LayoutBuilder. It includes two implementations: one for narrow and wide layouts, and another that incorporates media queries for mobile, tablet, and desktop layouts. Each layout features a Flutter logo, a text label indicating the layout type, and a button.

Uploaded by

vikaspithala2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

3.

a) Design a responsive UI that adapts to different screen sizes

import 'package:flutter/material.dart';

void main() {

runApp(MyApp());

class MyApp extends StatelessWidget {

@override

Widget build(BuildContext context) {

return MaterialApp(

title: 'Responsive UI Demo', theme:

ThemeData( primarySwatch:

Colors.blue,

),

home: ResponsiveHomePage(),

);

class ResponsiveHomePage extends StatelessWidget {

@override

Widget build(BuildContext context) {

return Scaffold(

appBar: AppBar(

title: Text('Responsive UI Demo'),

),

body: LayoutBuilder(

builder: (BuildContext context, BoxConstraints constraints) {

if (constraints.maxWidth < 600) {

return _buildNarrowLayout();

} else {
return _buildWideLayout();

},

),

);

Widget _buildNarrowLayout() {

return Center(

child: Column(

mainAxisAlignment: MainAxisAlignment.center, children:

<Widget>[

FlutterLogo(size: 100),

SizedBox(height: 20), Text(

'Narrow Layout',

style: TextStyle(fontSize: 24),

),

SizedBox(height: 20),

ElevatedButton( onPressed:

() {},

child: Text('Button'),

),

],

),

);

Widget _buildWideLayout() {

return Center(

child: Row(

mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[

FlutterLogo(size: 100),

SizedBox(width: 20),

Column(

mainAxisAlignment: MainAxisAlignment.center,

children: <Widget>[

Text(

'Wide Layout',

style: TextStyle(fontSize: 24),

),

SizedBox(height: 20),

ElevatedButton( onPressed: ()

{},

child: Text('Button'),

),

],

),

],

),

);

3.b Implement media queries and breakpoints for responsiveness

import 'package:flutter/material.dart';

void main() {

runApp(MyApp());

class MyApp extends

StatelessWidget {
@override

Widget build(BuildContext

context) {

return MaterialApp(

title: 'Responsive UI with Media Queries', theme: ThemeData(

primarySwatch: Colors.blue,

),

home:

ResponsiveHomePage(),

);

class ResponsiveHomePage extends

StatelessWidget {

@override

Widget build(BuildContext context) {

return

Scaffold(

appBar: AppBar(

title: Text('Responsive UI with Media Queries'),

),

body: LayoutBuilder(

builder: (BuildContext context, BoxConstraints constraints) {

if (constraints.maxWidth < 600) {

return _buildMobileLayout();

} else if (constraints.maxWidth < 1200) {

return _buildTabletLayout();

} else {

return _buildDesktopLayout();
}

},

),

);

Widget _buildMobileLayout() {

return Center(

child: Column(

mainAxisAlignment: MainAxisAlignment.center,

children: <Widget>[

FlutterLogo(size: 100),

SizedBox(height: 20),

Text(

'Mobile Layout',

style: TextStyle(fontSize: 24),

),

SizedBox(height: 20),

ElevatedButton(

onPressed: () {},

child: Text('Button'),

),

],

),

);

Widget

_buildTabletLayout() {

return

Center(
child:

Row(

mainAxisAlignment: MainAxisAlignment.center,

children: <Widget>[

FlutterLogo(size: 100),

SizedBox(width: 20),

Column(

mainAxisAlignment: MainAxisAlignment.center,

children: <Widget>[

Text(

'Tablet Layout',

style: TextStyle(fontSize: 24),

),

SizedBox(height: 20),

ElevatedButton(

onPressed: () {},

child: Text('Button'),

),

],

),

],

),

);

Widget _buildDesktopLayout() {

return

Center(

child: Row(

mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[

FlutterLogo(size: 100),

SizedBox(width: 20),

Column(

mainAxisAlignment: MainAxisAlignment.center,

children: <Widget>[

Text(

'Desktop Layout',

style: TextStyle(fontSize: 24),

),

SizedBox(height: 20),

ElevatedButton(

onPressed: () {},

child: Text('Button'),

),

],

),

],

),

);

You might also like