'How to use getx controller, binding,getview?

I trying to create small project with getx, I have 3 file's get view,getxcontroller,binding and then when I'm running I get issue like this :

Unhandled Exception: "IncrementController" not found. You need to call "Get.put(IncrementController())" or "Get.lazyPut(()=>IncrementController())"

so did i wrong about getx flow step? let's checkit my code below:

main.dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_application_1/controller.dart';
import 'package:get/get.dart';

void main() {
  runApp(GetMaterialApp(
    home: HomePage(),
  ));
}

class HomePage extends GetView<IncrementController> {
  final IncrementController _controller = Get.find<IncrementController>();
  @override
  Widget build(BuildContext context) {
    //display increment with getx
    return Scaffold(
      appBar: AppBar(
        title: Text('GetX'),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(
              'You have pushed the button this many times:',
            ),
            Text(
              '${_controller.increment}',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _controller.incrementFun,
        tooltip: 'Increment',
        child: Icon(Icons.add),
      ),
    );
  }
}

controller

import 'package:get/get_rx/get_rx.dart';
import 'package:get/get_state_manager/src/rx_flutter/rx_getx_widget.dart';
import 'package:get/get_state_manager/src/simple/get_controllers.dart';

class IncrementController extends GetxController {
  //create increment with getx
  RxInt _increment = 0.obs;
  //get increment
  int get increment => _increment.value;

  //create increment functiion with getx
  void incrementFun() => _increment.value++;
}

binding

import 'package:flutter_application_1/controller.dart';
import 'package:get/get.dart';

class IncrementBinding implements Bindings {
  @override
  void dependencies() {
    // TODO: implement dependencies
    //create controller with getx
    Get.lazyPut<IncrementController>(() => IncrementController());
  }
}


Solution 1:[1]

You need to set the initial binding inside the MaterialApp or GetMaterialApp like this:

    GetMaterialApp(
      initialBinding: IncrementBinding(),
      home: HomeOage(),
    );

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ankit Kumar Maurya