Layout-Stack

 Stack

Source Code

import 'package:flutter/material.dart';

void main() {
runApp( MaterialApp(
title:"Stack",
home:Scaffold(appBar: AppBar(title: Text(' Stack',),),
body: Material(
child: Center(
child:
StackExample()
,
),
) ,
),
));
}

class StackExample extends StatefulWidget {
const StackExample({Key? key}) : super(key: key);

@override
_StackExampleState createState() => _StackExampleState();
}

class _StackExampleState extends State<StackExample> {
AlignmentDirectional _alignmentDirectional = AlignmentDirectional.topStart;

@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Stack(
alignment: _alignmentDirectional,
children: <Widget>[
Container(width: 300.0, height: 300.0, color: Colors.red),
Container(width: 200.0, height: 200.0, color: Colors.green),
Container(width: 100.0, height: 100.0, color: Colors.blue),
],
),
),
bottomNavigationBar: _getBottomBar(),
);
}

Widget _getBottomBar() {
const kAlignmentDirectionalVals = <String, AlignmentDirectional>{
'topStart': AlignmentDirectional.topStart,
'topCenter': AlignmentDirectional.topCenter,
'topEnd': AlignmentDirectional.topEnd,
'centerStart': AlignmentDirectional.centerStart,
'center': AlignmentDirectional.center,
'centerEnd': AlignmentDirectional.centerEnd,
'bottomStart': AlignmentDirectional.bottomStart,
'bottomCenter': AlignmentDirectional.bottomCenter,
'bottomEnd': AlignmentDirectional.bottomEnd
};
return Material(
color: Theme.of(context).primaryColorLight,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
ListTile(
title: const Text('alignmentDirectional:'),
trailing: DropdownButton<AlignmentDirectional>(
value: _alignmentDirectional,
onChanged: (AlignmentDirectional? newVal) {
if (newVal != null) {
setState(() => this._alignmentDirectional = newVal);
}
},
items: kAlignmentDirectionalVals
.map(
(String name, AlignmentDirectional val) => MapEntry(
name,
DropdownMenuItem(value: val, child: Text(name)),
),
)
.values
.toList(),
),
),
],
),
);
}
}





Comments