FlutterアプリでElevatedButtonのonPressedに指定したメソッドが反応しない

dart

1import 'package:flutter/material.dart';2import 'package:flutter_map/flutter_map.dart';3import 'package:latlong2/latlong.dart';4 5double a = 0;6double b = 0;7 8void main() async {9 WidgetsFlutterBinding.ensureInitialized();10 print('初期表示');11 runApp(const TestApp());12}13 14class TestApp extends StatefulWidget {15 const TestApp({super.key});16 17 State<TestApp> createState() => _TestApp();18}19 20class _TestApp extends State<TestApp> {21 final String _title = 'TestApp';22 List<CircleMarker> circleMarkers = [];23 24 void initState() {25 super.initState();26 initLocation();27 }28 29 30 Widget build(BuildContext context) {31 return MaterialApp(32 title: 'TestMap',33 theme: ThemeData(34 primarySwatch: Colors.blue,35 ),36 home: Scaffold(37 appBar: AppBar(38 title: Text(_title),39 actions: <Widget>[40 SizedBox(41 width: 36,42 height: 36,43 child: ElevatedButton(44 style: ElevatedButton.styleFrom(45 elevation: 10,46 backgroundColor: Colors.amber[500],47 shape: const CircleBorder(),48 padding: const EdgeInsets.all(2),49 ),50 onPressed: () => _onButtonPressed(),51 child: const Icon(52 Icons.refresh_sharp,53 color: Colors.blue,54 ),55 ),56 ),57 const SizedBox(58 width: 10,59 ),60 ],61 ),62 extendBodyBehindAppBar: false,63 body: FlutterMap(64 options: MapOptions(65 center: LatLng(a, b),66 zoom: 16.0,67 interactiveFlags: InteractiveFlag.all,68 enableScrollWheel: true,69 scrollWheelVelocity: 0.00001,70 ),71 children: [72 TileLayer(73 urlTemplate: "https://tile.openstreetmap.jp/{z}/{x}/{y}.png",74 userAgentPackageName: 'land_place',75 ),76 CircleLayer(circles: circleMarkers),77 ],78 ),79 ),80 );81 }82 83 _onButtonPressed() {84 print('ボタン押下');85 }86 87 Future<void> initLocation() async {88 setState(() {});89 }90}91

コメントを投稿

0 コメント