Great blog post by a good friend and colleague of mine, James MacKay from Esri Australia on building your first widget for Web AppBuilder for ArcGIS. Includes links to code samples on GitHub.
Web AppBuilder: Build your first widget in 15 minutes
Enjoy,