I've tried defining the following custom environment, but I get errors:
\begin{gather} ended by \end{solution} etc...
Here's a MWE showing my problem:
\documentclass{article}
\usepackage[fleqn]{mathtools}
\newenvironment{solution}{% <-Solution
\par\addvspace{1em}
\itshape{Solution:}\par\begin{gather}}
{\end{gather}\par\normalfont\hfill\qed\par\addvspace{\medskipamount}}%
\begin{document}
\begin{gather}
testing
\end{gather}
%% This does not work:
\begin{solution}
testing
\end{solution}
\end{document}
