counterApp, Themes, Snackbar using GetX

 import "package:flutter/material.dart";

import "package:get/get.dart";
import "package:getx_flutter/GetX_Counter_App/controller1.dart";
import "package:getx_flutter/GetX_Counter_App/second_page.dart";

void main() {
runApp(const MyDemo(),);
}
class MyDemo extends StatelessWidget {
const MyDemo({super.key}) : super();

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

DemoController mycontrol = Get.put(DemoController(),);

// List themeList = [ ListTile(
// leading: const Icon(Icons.light_mode, color: Colors.white,),
// title: const Text("Light mode", style: TextStyle(color: Colors.white,),),
// onTap: () {
// print("Light");
// Get.changeTheme(ThemeData.light(),);
// },
// ), ListTile(
// leading: const Icon(Icons.dark_mode, color: Colors.white,),
// title: const Text("Dark mode", style: TextStyle(color: Colors.white,),),
// onTap: () {
// print("dark");
// Get.changeTheme(ThemeData.dark(),);
// },
// ),];

List listIcon = [Icons.light_mode, Icons.dark_mode,];

List listTitle = ["Light Mode", "Dark Mode",];

List listTheme = [ThemeData.light(), ThemeData.dark(),];

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
centerTitle: true,
title: const Text("GetX Counter Application"),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Center(child: Image.asset("assets/images/Logo_Flutter.png", height: 150.0, width: 150.0,),),
const SizedBox(height: 40.0,),
Obx(() {
return Text("Count : ${mycontrol.count2.value}",
style: const TextStyle(fontSize: 40.0, fontFamily: "FontsFour",),
);
},),
const SizedBox(height: 20.0,),
ElevatedButton(
onPressed: () {
Get.snackbar(
"GetX Snack bar",
"Yay! Awesome GetX Snack bar",
icon: const Icon(Icons.account_balance, color: Colors.black,),
backgroundColor: Colors.grey,
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.blue,
fixedSize: const Size(300.0, 50.0,),
),
child: const Text("Show Snack bar", style: TextStyle(fontSize: 20.0,),),
),
const SizedBox(height: 40.0,),
ElevatedButton(
onPressed: () {
Get.defaultDialog(
title: "GetX Alert",
middleText: "Simple GetX Alert",
titlePadding: const EdgeInsets.only(top: 10.0,),
textConfirm: "Okey",
contentPadding: const EdgeInsets.all(10.0,),
textCancel: "Cancel",
confirmTextColor: Colors.white,
content: const Column(
children: [
Text("This is First content,"),
Text("This is second content,"),
Text("This is third content,"),
Text("This is fourth content"),
],
),
confirm: TextButton(
onPressed: () { Get.back(); },
// style: TextButton.styleFrom(
// backgroundColor: Colors.brown,
// ),
child: const Text("Okey",),
),
cancel: TextButton(
onPressed: () { Get.back(); },
// style: TextButton.styleFrom(
// backgroundColor: Colors.brown,
// ),
child: const Text("Cancel",),
),
);
},
style: ElevatedButton.styleFrom(
fixedSize: const Size(300.0, 50.0,),
),
child: const Text("Show AlertDialog", style: TextStyle(fontSize: 20.0,),),
),
const SizedBox(height: 40.0,),
ElevatedButton(
onPressed: () {
Get.to(() {
return const SecondPage();
},);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.black,
fixedSize: const Size(300.0, 50.0,),
),
child: const Row(
children: [
Spacer(),
Text("Go to next Screen", style: TextStyle(fontSize: 20.0,),),
Expanded(child: Icon(Icons.arrow_right_alt,),),
],
),
),
const SizedBox(height: 40.0,),
ElevatedButton(
onPressed: () {
Get.bottomSheet(
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30.0,),
color: Colors.black,
),
child: Column(
children: [
ListTile(
leading: const Icon(Icons.light_mode, color: Colors.white,),
title: const Text("Light mode", style: TextStyle(color: Colors.white,),),
onTap: () {
print("Light");
Get.changeTheme(ThemeData.light(),);
},
),
const Divider(thickness: 1.0, color: Colors.white,),
ListTile(
leading: const Icon(Icons.dark_mode, color: Colors.white,),
title: const Text("Dark mode", style: TextStyle(color: Colors.white,),),
onTap: () {
print("dark");
Get.changeTheme(ThemeData.dark(),);
},
),

// ListTile(
// leading: Icon(listIcon[index]),
// title: Text("${mycontrol.listTile[index]}"),
// // subtitle: Text("${mycontrol.listTile[index]}"),
// onTap: Get.changeTheme(listTheme[index]);
// ),
],
),
),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: Colors.teal,
fixedSize: const Size(300.0, 50.0,),
),
child: const Text("Show BottomSheet", style: TextStyle(fontSize: 20.0,),),
),
],
),
),
floatingActionButton: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
FloatingActionButton(
heroTag: "btn1",
backgroundColor: Colors.blue,
onPressed: () {
mycontrol.increment();
},
tooltip: "Increment",
child: const Icon(Icons.add,),
),
const SizedBox(width: 10.0,),

FloatingActionButton(
heroTag: "btn2",
backgroundColor: Colors.brown,
onPressed: () {
mycontrol.decrement();
},
tooltip: "decrement",
child: const Icon(Icons.remove,),
),
],
),
);
}
}
///I have encountered Error named "There are multiple heroes that share the same tag
///within a subtree. Within each subtree for which heroes are to be animated
///(i.e. a PageRoute subtree), each Hero must have a unique non-null tag..." before, and
///it was because I had two FloatingAction buttons on one screen, I had to add
///a heroTag property + value per FloatingActionButton in order for the error to go away.import "package:get/get.dart";
///Always, All the business Logics(Like variable, methods...) will written in Controller class
/// and it is separate from UI

class DemoController extends GetxController {
var count2 = 0.obs;

void increment() {
count2.value++;
}

void decrement() {
count2.value--;
}
}

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