Changed Theme.of(context).primaryColor to Theme.of(contex).colorScheme.primary to make dark mode work properly.