  Superconducting Quantum Interference Devices (SQUIDs) and other
superconducting circuits are limited by intrinsic flux noise with spectral
density $1/f^{\alpha}$ with $\alpha<1$ whose origin is believed to be due to
spin impurities. Here we present a theory of flux noise that takes into account
the vectorial nature of the coupling of spins to superconducting wires. We
present explicit numerical calculations of the flux noise power (spectral
density integrated over all frequencies) for electron impurities and lattice
nuclear spins under several different assumptions. The noise power is shown to
be dominated by surface electron spins near the wire edges, with bulk lattice
nuclear spins contributing $\sim 5$% of the noise power in aluminum and niobium
wires. We consider the role of electron spin phase transitions, showing that
the spin-spin correlation length (describing e.g. the average size of
ferromagnetic spin clusters) greatly impacts the scaling of flux noise with
wire geometry. Remarkably, flux noise power is exactly equal to zero when the
spins are polarized along the flux vector direction, forming what we call a
poloidal state. Flux noise is non-zero for other spin textures, but gets
reduced in the presence of correlated ferromagnetic fluctuations between the
top and bottom wire surfaces, where the flux vectors are antiparallel. This
demonstrates that engineering spin textures and/or inter-surface correlation
provides a method to reduce flux noise in superconducting devices.
