1
1
import 'package:flutter/material.dart' ;
2
+ import 'package:flutter_localizations/flutter_localizations.dart' ;
3
+ import 'package:flutter_markdown/flutter_markdown.dart' ;
4
+
5
+ import 'texts.dart' ;
2
6
3
7
void main () {
4
8
runApp (const MyApp ());
@@ -11,22 +15,16 @@ class MyApp extends StatelessWidget {
11
15
Widget build (BuildContext context) {
12
16
return MaterialApp (
13
17
title: 'Flutter Chat' ,
18
+ localizationsDelegates: const [
19
+ GlobalMaterialLocalizations .delegate,
20
+ GlobalWidgetsLocalizations .delegate,
21
+ GlobalCupertinoLocalizations .delegate,
22
+ ],
23
+ supportedLocales: const [
24
+ Locale ('en' ), // English
25
+ Locale ('ru' ), // Russian
26
+ ],
14
27
theme: ThemeData (
15
- // This is the theme of your application.
16
- //
17
- // TRY THIS: Try running your application with "flutter run". You'll see
18
- // the application has a blue toolbar. Then, without quitting the app,
19
- // try changing the seedColor in the colorScheme below to Colors.green
20
- // and then invoke "hot reload" (save your changes or press the "hot
21
- // reload" button in a Flutter-supported IDE, or press "r" if you used
22
- // the command line to start the app).
23
- //
24
- // Notice that the counter didn't reset back to zero; the application
25
- // state is not lost during the reload. To reset the state, use hot
26
- // restart instead.
27
- //
28
- // This works for code too, not just values: Most code changes can be
29
- // tested with just a hot reload.
30
28
colorScheme: ColorScheme .fromSeed (seedColor: Colors .deepPurple),
31
29
useMaterial3: true ,
32
30
),
@@ -38,87 +36,54 @@ class MyApp extends StatelessWidget {
38
36
class MyHomePage extends StatefulWidget {
39
37
const MyHomePage ({super .key, required this .title});
40
38
41
- // This widget is the home page of your application. It is stateful, meaning
42
- // that it has a State object (defined below) that contains fields that affect
43
- // how it looks.
44
-
45
- // This class is the configuration for the state. It holds the values (in this
46
- // case the title) provided by the parent (in this case the App widget) and
47
- // used by the build method of the State. Fields in a Widget subclass are
48
- // always marked "final".
49
-
50
39
final String title;
51
40
52
41
@override
53
42
State <MyHomePage > createState () => _MyHomePageState ();
54
43
}
55
44
56
45
class _MyHomePageState extends State <MyHomePage > {
57
- int _counter = 0 ;
58
-
59
- void _incrementCounter () {
60
- setState (() {
61
- // This call to setState tells the Flutter framework that something has
62
- // changed in this State, which causes it to rerun the build method below
63
- // so that the display can reflect the updated values. If we changed
64
- // _counter without calling setState(), then the build method would not be
65
- // called again, and so nothing would appear to happen.
66
- _counter++ ;
67
- });
68
- }
46
+ Locales _locale = Locales .en;
69
47
70
48
@override
71
49
Widget build (BuildContext context) {
72
- // This method is rerun every time setState is called, for instance as done
73
- // by the _incrementCounter method above.
74
- //
75
- // The Flutter framework has been optimized to make rerunning build methods
76
- // fast, so that you can just rebuild anything that needs updating rather
77
- // than having to individually change instances of widgets.
50
+ final titleBgColor = Theme .of (context).colorScheme.inversePrimary;
51
+ final bgColor = Theme .of (context).colorScheme.background;
52
+
78
53
return Scaffold (
79
54
appBar: AppBar (
80
- // TRY THIS: Try changing the color here to a specific color (to
81
- // Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
82
- // change color while the other colors stay the same.
83
- backgroundColor: Theme .of (context).colorScheme.inversePrimary,
84
- // Here we take the value from the MyHomePage object that was created by
85
- // the App.build method, and use it to set our appbar title.
55
+ backgroundColor: titleBgColor,
86
56
title: Text (widget.title),
87
57
),
88
- body: Center (
89
- // Center is a layout widget. It takes a single child and positions it
90
- // in the middle of the parent.
58
+ body: Padding (
59
+ padding: const EdgeInsets .all (8.0 ),
91
60
child: Column (
92
- // Column is also a layout widget. It takes a list of children and
93
- // arranges them vertically. By default, it sizes itself to fit its
94
- // children horizontally, and tries to be as tall as its parent.
95
- //
96
- // Column has various properties to control how it sizes itself and
97
- // how it positions its children. Here we use mainAxisAlignment to
98
- // center the children vertically; the main axis here is the vertical
99
- // axis because Columns are vertical (the cross axis would be
100
- // horizontal).
101
- //
102
- // TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
103
- // action in the IDE, or press "p" in the console), to see the
104
- // wireframe for each widget.
105
- mainAxisAlignment: MainAxisAlignment .center,
106
61
children: < Widget > [
107
- const Text (
108
- 'You have pushed the button this many times:' ,
62
+ Align (
63
+ alignment: Alignment .topRight,
64
+ child: DropdownButton <Locales >(
65
+ focusColor: bgColor,
66
+ items: Locales .values
67
+ .map ((l) =>
68
+ DropdownMenuItem (value: l, child: Text (l.displayName)))
69
+ .toList (),
70
+ onChanged: (l) => setState (() {
71
+ _locale = l! ;
72
+ }),
73
+ value: _locale,
74
+ ),
109
75
),
110
- Text (
111
- '$_counter ' ,
112
- style: Theme .of (context).textTheme.headlineMedium,
76
+ Expanded (
77
+ child: SizedBox (
78
+ //width: 400,
79
+ child: Markdown (
80
+ data: Texts .mainIntro.text[_locale]! ,
81
+ ),
82
+ ),
113
83
),
114
84
],
115
85
),
116
86
),
117
- floatingActionButton: FloatingActionButton (
118
- onPressed: _incrementCounter,
119
- tooltip: 'Increment' ,
120
- child: const Icon (Icons .add),
121
- ), // This trailing comma makes auto-formatting nicer for build methods.
122
87
);
123
88
}
124
89
}
0 commit comments