The QIIME 2 plugin q2-quality-filter also already has such an action. It does not use an average across a sliding window, but you can set a window size for the number of low-quality nucleotides that must occur in a row for trimming to be done at that position.
See qiime quality-filter q-score --help for more details.
So it should be possible to trim with this and then pass to q2-dada2. However, note that dada2 can experience lowered performance when amplicons are of different lengths, as this can impact the error modeling step, so this is possible but you should closely check the results. Some relevant posts about this: