The cooperative behavior in a population engaging in Public Goods Games (PGG) with players in dynamic groups of various sizes and memberships, and a learning mechanism for switching strategy by comparing payoffs between two randomly chosen players each engaging in their own group is studied. We demonstrate that the model has the merit of allowing for an analytic treatment. Upon averaging over all possible group sizes and group constituents in PGG, we derive an analytic expression of the time evolution of the frequency of cooperation fc(t). Starting from an initial cooperative level fc(0), the population will evolve either to a 100% cooperative (AllC) or a 100% non-cooperative (AllD) state depending on the sign of a parameter K∝(r〈1/g〉−1), where r is the multiplicative factor in PGG and 〈1/g〉 is the inverse first moment of the group size distribution of players engaging in PGG. For K>0 (K<0), the system approaches an AllC (AllD) state with an exponential temporal behavior of exp(−2|K|t/M), where M is the population size. The parameter K suggests that cooperation can be promoted by suitably adjusting the multiplicative factor r to be above a critical value rc≡1/〈1/g〉. All the features predicted by the analytic results, including fc(t), the effects of the multiplicative factor r and group size distribution, and how the time constant depends on the parameter K, are confirmed by detailed numerical simulations of the model. The work sheds light on how the varying group sizes, especially the smaller groups, help promote cooperation in a PGG setting.