I am trying to use AMS blackboard bold font together with TG Pagella Math in the way given in this answer. But I got the error
! Internal error: bad native font flag in `map_char_to_glyph'
Example (xelatex):
\documentclass{article}
\usepackage{mathtools}
\usepackage{unicode-math}
\setmathfont{TeX Gyre Pagella Math}
\DeclareSymbolFont{AMSb}{U}{msb}{m}{n}
\protected\def\mathbb#1{{\mathchar\numexpr256*\symAMSb+`#1\relax}}
\begin{document}
$\hat{\mathbb{Z}}$
\end{document}
It seems that there is a similar question here. I would like to know whether there are some better workaround to this problem.