  Motivated by the recent discovery of Mott insulating phase and unconventional
superconductivity due to the flat bands in twisted bilayer graphene, we propose
more generic ways of getting two-dimensional (2D) emergent flat band lattices
using either 2D Dirac materials or ordinary electron gas (2DEG) subject to
moderate periodic orbital magnetic fields with zero spatial average. Employing
both momentum-space and real-space numerical methods to solve the eigenvalue
problems, we find stark contrast between Schr\"{o}dinger and Dirac electrons,
i.e., the former show recurring "magic" values of the magnetic field when the
lowest band becomes flat, while for the latter the zero-energy bands are
asymptotically flat without magicness. By examining the Wannier functions
localized by the smooth periodic magnetic fields, we are able to explain these
nontrivial behaviors using minimal tight-binding models on a square lattice.
The two cases can be interpolated by varying the $g$-factor or effective mass
of a 2DEG and by taking into account the Zeeman coupling, which also leads to
flat bands with nonzero Chern numbers for each spin. Our work provides flexible
platforms for exploring interaction-driven phases in 2D systems with on-demand
superlattice symmetries.
