mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-08-25 01:05:36 +00:00
refactor: split app wrapper from focused example code (single-file apps)
Convert 20 more single-file apps to the validated pattern: lib/main.dart holds only the runApp + MaterialApp bootstrap, while a new lib/example.dart holds the full screen (Scaffold, AppBar) and the focused example code. Apps: enabling_splash_screen, getx_counter_app, image_from_network, infinite_list, load_local_image, load_local_json, persist_key_value, push_notifications, sliver_app_bar_example, stateless_widgets, tic_tac_toe, tip_calculator, using_alert_dialog, using_edittext, using_expansionpanel, using_http_get, using_interactiveviewer, using_snackbar, using_stepper, using_theme
This commit is contained in:
49
using_snackbar/lib/example.dart
Normal file
49
using_snackbar/lib/example.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// Example: show a SnackBar with an action button when the button is pressed.
|
||||
class Example extends StatelessWidget {
|
||||
const Example({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Using SnackBar"),
|
||||
),
|
||||
body: Center(
|
||||
child: MyButton(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyButton extends StatelessWidget {
|
||||
const MyButton({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ElevatedButton(
|
||||
child: const Text('Show SnackBar'),
|
||||
// On pressing the raised button
|
||||
onPressed: () {
|
||||
// show snackbar
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
// set content of snackbar
|
||||
content: const Text("Hello! I am SnackBar :)"),
|
||||
// set duration
|
||||
duration: const Duration(seconds: 3),
|
||||
// set the action
|
||||
action: SnackBarAction(
|
||||
label: "Hit Me (Action)",
|
||||
onPressed: () {
|
||||
// When action button is pressed, show another snackbar
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: const Text(
|
||||
"Hello! I am shown becoz you pressed Action :)"),
|
||||
));
|
||||
}),
|
||||
));
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,52 +1,20 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'example.dart';
|
||||
|
||||
void main() {
|
||||
runApp(MaterialApp(home: ContactPage(), debugShowCheckedModeBanner: false,));
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class ContactPage extends StatelessWidget {
|
||||
const ContactPage({super.key});
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text("Using SnackBar"),
|
||||
),
|
||||
body: Center(
|
||||
child: MyButton(),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class MyButton extends StatelessWidget {
|
||||
const MyButton({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ElevatedButton(
|
||||
child: Text('Show SnackBar'),
|
||||
// On pressing the raised button
|
||||
onPressed: () {
|
||||
// show snackbar
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
// set content of snackbar
|
||||
content: Text("Hello! I am SnackBar :)"),
|
||||
// set duration
|
||||
duration: Duration(seconds: 3),
|
||||
// set the action
|
||||
action: SnackBarAction(
|
||||
label: "Hit Me (Action)",
|
||||
onPressed: () {
|
||||
// When action button is pressed, show another snackbar
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(
|
||||
"Hello! I am shown becoz you pressed Action :)"),
|
||||
));
|
||||
}),
|
||||
));
|
||||
},
|
||||
return MaterialApp(
|
||||
debugShowCheckedModeBanner: false,
|
||||
title: "Using SnackBar",
|
||||
home: const Example(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user