1
0
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:
Nishant Srivastava
2026-08-18 00:41:30 +02:00
parent e143b4c3a2
commit 780c0f1dbb
40 changed files with 1603 additions and 1357 deletions

View File

@@ -0,0 +1,41 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
// Example: a reactive counter using GetX state management.
class Example extends StatelessWidget {
const Example({super.key});
@override
Widget build(BuildContext context) {
// create variable that hold out number with .obs parameter (.obs comes from getx state management)
var counter = 0.obs;
return Scaffold(
appBar: AppBar(
title: const Text("Counter app with Getx (Get) state management"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
// in get (getx) we must ue Obx for the widget that we want to change like setState in statefull widget\
Obx(() => Text(
// we can show our variable by call .value method
'${counter.value}',
style: Theme.of(context).textTheme.headlineSmall,
)),
],
),
),
floatingActionButton: FloatingActionButton(
// we can plus or everything that we want by add .value method to our obs variable
onPressed: () => counter.value++,
tooltip: 'Increment',
child: const Icon(Icons.add),
));
}
}

View File

@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'example.dart';
void main() {
runApp(const MyApp());
@@ -16,44 +16,7 @@ class MyApp extends StatelessWidget {
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
home: const Example(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({super.key});
@override
Widget build(BuildContext context) {
// create variable that hold out number with .obs parameter (.obs comes from getx state management)
var counter = 0.obs;
return Scaffold(
appBar: AppBar(
title: const Text("Counter app with Getx (Get) state management"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
// in get (getx) we must ue Obx for the widget that we want to change like setState in statefull widget\
Obx(() => Text(
// we can show our variable by call .value method
'${counter.value}',
style: Theme.of(context).textTheme.headlineSmall,
)),
],
),
),
floatingActionButton: FloatingActionButton(
// we can plus or everything that we want by add .value method to our obs variable
onPressed: () => counter.value++,
tooltip: 'Increment',
child: const Icon(Icons.add),
));
}
}