If you know when the dividends were paid (usually every quarter), then allocate them based on where you were living at the time they were paid to you.You can check with your investment firn/bank/brokerage to see when the dividends were paid.
Otherwise, allocate the total based on the percentage of time you lived in each state. For example, if you had $1000 in dividends and lived in one state fo4 4 months, then that state would have (4/12) X $1000 = $333 of your 2020 dividend income; the other state would have the rest of the dividend income, i.e. $667.