DEV Community

2025
2025

Posted on

snackbar in flutter

import 'package:flutter/material.dart';

void main() {
  runApp(om());
}

class om extends StatefulWidget {
  const om({super.key});

  @override
  State<om> createState() => _omState();
}

class _omState extends State<om> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'om namah shivay',
      debugShowCheckedModeBanner: false,
      darkTheme: ThemeData.dark(),
      home: Scaffold(
        appBar: AppBar(
          title: Text('snackbar'),
          backgroundColor: Colors.red,
        ),
        body: Center(
          child: Builder(builder: (contextForSnckbar) {
            return ElevatedButton(
                style: ButtonStyle(
                    backgroundColor: WidgetStatePropertyAll(Colors.red)),
                onPressed: () {
                  final snackbar = SnackBar(content: Text('i understood'));
                  ScaffoldMessenger.of(contextForSnckbar)
                      .showSnackBar(snackbar);
                },
                child: Text('click'));
          }),
        ),
      ),
    );
  }
}

Enter fullscreen mode Exit fullscreen mode

I understood

Top comments (0)