#flutter
#flutter
Вопрос:
Я новичок в Flutter, и кнопки в следующем коде не показывают никакого эффекта нажатия кнопок, когда я нажимаю кнопки. Я пробовал как в симуляторе, так и на устройстве Android.
Вот код:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
backgroundColor: Colors.blue,
body: SafeArea(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
width: 50,
height: 50,
child: FlatButton(
onPressed: null,
padding: EdgeInsets.all(0.0),
child: Text('First Button'),
),
),
FlatButton(
onPressed: null,
padding: EdgeInsets.all(0.0),
child: Text('Click Me'),
),
Container(
width: 50,
height: 50,
color: Colors.deepPurple,
),
Container(
width: 50,
height: 50,
color: Colors.white,
),
],
)),
));
}
}
Ответ №1:
Ваш onPressed равен нулю, поэтому вы не получаете событие нажатия
FlatButton(
onPressed: (){},
padding: EdgeInsets.all(0.0),
child: Text('Click Me'),
),