You could try my example:
import tensorflow as tf

tsta = tf.random.uniform([3,10,2])
tf.random.set_seed(111111)
inp = tf.keras.layers.Input((10,2))
x = tf.keras.layers.Flatten()(inp)
x = tf.keras.layers.Dense(5)(x)
m1 = tf.keras.Model(inputs=inp, outputs=x)
m1.build(input_shape = (3, 10, 2))
m1.summary()
print(m1(tsta))

tf.random.set_seed(111111)
class MyModel(tf.keras.Model):
   def __init__(self, out_size = 5):
       super(MyModel, self).__init__()
       self.flatten = tf.keras.layers.Flatten()
       self.dense = tf.keras.layers.Dense(out_size)

   def call(self, x):
       x = self.flatten(x)
       x = self.dense(x)
       return x
m2 = MyModel()
m2.build(input_shape = (3, 10, 2))
m2.summary()
print(m2(tsta))