mirror of
https://github.com/nisrulz/flutter-examples.git
synced 2026-08-25 01:05:36 +00:00
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
42 lines
1.4 KiB
Dart
42 lines
1.4 KiB
Dart
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),
|
|
));
|
|
}
|
|
}
|