How To Integrate Getx in Flutter
Hello Coders,Hope you watched my video on this Topic and if still you didn't watch then Please go and watch
https://youtu.be/xiJjolqWHM0
In this post you will get all the required code to implement or set up Getx in Flutter or You can get that from Github
https://youtu.be/xiJjolqWHM0
In this post you will get all the required code to implement or set up Getx in Flutter or You can get that from Github
Pubspec.yaml
name: codemicros_getx_series
description: "A new Flutter project."
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: '>=3.3.3 <4.0.0'
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.6
get: ^4.6.6
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^3.0.0
flutter:
uses-material-design: true
main.dart
import 'package:codemicros_getx_series/app/views/homepage_view.dart';
import 'package:flutter/material.dart';
import 'package:get/route_manager.dart';
main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return GetMaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
useMaterial3: true,
),
home: const HomepageView(),
);
}
}
homepage_view.dart
import 'package:codemicros_getx_series/app/views/homepage_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class HomepageView extends StatelessWidget {
const HomepageView({super.key});
@override
Widget build(BuildContext context) {
HomepageController homepageController = Get.put(HomepageController());
return Scaffold(
body: Obx(
() => Center(
child: Text(
homepageController.counter.value.toString(),
style: const TextStyle(fontSize: 45.0),
),
),
),
floatingActionButton: ElevatedButton(
onPressed: () {
homepageController.updateCounterValue();
},
child: const Text("Add")),
);
}
}
homepage_controller.dart
import 'package:get/get.dart';
class HomepageController extends GetxController {
final RxInt counter = 0.obs;
updateCounterValue() {
counter.value = counter.value + 1;
}
}
homepage_binding.dart
import 'package:codemicros_getx_series/app/views/homepage_controller.dart';
import 'package:get/get.dart';
class HomepageBinding extends Bindings {
@override
void dependencies() {
Get.lazyPut(() => HomepageController());
}
}
------- Thank You -------