Heat the butter in a pan or wok on a medium flame. Add garlic to the butter and add the chopped onion and stir until onion is softened. Then add the chili flakes and cook about 3 minutes in a very low flame.
Now add the pineapple and bring the heat up to medium. Add salt and mix well. And add the sugar and mix again.
Keep stir until the gravy is dissolved. You may notice that pineapple color will change gradually.