Skip to content

Instantly share code, notes, and snippets.

@obumnwabude
Created June 2, 2022 01:46
Show Gist options
  • Save obumnwabude/de06d67b7e636dfb8ae1b852b97624b4 to your computer and use it in GitHub Desktop.
Save obumnwabude/de06d67b7e636dfb8ae1b852b97624b4 to your computer and use it in GitHub Desktop.
Example of using Stack in Flutter
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