diff --git a/lib/dummy_page.dart b/lib/dummy_page.dart new file mode 100644 index 0000000..dcace44 --- /dev/null +++ b/lib/dummy_page.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +class DummyPage extends StatelessWidget { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text("dummy"), + ), + body: const Text("dummy"), + ); + } +} diff --git a/lib/main.dart b/lib/main.dart index 0df2043..b8def9b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,156 +1,117 @@ +// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + import 'package:flutter/material.dart'; +import 'dummy_page.dart'; -void main() => runApp(const MyApp()); +void main() => runApp(MyApp()); class MyApp extends StatelessWidget { - const MyApp({super.key}); - @override Widget build(BuildContext context) { - Color color = Theme.of(context).primaryColor; - - Widget buttonSection = Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - _buildButtonColumn(color, Icons.call, 'CALL'), - _buildButtonColumn(color, Icons.near_me, 'ROUTE'), - _buildButtonColumn(color, Icons.share, 'SHARE'), - ], - ); - - Widget titleSection = Container( - padding: const EdgeInsets.all(32), - child: Row( - children: [ - Expanded( - /*1*/ - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - /*2*/ - Container( - padding: const EdgeInsets.only(bottom: 8), - child: const Text( - 'Oeschinen Lake Campground', - style: TextStyle( - fontWeight: FontWeight.bold, - ), - ), - ), - Text( - 'Kandersteg, Switzerland', - style: TextStyle( - color: Colors.grey[500], - ), - ), - ], - ), - ), - /*3*/ - const FavoriteWidget() - ], - ), - ); - Widget textSection = const Padding( - padding: EdgeInsets.all(32), - child: Text( - 'Lake Oeschinen lies at the foot of the Blüemlisalp in the Bernese ' - 'Alps. Situated 1,578 meters above sea level, it is one of the ' - 'larger Alpine Lakes. A gondola ride from Kandersteg, followed by a ' - 'half-hour walk through pastures and pine forest, leads you to the ' - 'lake, which warms to 20 degrees Celsius in the summer. Activities ' - 'enjoyed here include rowing, and riding the summer toboggan run.', - softWrap: true, - ), - ); return MaterialApp( - title: 'Flutter layout demo', - home: Scaffold( - appBar: AppBar( - title: const Text('Flutter layout demo'), - ), - body: ListView( - children: [ - Image.asset('images/lake.jpeg', - width: 600, height: 240, fit: BoxFit.cover), - titleSection, - buttonSection, - textSection - ], - ), + title: 'Flutter Demo', + debugShowCheckedModeBanner: false, + theme: ThemeData( + primarySwatch: Colors.blue, ), + home: const MyHomePage(title: 'Flutter Demo Home Page'), ); } +} - Column _buildButtonColumn(Color color, IconData icon, String label) { - return Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Icon(icon, color: color), - Container( - margin: const EdgeInsets.only(top: 8), - child: Text( - label, - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.w400, - color: color, - ), - ), - ), - ], - ); +class MyHomePage extends StatefulWidget { + final String title; + + const MyHomePage({ + Key? key, + required this.title, + }) : super(key: key); + + @override + State createState() { + print("call createState"); + return _MyHomePageState(); } } -class FavoriteWidget extends StatefulWidget { - const FavoriteWidget({super.key}); +class _MyHomePageState extends State { + int _counter = 0; + + void _incrementCounter() { + setState(() { + print("call setState"); + _counter++; + }); + // nextpage(); + } + + void nextpage() async { + print('ダミー画面に今から遷移します'); + // ダミー画面へ遷移 + await Navigator.of(context) + .pushReplacement(MaterialPageRoute(builder: (context) { + return DummyPage(); + })); + } @override - State createState() => _FavoriteWidgetState(); -} + void initState() { + super.initState(); + print("call initState"); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + print("call didChangeDependencies"); + } -class _FavoriteWidgetState extends State { - bool _isFavorited = true; - int _favoriteCount = 41; + @override + void didUpdateWidget(MyHomePage oldWidget) { + super.didUpdateWidget(oldWidget); + print("call didUpdateWidget"); + } @override Widget build(BuildContext context) { - return Row( - mainAxisSize: MainAxisSize.min, - children: [ - Container( - padding: const EdgeInsets.all(0), - child: IconButton( - padding: const EdgeInsets.all(0), - alignment: Alignment.centerRight, - icon: (_isFavorited - ? const Icon(Icons.star) - : const Icon(Icons.star_border)), - color: Colors.red[500], - onPressed: _toggleFavorite, - ), - ), - SizedBox( - width: 18, - child: SizedBox( - child: Text('$_favoriteCount'), - ), + print("call build"); + return Scaffold( + appBar: AppBar( + title: Text(widget.title), + ), + body: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text( + 'You have pushed the button this many times:', + ), + Text( + '$_counter', + style: Theme.of(context).textTheme.headline4, + ), + ], ), - ], + ), + floatingActionButton: FloatingActionButton( + onPressed: _incrementCounter, + tooltip: 'Increment', + child: const Icon(Icons.add), + ), ); } - void _toggleFavorite() { - setState(() { - if (_isFavorited) { - _favoriteCount -= 1; - _isFavorited = false; - } else { - _favoriteCount += 1; - _isFavorited = true; - } - }); + @override + void deactivate() { + super.deactivate(); + print("call deactivate"); + } + + @override + void dispose() { + super.dispose(); + print("call dispose"); } }