Skip to content

Instantly share code, notes, and snippets.

@angelabauer
Created March 7, 2019 12:19
Show Gist options
  • Save angelabauer/76043b339eeee1142b8d02ee05bde15c to your computer and use it in GitHub Desktop.
Save angelabauer/76043b339eeee1142b8d02ee05bde15c to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() => runApp(
MaterialApp(
home: BallPage(),
),
);
class BallPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blue,
appBar: AppBar(
backgroundColor: Colors.blue.shade900,
title: Text('Ask Me Anything'),
),
body: Ball(),
);
}
}
class Ball extends StatefulWidget {
@override
_BallState createState() => _BallState();
}
class _BallState extends State<Ball> {
@override
Widget build(BuildContext context) {
return Center(
child: FlatButton(
onPressed: () {
print('I got clicked');
},
child: Image.asset('images/ball1.png'),
),
);
}
}
@wkzmrj
Copy link

wkzmrj commented Sep 23, 2023 via email

@AdityaAmara
Copy link

I couldn't find FlatButton in the latest Flutter SDK. I have used TextButton instead of FlatButton. The code as follows:

import 'package:flutter/material.dart';

void main() => runApp(
      MaterialApp(
        home: BallPage(),
      ),
);

class BallPage extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.blue[100],
      appBar: AppBar(
        title: Text('Ask Me Anything'),
      ),
      body: Ball()
    );
  }
}

class Ball extends StatefulWidget {
  @override
  State<Ball> createState() => _BallState();
}

class _BallState extends State<Ball> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: TextButton(
          onPressed: () {
            print("I got clicked");
          },
          child: Image.asset('images/ball1.png')
      ),
    );
  }
}

@xmkhatshwa
Copy link

xmkhatshwa commented May 11, 2024

This is how I got my code to work:

import 'package:flutter/material.dart';

void main() => runApp(
      MaterialApp(
        home: BallPage()
      ),
    );

class Ball extends StatefulWidget {
  const Ball({super.key});

  @override
  State<Ball> createState() => _BallState();
}

class _BallState extends State<Ball> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: TextButton(
          onPressed: () {
              print('Button clicked!');
            },
          child: Image.asset('images/ball1.png'),
      )
    );
  }
}


class BallPage extends StatelessWidget {
  const BallPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.blue,
      appBar: AppBar(
        title: Text('Ask Me Anything',
          style: TextStyle(
              color: Colors.white
          ),
        ),
        backgroundColor: Colors.blue.shade900,
      ),
      body: Ball(),
    );
  }
}

image

Thank you @angelabauer

@wkzmrj
Copy link

wkzmrj commented May 11, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment