Skip to content

Commit 19b0da8

Browse files
committed
-
1 parent 6fb5943 commit 19b0da8

File tree

5 files changed

+83
-264
lines changed

5 files changed

+83
-264
lines changed

lib/l10n/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://docs.flutter.dev/development/accessibility-and-localization/internationalization#introduction-to-localizations-in-flutter

lib/main.dart

Lines changed: 40 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
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';
26

37
void main() {
48
runApp(const MyApp());
@@ -11,22 +15,16 @@ class MyApp extends StatelessWidget {
1115
Widget build(BuildContext context) {
1216
return MaterialApp(
1317
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+
],
1427
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.
3028
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
3129
useMaterial3: true,
3230
),
@@ -38,87 +36,54 @@ class MyApp extends StatelessWidget {
3836
class MyHomePage extends StatefulWidget {
3937
const MyHomePage({super.key, required this.title});
4038

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-
5039
final String title;
5140

5241
@override
5342
State<MyHomePage> createState() => _MyHomePageState();
5443
}
5544

5645
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;
6947

7048
@override
7149
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+
7853
return Scaffold(
7954
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,
8656
title: Text(widget.title),
8757
),
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),
9160
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,
10661
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+
),
10975
),
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+
),
11383
),
11484
],
11585
),
11686
),
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.
12287
);
12388
}
12489
}

lib/texts.dart

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
enum Locales {
2+
en('English'),
3+
ru('Русский'),
4+
;
5+
6+
const Locales(this.displayName);
7+
8+
final String displayName;
9+
}
10+
11+
enum Texts {
12+
mainIntro({
13+
Locales.en: '''
14+
[Flutter](http://flutter.dev) is a beautiful technology for building beautiful applications.
15+
16+
We are a community of people who want Flutter to empower those making this world better, by enabling them to quickly create beautiful web and mobile applications.
17+
18+
We welcome:
19+
* Career explorers, who want to learn and use Flutter
20+
* Volunteers, who would like to support the explorers in understanding Flutter, online or in classroom
21+
22+
We speak English and Russian and want to extend the list of languages.
23+
24+
We are located in the US, Redmond WA and want to extend the list of locations.
25+
26+
Required skills: basic English reading.
27+
28+
Join us at Facebook group [Flutter Chat](https://www.facebook.com/groups/676660377543846/) to participate.
29+
''',
30+
Locales.ru: '''
31+
hi
32+
''',
33+
});
34+
35+
const Texts(this.text);
36+
37+
final Map<Locales, String> text;
38+
}

pubspec.lock

Lines changed: 0 additions & 188 deletions
This file was deleted.

pubspec.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ environment:
99
dependencies:
1010
flutter:
1111
sdk: flutter
12-
cupertino_icons: ^1.0.2
12+
flutter_localizations:
13+
sdk: flutter
14+
flutter_markdown: ^0.6.14
15+
intl: ^0.18.0
1316

1417
dev_dependencies:
1518
flutter_test:

0 commit comments

Comments
 (0)