0% found this document useful (0 votes)
7 views3 pages

UI Design Flutter R22 Week 4

The document provides code examples for implementing a Stack Widget in Flutter, showcasing different layout structures with overlapping containers. It also demonstrates setting up navigation between different screens using the Navigator class, allowing users to transition from a home screen to a new screen. The examples include basic Flutter app structure with MaterialApp and Scaffold widgets.

Uploaded by

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

UI Design Flutter R22 Week 4

The document provides code examples for implementing a Stack Widget in Flutter, showcasing different layout structures with overlapping containers. It also demonstrates setting up navigation between different screens using the Navigator class, allowing users to transition from a home screen to a new screen. The examples include basic Flutter app structure with MaterialApp and Scaffold widgets.

Uploaded by

addagudi ashwini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Week-4

4a)ImplementdifferentlayoutstructuresusingStackWidget.

StackWidget:
import'package:flutter/[Link]';
void main() {
runApp(MaterialApp(
home:Scaffold(
appBar:AppBar(
title: Text('Stack Widget'),
backgroundColor:[Link][400],
), //AppBar
body: Center(
child:SizedBox(
width: 300,
height: 300,
child:Center(
child: Stack(
children:<Widget>[
Container(
width:300,
height: 300,
color:[Link],
),//Container
Container(
width: 250,
height:250,
color:[Link],
),//Container
Container(
height: 200,
width: 200,
color: [Link],
),//Container
],//<Widget>[]
),//Stack
),//Center
),//SizedBox
)//Center
)//Scaffold
)//MaterialApp
);
}
Output:

4b)SetupnavigationbetweendifferentscreensusingNavigator.
import 'package:flutter/[Link]';
void main() => runApp(MyApp());
classMyAppextendsStatelessWidget {
@override
Widgetbuild(BuildContextcontext){ return
MaterialApp(
title:'FlutterDemo',
theme:ThemeData(primarySwatch:[Link]),
home: HomeScreen(),
);
}
}
classHomeScreenextendsStatelessWidget {
@override
Widgetbuild(BuildContextcontext){ return
Scaffold(
appBar:AppBar(title:constText('HomeScreen')),
body: Center(
child:ElevatedButton(
child: const Text(
'Navigate to a new screen >>',
style:TextStyle(fontSize:24.0),
),
onPressed:() {
_navigateToNextScreen(context);
},
),
),
);
}

void _navigateToNextScreen(BuildContext context) {


[Link](context).push(MaterialPageRoute(builder:(context)=>
NewScreen()));
}
}
classNewScreenextendsStatelessWidget {
@override
Widgetbuild(BuildContextcontext){ return
Scaffold(
appBar:AppBar(title:constText('NewScreen')),
body: const Center(
child:Text(
'Thisisanewscreen',
style:TextStyle(fontSize:24.0),
),
),
);
}
}

Output:

You might also like