// Copyright (c) 2021 Razeware LLC // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // Notwithstanding the foregoing, you may not use, copy, modify, merge, publish, // distribute, sublicense, create a derivative work, and/or sell copies of the // Software in any work that is designed, intended, or marketed for pedagogical // or instructional purposes related to programming, coding, application // development, or information technology. Permission for such use, copying, // modification, merger, publication, distribution, sublicensing, creation of // derivative works, or sale is expressly withheld. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. import 'arc_curves_painter.dart'; import 'common/common_scaffold.dart'; import 'grid/grid_widget.dart'; import 'ovals_painter.dart'; import 'polygon_painter.dart'; import 'battery/animated_battery.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({Key? key}) : super(key: key); @override Widget build(BuildContext context) { SystemChrome.setPreferredOrientations([ DeviceOrientation.portraitUp, DeviceOrientation.portraitDown, ]); return MaterialApp( title: 'Canvas Basics', debugShowCheckedModeBanner: false, theme: ThemeData( primarySwatch: Colors.blue, ), home: HomeWidget(), ); } } class HomeWidget extends StatelessWidget { HomeWidget({Key? key}) : super(key: key); final items = [ Item('Polygons', GridWidget(PolygonPainter())), Item('Ovals and Circles', GridWidget(OvalPainter())), Item('Arc and Curves', GridWidget(ArcsCurvesPainter())), Item('Animated Battery', const AnimatedBattery()), ]; @override Widget build(BuildContext context) { return CommonScaffold( title: 'Canvas Basics', child: Column( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: items.map((e) => ItemWidget(e)).toList(), ), ); } } // TODO: Rename project class ItemWidget extends StatelessWidget { final Item item; const ItemWidget(this.item, {Key? key}) : super(key: key); @override Widget build(BuildContext context) { return Container( width: double.infinity, margin: const EdgeInsets.symmetric(horizontal: 20, vertical: 7), child: TextButton( style: TextButton.styleFrom( foregroundColor: Colors.white, backgroundColor: const Color(0xFF158443), padding: const EdgeInsets.symmetric(vertical: 15)), onPressed: () { final widget = CommonScaffold(title: item.title, child: item.widget); Navigator.of(context) .push(MaterialPageRoute(builder: (_) => widget)); }, child: Text( item.title, style: const TextStyle( fontSize: 18, fontWeight: FontWeight.bold, ), ), ), ); } } class Item { final String title; final Widget widget; Item(this.title, this.widget); }