Created
July 3, 2025 07:02
-
-
Save rena2019/ac685094626652f9d3fc76e4fbc03e9f to your computer and use it in GitHub Desktop.
AlertDialog with Pop-up dialog
This file contains hidden or 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({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: 'Pop-up Demo', | |
theme: ThemeData( | |
primarySwatch: Colors.blue, | |
), | |
home: const HomeScreen(), | |
); | |
} | |
} | |
class HomeScreen extends StatelessWidget { | |
const HomeScreen({super.key}); | |
void _showPopup(BuildContext context) { | |
showDialog( | |
context: context, | |
builder: (BuildContext context) { | |
return AlertDialog( | |
shape: const RoundedRectangleBorder( | |
borderRadius: BorderRadius.zero, | |
), | |
title: const Text('Placeholder Iamge'), | |
content: SizedBox( | |
width: 600, | |
height: 400, | |
child: Image.network( | |
'https://dummyimage.com/600x400/EEE/31343C', // Placeholder image URL | |
fit: BoxFit.cover, | |
), | |
), | |
actions: <Widget>[ | |
TextButton( | |
child: const Text('Schließen'), | |
onPressed: () { | |
Navigator.of(context).pop(); // Close the dialog | |
}, | |
), | |
], | |
); | |
}, | |
); | |
} | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar( | |
title: const Text('Hauptbildschirm'), | |
), | |
body: Center( | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
const Text( | |
'Press Button to open popup dialog', | |
style: TextStyle(fontSize: 18), | |
textAlign: TextAlign.center, | |
), | |
const SizedBox(height: 30), | |
ElevatedButton( | |
onPressed: () => _showPopup(context), | |
child: const Text('Open pop-up'), | |
), | |
], | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment