GetX GetStorage

 import "package:flutter/material.dart";

import "package:get/get.dart";
import "package:get_storage/get_storage.dart";

void main() async {
await GetStorage.init(); ///Initialize storage driver
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key}) : super();

@override
Widget build(BuildContext context) {
return GetMaterialApp(
debugShowCheckedModeBanner: false,
title: "Flutter Demo",
theme: ThemeData(
primarySwatch: Colors.brown,
),
home: DemoStore1(),
);
}
}
class DemoStore1 extends StatelessWidget {
DemoStore1({super.key}) : super();

var _counter = 0.obs;
final box = GetStorage();

void incrementCounter() {
_counter++;
box.write("finalCount", _counter);
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("Get Storage Demo"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text("You have pushed the button many times:"),
Obx(() {
return Text("${box.read("finalCount")}",
style: const TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold,),);
},),
],
),
),
);
}
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter