I found one method to do this. There is a plugin "WindowListener"
class _AppHomePageState extends State<AppHomePage> with WindowListener // Overrite the onWindowClose method. When exit app, onWindowClose will be called.