Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – a function top of Navigator.of(context).push in the onPressed part of the MaterialButton prevent the button to work

Posted on November 11, 2022 By

Solution 1 :

I had to edit your code because of some syntax errors.
your code is working fine but the problem is that you don’t display the result of minimalController.realIfSuExpress(); to do that you can
1-insert get function in minimalController like this

import 'package:get/get.dart';

class MinimalCartController extends GetxController {
  var realTotal = 0.0;
  var globalsom = 3000.0;
  var ifCinqMilles = 5000.0;
  var totalOfArticles = 2.0;
  var theRemiseTwenty = 0.0;
  var theRemiseTen = 0.0;

  void realIfSuExpress() {
    realTotal = globalsom + ifCinqMilles;
    if (totalOfArticles > 20) {
      theRemiseTwenty = (globalsom * 20) / 100;
    }
    if (totalOfArticles > 9 && totalOfArticles < 20) {
      theRemiseTen = (globalsom * 15) / 100;
    }
  }
  get total=>realTotal;
}

2- you need to inject dependency in your main like this:

var c=Get.put(MinimalCartController());
final minimalController = Get.find<MinimalCartController>();

3- call MinimalCartController in minimal_cart_bill.dart file by using:

final minimalController = Get.find<MinimalCartController>(); 

4- display The total

child: Text(
          "Welcome ! ${minimalController.total}",
          style: TextStyle(
            fontWeight: FontWeight.bold,
            fontSize: 14.0,
            color: Colors.black,
          ),
        ),

5- you will need to remove some of const keyword because your file isn’t const anymore

Solution 2 :

It’s ok, i saw the problem and solve it. “realTotal” var in the void realIfSuExpress() in my not minimal code (my actual full project code) was recieving 0 instead of 0.0 in initiating, so that was considering as an int. I just replaced it (by 0.0) and everythings run fine now when install and run apk on an android device.

Problem :

When I run on chrome on the computer, everything is ok, but on an Android device, there is a bug while clicking a material button on the app.

Expected results: When clicking on the button, the function must do a calculus about the total order discount or add 5000 to the total if some kind of articles are selected.

READ  [FIXED] android - How to show an error when Firebase Realtime Database denies access?
Powered by Inline Related Posts

Actual results: While the function is on top the Navigator switching page in the button onPressed part, nothing appear when clicking on it (the button do not lead to the concerned page). In other side, when the function is down to the Navigator switching page, the function is not implemented (like there is not a certain function there).

I have try many type of putting this function on the onPressed part of the button, and many other type of button but the same result.

A minimal complete reproductible code sample

The main.dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'minimal_cart_bill.dart';
import 'minimal_cart_controller.dart';

void main() {
runApp(const MyApp());
}

//Stateless du MaterialApp
// ignore: must_be_immutable
class MyApp extends StatelessWidget {
// final bool showHome;
const MyApp({Key? key}) : super(key: key);

static const String title = "Eclat d'Afrik";
// final userr = UserPreferences.myUser;

@override
Widget build(BuildContext context) {
return MaterialApp(
title: title,
home: MinimalReproductible(),
// home: showHome ? const AuthPage() : OnBrodingPage(),
);
}
}

class MinimalReproductible extends StatelessWidget {
MinimalReproductible({super.key});

final minimalController = Get.find<MinimalCartController>();

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Bill Generator')),
body: MaterialButton(
onPressed: () {
minimalController.realIfSuExpress();
Navigator.of(context).push(
MaterialPageRoute(builder: (builder) => const MinimalCartBill()));
},
color: const Color(0xFF5ACC80),
height: 55.0,
child: const Text(
"GENERATE MY BILL",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
color: Colors.black,
),
),
),
);
}
}

The minimal_cart_controller.dart

// ignore: depend_on_referenced_packagesimport 'package:get/get.dart';

