Skip to content

Instantly share code, notes, and snippets.

@vanpav
Last active February 6, 2020 19:29
Show Gist options
  • Save vanpav/46245b947becc870337ce605c07c3c90 to your computer and use it in GitHub Desktop.
Save vanpav/46245b947becc870337ce605c07c3c90 to your computer and use it in GitHub Desktop.
import 'dart:math';
import 'package:flutter/material.dart';
class MyFailureApp extends StatefulWidget{
@override
State<MyFailureApp> createState() => new MyFailureAppState();
}
class MyFailureAppState extends State<MyFailureApp>{
var fillerTexts = List<String>.generate(5, (int index) => Random().nextInt(100).toString());
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: Text("Ayaya"),
actions: <Widget>[PopupButtonWidget()],
),
body: new Container(
child: new ListView.builder(
itemCount: this.fillerTexts.length,
itemBuilder: (context, int index) => WidgetForListsContent(
fillerTexts[index])
),
),
);
}
}
class WidgetForListsContent extends StatelessWidget{
final String name;
WidgetForListsContent(this.name);
@override
Widget build(BuildContext context) {
return new Card(
child: new Container(
padding: EdgeInsets.all(8.0),
child: new Row(
children: <Widget>[
new CircleAvatar(child: new Text(name[0]),),
new Padding(padding: EdgeInsets.only(right: 10.0)),
new Text(name,style: TextStyle(fontSize: 20.0),)
],
),
),
);
}
}
class PopupButtonWidget extends StatelessWidget {
const PopupButtonWidget();
@override
Widget build(BuildContext context) {
return Container(
child: PopupMenuButton<void>(
onSelected: (_) {
myChoiceAction(context);
},
itemBuilder: (BuildContext context){
return MyStringsForApp.myChoices.map((String choice){
return PopupMenuItem<String>(
value: choice,
child: Text(choice),
);
}).toList();
},
)
);
}
void myChoiceAction(context){
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
}
}
// создание роутов для новых экранов
class SecondScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Ti pidor'),
),
);
}
}
// наполнение попап-окошка
class MyStringsForApp{
static const String Choice_One = "Choice_1";
static const String Choice_Two = "Choice_2";
static const String Choice_Three = "Choice_3";
static const List<String> myChoices = <String>[
Choice_One,
Choice_Two,
Choice_Three
];
}
main() => runApp(MaterialApp(home: MyFailureApp(), debugShowCheckedModeBanner: false,));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment