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.
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
• 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 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!
2
Answers
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.
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 can1-insert
get
function inminimalController
like this2- you need to inject dependency in your main like this:
3- call
MinimalCartController
in minimal_cart_bill.dart file by using:4- display The
total
5- you will need to remove some of
const
keyword because your file isn’t const anymore