class MinimalCartController extends GetxController {
var realTotal = 0.0;var globalsom = 3000.0;var ifCinqMilles = 5000.0;var totalOfArticles = 2.0;var theRemiseTwenty = 0.0;var theRemiseTen = 0.0;

void realIfSuExpress() {realTotal = globalsom + ifCinqMilles;if (totalOfArticles > 20) {theRemiseTwenty = (globalsom * 20) / 100;}if (totalOfArticles > 9 && totalOfArticles < 20) {theRemiseTen = (globalsom * 15) / 100;}}}

The minimal_cart_bill.dart

import 'package:flutter/material.dart';

class MinimalCartBill extends StatelessWidget {
const MinimalCartBill({super.key});

@override 
Widget build(BuildContext context) {return Scaffold(appBar: AppBar(title: const Text('Welcome Page')),body: const Padding(padding: EdgeInsets.all(.0),child: Text ("Welcome !",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 14.0,color: Colors.black,),),),);}}

Logs

  • Flutter run –verbose my flutter run verbose.txt

  • Flutter Analyse

Analyzing afrikeclat…

0 issue found. (ran in 548.3s)

  • Flutter Doctor
READ  [FIXED] java - How to make discrete seek/progress bar in android?
Powered by Inline Related Posts

[√] Flutter (Channel stable, 3.3.3, on Microsoft Windows [version 10.0.19044.2130], locale fr-FR)
• Flutter version 3.3.3 on channel stable at C:UsersAsusflutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 18a827f393 (5 weeks ago), 2022-09-28 10:03:14 -0700
• Engine revision 5c984c26eb
• Dart version 2.18.2
• DevTools version 2.15.0

Checking Android licenses is taking an unexpectedly long time…[√] Android toolchain – develop for Android devices (Android SDK version 33.0.0)
• Android SDK at C:UsersAsusAppDataLocalAndroidsdk
• Platform android-TiramisuPrivacySandbox, build-tools 33.0.0
• Java binary at: C:Program FilesAndroidAndroid Studiojrebinjava
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
• All Android licenses accepted.

[√] Chrome – develop for the web
• Chrome at C:Program Files (x86)GoogleChromeApplicationchrome.exe

[√] Visual Studio – develop for Windows (Visual Studio Community 2022 17.2.6)
• Visual Studio at C:Program FilesMicrosoft Visual Studio2022Community
• Visual Studio Community 2022 version 17.2.32630.192
• Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2021.3)
• Android Studio at C:Program FilesAndroidAndroid Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[√] VS Code (version 1.72.2)
• VS Code at C:UsersAsusAppDataLocalProgramsMicrosoft VS Code
• Flutter extension version 3.50.0

[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [version 10.0.19044.2130]
• Chrome (web) • chrome • web-javascript • Google Chrome 107.0.5304.87
• Edge (web) • edge • web-javascript • Microsoft Edge 106.0.1370.37

[√] HTTP Host Availability
• All required HTTP hosts are available

• No issues found!

READ  [FIXED] java - NullPointerException Error without line number. How can I get the line number that is causing this error in Android Studio?
Powered by Inline Related Posts

Comments

Comment posted by Djèlé Bi Berci

Thank a lot for that full correct implementation of the Getx. I will save all this for the next time <3

Android Tags:android, apk, flutter

Post navigation

Previous Post: [FIXED] Unable to connect Firebase in Android Emulator for Flutter Project
Next Post: [FIXED] android – Highlight only one Card in Compose through selection

Related Posts

[FIXED] java – How can I ensure my spinner (inside menu) updates my menu title and ensure the title is displayed in full? Android
[FIXED] Activity minimize in android Android
[FIXED] java – Android Notifications – replace one notification with another Android
[FIXED] android – why my seek bar brightness setting locked for change and how can i fix it Android
[FIXED] android – pass multiple value from recyclerview to main activity when button is clicked Android
[FIXED] kotlin – Android Child Coroutines Not Cancelling Appropriately (SupervisorJob) Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Can VPN be traced by police?
  • Where were Kaiser-Frazer cars built?
  • How do you make gold rose gold paint?
  • What are the newest type of dentures?
  • Can you wear joggers as dress pants?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme