|
1 | 1 | import 'package:flutter/material.dart'; |
2 | | -import 'detail.dart'; |
3 | | -import 'service.dart'; |
4 | | -import 'package:pr12er/protos/pkg/pr12er/messages.pb.dart'; |
| 2 | +import 'package:pr12er/service.dart'; |
| 3 | +import 'package:provider/provider.dart'; |
5 | 4 |
|
6 | | -void main() => runApp(MyApp()); |
| 5 | +import 'screens/detail_screen.dart'; |
| 6 | +import 'screens/main_screen.dart'; |
7 | 7 |
|
8 | | -class MyApp extends StatelessWidget { |
9 | | - @override |
10 | | - Widget build(BuildContext context) { |
11 | | - return MaterialApp( |
12 | | - title: 'Welcome to Flutter', |
13 | | - home: Scaffold( |
14 | | - appBar: AppBar( |
15 | | - leading: Icon(Icons.search), |
16 | | - title: Text('pr12errrrrrrrrrrrrrrrrrrr'), |
17 | | - ), |
18 | | - body: Client()), |
19 | | - ); |
20 | | - } |
21 | | -} |
| 8 | +const appName = 'PR12er'; |
22 | 9 |
|
23 | | -class Client extends StatefulWidget { |
24 | | - @override |
25 | | - _ClientState createState() => _ClientState(); |
26 | | -} |
| 10 | +void main() => runApp(MultiProvider(providers: [ |
| 11 | + Provider( |
| 12 | + create: (context) => GrpcClient(), |
| 13 | + ) |
| 14 | + ], child: const MainApp())); |
27 | 15 |
|
28 | | -class _ClientState extends State<Client> { |
29 | | - List<Video> videos = []; |
30 | | - final myController = TextEditingController(); |
31 | | - |
32 | | - Future<List<Video>> _fetchListItems() async { |
33 | | - List<Video> videos = await GrpcMsgSender().getVideos(); |
34 | | - return videos; |
35 | | - } |
36 | | - |
37 | | - List<Widget> getCategoryWidgets(Category category) { |
38 | | - switch (category) { |
39 | | - case Category.CATEGORY_VISION: |
40 | | - return [Icon(Icons.remove_red_eye), Text('CV')]; |
41 | | - case Category.CATEGORY_NLP: |
42 | | - return [Icon(Icons.translate), Text('NLP')]; |
43 | | - case Category.CATEGORY_AUDIO: |
44 | | - return [Icon(Icons.graphic_eq), Text('AUDIO')]; |
45 | | - case Category.CATEGORY_RS: |
46 | | - return [Icon(Icons.assistant), Text('RS')]; |
47 | | - case Category.CATEGORY_OCR: |
48 | | - return [Icon(Icons.text_fields), Text('OCR')]; |
49 | | - case Category.CATEGORY_UNSPECIFIED: |
50 | | - default: |
51 | | - return [Icon(Icons.grid_view), Text('ETC')]; |
52 | | - } |
53 | | - } |
| 16 | +class MainApp extends StatelessWidget { |
| 17 | + const MainApp({ |
| 18 | + Key? key, |
| 19 | + }) : super(key: key); |
54 | 20 |
|
55 | 21 | @override |
56 | 22 | Widget build(BuildContext context) { |
57 | | - return FutureBuilder( |
58 | | - future: _fetchListItems(), |
59 | | - builder: (context, AsyncSnapshot snapshot) { |
60 | | - if (!snapshot.hasData) { |
61 | | - return Center(child: CircularProgressIndicator()); |
62 | | - } |
63 | | - return ListView.builder( |
64 | | - padding: const EdgeInsets.all(8), |
65 | | - itemCount: snapshot.data.length, |
66 | | - itemBuilder: (BuildContext context, int index) { |
67 | | - return getTile(index, |
68 | | - title: snapshot.data[index].title, |
69 | | - presenter: snapshot.data[index].presenter, |
70 | | - keyword: "현재 키워드 지원(X)", |
71 | | - category: snapshot.data[index].category, |
72 | | - url: snapshot.data[index].link); |
73 | | - }); |
74 | | - }); |
75 | | - } |
76 | | - |
77 | | - Widget getTile(int index, |
78 | | - {String title = "", |
79 | | - String presenter = "", |
80 | | - String keyword = "", |
81 | | - Category category = Category.CATEGORY_UNSPECIFIED, |
82 | | - String url = ""}) { |
83 | | - return Card( |
84 | | - child: ListTile( |
85 | | - leading: Column( |
86 | | - mainAxisAlignment: MainAxisAlignment.center, |
87 | | - children: getCategoryWidgets(category)), |
88 | | - title: Text('${title}'), |
89 | | - subtitle: Padding( |
90 | | - padding: EdgeInsets.only(top: 10), |
91 | | - child: Row(children: [ |
92 | | - Column(children: [Text(presenter)]), |
93 | | - Padding( |
94 | | - padding: EdgeInsets.only(left: 30), |
95 | | - child: Column(children: [ |
96 | | - Text( |
97 | | - keyword, |
98 | | - style: TextStyle(fontStyle: FontStyle.italic), |
99 | | - ) |
100 | | - ])) |
101 | | - ])), |
102 | | - trailing: Column( |
103 | | - mainAxisAlignment: MainAxisAlignment.center, |
104 | | - children: [Icon(Icons.favorite_border_outlined)]), |
105 | | - onTap: () { |
106 | | - Navigator.push( |
107 | | - context, |
108 | | - MaterialPageRoute( |
109 | | - builder: (context) => DetailApp(url), |
110 | | - ), |
111 | | - ); |
112 | | - }, |
113 | | - ), |
| 23 | + return MaterialApp( |
| 24 | + title: appName, |
| 25 | + initialRoute: MainScreen.routeName, |
| 26 | + routes: { |
| 27 | + MainScreen.routeName: (context) => MainScreen(), |
| 28 | + DetailScreen.routeName: (context) => DetailScreen(), |
| 29 | + }, |
114 | 30 | ); |
115 | 31 | } |
116 | 32 | } |
0 commit comments