Fix incorrect usage of BuildContext APIs