Open mohamedkaddouri opened 1 year ago
Hi @mohamedkaddouri,
Are you calling Zettle.init
before any other methods?
Do you have a code example to share?
Hi @davidhole,
I call the zettle.init after not before any other methods. The app uses the flutter navigator to navigate between pages. One of those pages is zettle login screen. and if you click on the login button. the zettle init function get triggered. But it results in this error:
Error message: Unhandled Exception: Exception: Zettle SDK is not initialized. You should call Zettle.init(iosClientId, androidClientId, redirectUrl)
I do have code to share
class LoginZettleScreen extends StatefulWidget { static String id = 'login_zettle_screen';
@override _LoginZettleScreenState createState() => _LoginZettleScreenState(); }
class _LoginZettleScreenState extends State
String? _message;
@override void initState() { super.initState(); _emailFocusNode.addListener(() { setState(() { _isFocuseOnEmailField = _emailFocusNode.hasFocus; }); }); _passwordFocusNode.addListener(() { setState(() { _isFocuseOnPasswordField = _passwordFocusNode.hasFocus; }); }); }
@override void dispose() { _emailFocusNode.dispose(); _passwordFocusNode.dispose(); super.dispose(); } bool isChecked = false; Color BillFoxPrimair = Color.fromRGBO(107, 184, 199,1.0); Color Background = Colors.white;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Background,
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children:
focusNode: _passwordFocusNode,
onChanged: (value) {
//Do something with the user input.
},
decoration: kTextFieldDecoration
.copyWith(hintText: 'Enter your password')
.copyWith(prefixIcon: const Icon(Icons.lock_outlined))
.copyWith(prefixIconColor: _isFocuseOnPasswordField ? BillFoxPrimair : Colors.grey
)
),
const SizedBox(
height: 24.0,
),
RoundedButton(Colors.blue, 'Log in', () async {
var clientId = "testclientid";
var zettleInit =
await Zettle.init(clientId, clientId, "redirectURL");
setState(() {
_message = 'init $zettleInit';
});
Navigator.pushNamed(context, InvoicesOverViewScreen.id);
}),
LabeledCheckbox(
label: 'Remember me',
value: isChecked,
onChanged: (value) {
isChecked = value;
},
leadingCheckbox: isChecked,
)
],
),
),
);
}
// void onChanged() {} }
I can see from your error trace that it is thrown when requestPayment
is called, but this is not in your example code, so I think that the example is incomplete.
Hi sorry for the late response I was sick last two weeks. I modified my code a little bit. To make it easier to fix the problem. But I cannot get any further I also tried using your example app, this also does not work. Same error it seems.
import 'package:flutter/material.dart'; import 'package:animated_text_kit/animated_text_kit.dart'; import 'package:payment_app/screens/registration_screen.dart'; import 'package:zettle/zettle.dart';
import 'login_screen.dart';
class WelcomeScreen extends StatefulWidget { static String id = 'welcome_screen';
@override _WelcomeScreenState createState() => _WelcomeScreenState(); }
class _WelcomeScreenState extends State
@override void initState() { super.initState();
animationController =
AnimationController(duration: const Duration(seconds: 1), vsync: this);
animation = ColorTween(begin: Colors.blueGrey, end: Colors.white)
.animate(animationController);
animationController.forward();
animationController.addListener(() {
setState(() {});
});
}
@override void dispose() { super.dispose(); animationController.dispose(); }
@override
Widget build(BuildContext context) {
Color BillFoxPrimair = Color.fromRGBO(107, 184, 199,1.0);
return Scaffold(
backgroundColor: animation.value,
body: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.stretch,
children:
class RoundedButton extends StatelessWidget { final Color color; final String buttonTitle; final VoidCallback onPressed;
RoundedButton(this.color, this.buttonTitle, this.onPressed, {super.key});
@override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.symmetric(vertical: 12.0), child: Material( color: color, borderRadius: BorderRadius.circular(5), elevation: 5.0, child: MaterialButton( onPressed: onPressed,
height: 42.0,
child: Text(
buttonTitle,
style: const TextStyle(color: Colors.white, fontSize: 20.0),
),
),
),
);
} }
received this message but i initiated the zettle sdk as per your documentation. Unhandled Exception: Exception: Zettle SDK is not initialized. You should call Zettle.init(iosClientId, androidClientId, redirectUrl)