The quotation Genius is an infinite capacity for taking pains is proverbial and dates to the late 19th century, more or less around Dickens's time. However, nothing like it is found in any of his novels or published letters. If he said it in an after-dinner speech, we have no records of the rest of the speech. Nor do we know when or to what audience he is supposed to have said it.
A close approximation turns up in the work of Dickens's contemporary, Thomas Carlyle. His Life of Frederick the Great (1858), Book IV, Chapter 3, has the following:
The good plan itself, this comes not of its own accord; it
is the fruit of "genius" (which means transcendent capacity of taking
trouble, first of all): given a huge stack of tumbled thrums, it is
not in your sleep that you will find the vital centre of it, or get the
first thrum by the end!
The earliest print source that I'm aware of where the quotation occurs exactly as stated in Maugham's 1930 novel is Arthur Conan Doyle's A Study in Scarlet (1887), Part I, Chapter 3, "The Lauriston Gardens Mystery":
"They say that genius is an infinite capacity for taking pains," he remarked with a smile. "It's a very bad definition, but it does apply to detective work."
Dickens died a scant seventeen years before this novel appeared in print. If the line is really from him, one would expect Holmes to say something like Dickens said rather than They say, I think. More likely it's just a pithy statement of a sentiment that comes from Carlyle and/or was in the air during the Victorian period.