Example of using Stack in Flutter
This file contains 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({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Flutter Demo', | |
theme: ThemeData(primarySwatch: Colors.green), | |
home: const MyHomePage(), | |
); | |
} | |
} | |
class MyHomePage extends StatelessWidget { | |
const MyHomePage({Key? key}) : super(key: key); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: const Text('Flutter Demo Home Page')), | |
body: Center( | |
child: Stack( | |
alignment: AlignmentDirectional.topCenter, | |
clipBehavior: Clip.none, | |
children: [ | |
Card( | |
color: Colors.green.shade50, | |
child: const Padding( | |
padding: EdgeInsets.fromLTRB(32, 56, 32, 32), | |
child: Text('Successful', style: TextStyle(fontSize: 32)), | |
), | |
), | |
Positioned( | |
top: -40, | |
child: Container( | |
child: const Icon(Icons.gpp_good, color: Colors.green, size: 48), | |
padding: const EdgeInsets.all(16), | |
decoration: BoxDecoration( | |
color: Colors.white, | |
border: Border.all(color: Colors.green.shade50, width: 4), | |
shape: BoxShape.circle, | |
), | |
), | |
) | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment