Skip to content

Instantly share code, notes, and snippets.

@kdmatrosov
Last active May 20, 2020 15:42
Show Gist options
  • Save kdmatrosov/8741cccdbb1c07728524dba79f1140d0 to your computer and use it in GitHub Desktop.
Save kdmatrosov/8741cccdbb1c07728524dba79f1140d0 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Example(),
),
);
}
}
class Example extends StatefulWidget {
@override
_ExampleState createState() => _ExampleState();
}
class _ExampleState extends State<Example> {
int _counter = 0;
Widget _weNeedItOnlyOnce() {
print('_weNeedItOnlyOnce');
return Padding(
padding: EdgeInsets.all(32),
child: Text('Просто немного текста'),
);
}
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(32),
child: Column(
children: [
FlatButton(
color: Colors.blue,
child: Text(
'Счетчик: $_counter',
style: TextStyle(color: Colors.white),
),
onPressed: () {
setState(() {
_counter++;
});
},
),
_weNeedItOnlyOnce(),
const WeNeedItOnlyOnce(),
],
));
}
}
class WeNeedItOnlyOnce extends StatelessWidget {
const WeNeedItOnlyOnce();
@override
Widget build(BuildContext context) {
print('WeNeedItOnlyOnce');
return Padding(
padding: EdgeInsets.all(32),
child: Text('Просто немного текста 2'),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment