Split into multiple files
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'package:english_words/english_words.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'states/my_app_states.dart';
|
||||
import 'widgets/big_card.dart';
|
||||
import 'widgets/my_home_page.dart';
|
||||
|
||||
void main() {
|
||||
runApp(MyApp());
|
||||
@@ -25,90 +27,6 @@ class MyApp extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class MyAppState extends ChangeNotifier {
|
||||
var current = WordPair.random();
|
||||
var favourites = <WordPair>[];
|
||||
|
||||
void getNext() {
|
||||
current = WordPair.random();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void toggleFavourites() {
|
||||
if (favourites.contains(current)) {
|
||||
favourites.remove(current);
|
||||
} else {
|
||||
favourites.add(current);
|
||||
}
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
class BigCard extends StatelessWidget {
|
||||
const BigCard({
|
||||
super.key,
|
||||
required this.pair,
|
||||
});
|
||||
|
||||
final WordPair pair;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final style = theme.textTheme.displayMedium!.copyWith(
|
||||
color: theme.colorScheme.onPrimary,
|
||||
);
|
||||
|
||||
return Card(
|
||||
color: theme.colorScheme.primary,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Text(pair.asLowerCase,
|
||||
semanticsLabel: "${pair.first} ${pair.second}", style: style),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ...
|
||||
|
||||
class MyHomePage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Row(
|
||||
children: [
|
||||
SafeArea(
|
||||
child: NavigationRail(
|
||||
extended: true,
|
||||
destinations: [
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.home),
|
||||
label: Text('Home'),
|
||||
),
|
||||
NavigationRailDestination(
|
||||
icon: Icon(Icons.favorite),
|
||||
label: Text('Favorites'),
|
||||
),
|
||||
],
|
||||
selectedIndex: 0,
|
||||
onDestinationSelected: (value) {
|
||||
print('selected: $value');
|
||||
},
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Container(
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
child: GeneratorPage(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class GeneratorPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
Reference in New Issue
Block a user