三天前我问了同样的问题,但我没有得到答案,所以我再次问。有没有办法在登录到odoo实例后保持相同的连接(客户端)并跨页面使用它,如果是这样,它是如何完成的?
import 'package:odoo_rpc/odoo_rpc.dart';
Future<bool> _loggin(email, password) async {
final client = OdooClient('http://localhost:8069');
// String database = 'CENTRAL-KAD';
String database = 'odoo';
String email = 'admin';
String password = "admin";
if (_formKey.currentState!.validate()) {
try {
final session = await client.authenticate(database, email, password);
final res = await client.callRPC('/web/session/modules', 'call', {});
print('Installed modules: \n' + res.toString());
Navigator.push(context,
MaterialPageRoute(builder: (context) => const welcomscreen()),
);
} on OdooException catch (e) {
print(e);
}
}
}
Welcome_screen
我想获取client
此页面中的连接,以便使用它进行 CRUD,并且无需打开新连接
class welcomeScreen extends StatefulWidget {
welcomeScreen();
@override
_welcomeScreenState createState() => _welcomeScreenState();
}
class _welcomeScreenState extends State<welcomeScreen> {
_welcomeScreenState();
@override
Widget build(BuildContext context) {
return Scaffold(
///... some view ...
child: MaterialButton(
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: const StadiumBorder(),
child: const Text(
'Find Customer',
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: 32.0,
fontWeight: FontWeight.bold,
),
),
onPressed: (){
client.callKw({
'model': 'res.partner',
'method': 'search_read',
'args': [],
'kwargs': {
'context': {'bin_size': true},
'domain': [],
'fields': ['id', 'name', 'email', '__last_update', 'image_128'],
'limit': 80,
},
});
}
)
);
}