Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
amse
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Matis SPINELLI
amse
Commits
285c5ed2
Commit
285c5ed2
authored
Feb 07, 2024
by
Timothe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tp1 base
parent
1e6c875c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
217 additions
and
196 deletions
+217
-196
analysis_options.yaml
tp1/analysis_options.yaml
+7
-24
main.dart
tp1/lib/main.dart
+178
-91
pubspec.lock
tp1/pubspec.lock
+25
-9
pubspec.yaml
tp1/pubspec.yaml
+7
-72
No files found.
tp1/analysis_options.yaml
View file @
285c5ed2
# This file configures the analyzer, which statically analyzes Dart code to
# check for errors, warnings, and lints.
#
# The issues identified by the analyzer are surfaced in the UI of Dart-enabled
# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be
# invoked from the command line by running `flutter analyze`.
# The following line activates a set of recommended lints for Flutter apps,
# packages, and plugins designed to encourage good coding practices.
include
:
package:flutter_lints/flutter.yaml
linter
:
# The lint rules applied to this project can be customized in the
# section below to disable rules from the `package:flutter_lints/flutter.yaml`
# included above or to enable additional rules. A list of all available lints
# and their documentation is published at https://dart.dev/lints.
#
# Instead of disabling a lint rule for the entire project in the
# section below, it can also be suppressed for a single line of code
# or a specific dart file by using the `// ignore: name_of_lint` and
# `// ignore_for_file: name_of_lint` syntax on the line or in the file
# producing the lint.
rules
:
# avoid_print: false # Uncomment to disable the `avoid_print` rule
# prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule
# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
avoid_print
:
false
prefer_const_constructors_in_immutables
:
false
prefer_const_constructors
:
false
prefer_const_literals_to_create_immutables
:
false
prefer_final_fields
:
false
unnecessary_breaks
:
true
use_key_in_widget_constructors
:
false
tp1/lib/main.dart
View file @
285c5ed2
import
'package:english_words/english_words.dart'
;
import
'package:flutter/material.dart'
;
import
'package:provider/provider.dart'
;
import
'dart:math'
;
void
main
(
)
{
runApp
(
const
MyApp
());
runApp
(
MyApp
());
}
class
MyApp
extends
StatelessWidget
{
const
MyApp
({
super
.
key
});
// This widget is the root of your application.
@override
Widget
build
(
BuildContext
context
)
{
return
MaterialApp
(
title:
'Flutter Demo'
,
theme:
ThemeData
(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme:
ColorScheme
.
fromSeed
(
seedColor:
Colors
.
deepPurple
),
useMaterial3:
true
,
return
ChangeNotifierProvider
(
create:
(
context
)
=>
MyAppState
(),
child:
MaterialApp
(
title:
'Namer App'
,
theme:
ThemeData
(
useMaterial3:
true
,
colorScheme:
ColorScheme
.
fromSeed
(
seedColor:
Color
.
fromARGB
(
255
,
Random
().
nextInt
(
255
),
Random
().
nextInt
(
255
),
Random
().
nextInt
(
255
))),
),
home:
MyHomePage
(),
),
home:
const
MyHomePage
(
title:
'Flutter Demo Home Page'
),
);
}
}
class
MyHomePage
extends
StatefulWidget
{
const
MyHomePage
({
super
.
key
,
required
this
.
title
});
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
class
MyAppState
extends
ChangeNotifier
{
var
current
=
WordPair
.
random
();
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
void
getNext
(){
current
=
WordPair
.
random
();
notifyListeners
();
}
var
favorites
=
<
WordPair
>[];
void
toggleFavorite
()
{
if
(
favorites
.
contains
(
current
))
{
favorites
.
remove
(
current
);
}
else
{
favorites
.
add
(
current
);
}
notifyListeners
();
}
final
String
title
;
}
class
MyHomePage
extends
StatefulWidget
{
@override
State
<
MyHomePage
>
createState
()
=>
_MyHomePageState
();
}
class
_MyHomePageState
extends
State
<
MyHomePage
>
{
int
_counter
=
0
;
void
_incrementCounter
()
{
setState
(()
{
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter
++;
});
var
selectedIndex
=
0
;
@override
Widget
build
(
BuildContext
context
)
{
Widget
page
;
switch
(
selectedIndex
)
{
case
0
:
page
=
GeneratorPage
();
break
;
case
1
:
page
=
FavoritePage
();
break
;
default
:
throw
UnimplementedError
(
'no widget for
$selectedIndex
'
);
}
return
LayoutBuilder
(
builder:
(
context
,
constraints
)
{
return
Scaffold
(
body:
Row
(
children:
[
SafeArea
(
child:
NavigationRail
(
extended:
constraints
.
maxWidth
>=
600
,
destinations:
[
NavigationRailDestination
(
icon:
Icon
(
Icons
.
home
),
label:
Text
(
'Home'
),
),
NavigationRailDestination
(
icon:
Icon
(
Icons
.
favorite
),
label:
Text
(
'Favorites'
),
),
],
selectedIndex:
selectedIndex
,
onDestinationSelected:
(
value
)
{
print
(
'selected:
$value
'
);
setState
(()
{
selectedIndex
=
value
;
});
},
),
),
Expanded
(
child:
Container
(
color:
Theme
.
of
(
context
).
colorScheme
.
primaryContainer
,
child:
page
,
),
),
],
),
);
}
);
}
}
class
GeneratorPage
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return
Scaffold
(
appBar:
AppBar
(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor:
Theme
.
of
(
context
).
colorScheme
.
inversePrimary
,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title:
Text
(
widget
.
title
),
var
appState
=
context
.
watch
<
MyAppState
>();
var
pair
=
appState
.
current
;
IconData
icon
;
if
(
appState
.
favorites
.
contains
(
pair
))
{
icon
=
Icons
.
favorite
;
}
else
{
icon
=
Icons
.
favorite_border
;
}
return
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
BigCard
(
pair:
pair
),
SizedBox
(
height:
10
),
Row
(
mainAxisSize:
MainAxisSize
.
min
,
children:
[
ElevatedButton
.
icon
(
onPressed:
()
{
appState
.
toggleFavorite
();
},
icon:
Icon
(
icon
),
label:
Text
(
'Like'
),
),
SizedBox
(
width:
10
),
ElevatedButton
(
onPressed:
()
{
appState
.
getNext
();
},
child:
Text
(
'Next'
),
),
],
),
],
),
body:
Center
(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child:
Column
(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
<
Widget
>[
const
Text
(
'You have pushed the button this many times:'
,
),
Text
(
'
$_counter
'
,
style:
Theme
.
of
(
context
).
textTheme
.
headlineMedium
,
),
],
);
}
}
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
),
child:
Text
(
pair
.
asLowerCase
,
style:
style
,
semanticsLabel:
"
${pair.first}
${pair.second}
"
,
),
),
floatingActionButton:
FloatingActionButton
(
onPressed:
_incrementCounter
,
tooltip:
'Increment'
,
child:
const
Icon
(
Icons
.
add
),
),
// This trailing comma makes auto-formatting nicer for build methods.
);
}
}
class
FavoritePage
extends
StatelessWidget
{
@override
Widget
build
(
BuildContext
context
)
{
var
appState
=
context
.
watch
<
MyAppState
>();
var
favorites
=
appState
.
favorites
;
return
Scaffold
(
body:
Column
(
children:
[
Text
(
'Favorites'
),
for
(
var
fav
in
favorites
)
Text
(
fav
.
asLowerCase
),
],)
);
}
}
\ No newline at end of file
tp1/pubspec.lock
View file @
285c5ed2
...
...
@@ -41,14 +41,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.18.0"
cupertino_icon
s:
english_word
s:
dependency: "direct main"
description:
name:
cupertino_icon
s
sha256:
d57953e10f9f8327ce64a508a355f0b1ec902193f66288e8cb5070e7c47eeb2d
name:
english_word
s
sha256:
"6a7ef6473a97bd8571b6b641d006a6e58a7c67e65fb6f3d6d1151cb46b0e983c"
url: "https://pub.dev"
source: hosted
version: "
1.0.6
"
version: "
4.0.0
"
fake_async:
dependency: transitive
description:
...
...
@@ -66,10 +66,10 @@ packages:
dependency: "direct dev"
description:
name: flutter_lints
sha256:
e2a421b7e59244faef694ba7b30562e489c2b489866e505074eb005cd7060db7
sha256:
a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04
url: "https://pub.dev"
source: hosted
version: "
3.0.1
"
version: "
2.0.3
"
flutter_test:
dependency: "direct dev"
description: flutter
...
...
@@ -103,10 +103,10 @@ packages:
dependency: transitive
description:
name: lints
sha256:
cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290
sha256:
"0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452"
url: "https://pub.dev"
source: hosted
version: "
3.0.0
"
version: "
2.1.1
"
matcher:
dependency: transitive
description:
...
...
@@ -131,6 +131,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.11.0"
nested:
dependency: transitive
description:
name: nested
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
path:
dependency: transitive
description:
...
...
@@ -139,6 +147,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.0"
provider:
dependency: "direct main"
description:
name: provider
sha256: "9a96a0a19b594dbc5bf0f1f27d2bc67d5f95957359b461cd9feb44ed6ae75096"
url: "https://pub.dev"
source: hosted
version: "6.1.1"
sky_engine:
dependency: transitive
description: flutter
...
...
@@ -209,5 +225,5 @@ packages:
source: hosted
version: "14.0.0"
sdks:
dart: ">=3.
4.0-99.0.dev
<4.0.0"
dart: ">=3.
2.0
<4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
tp1/pubspec.yaml
View file @
285c5ed2
name
:
tp1
description
:
"
A
new
Flutter
project."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
description
:
A new Flutter project.
publish_to
:
'
none'
# Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
# followed by an optional build number separated by a +.
# Both the version and the builder number may be overridden in flutter
# build by specifying --build-name and --build-number, respectively.
# In Android, build-name is used as versionName while build-number used as versionCode.
# Read more about Android versioning at https://developer.android.com/studio/publish/versioning
# In iOS, build-name is used as CFBundleShortVersionString while build-number is used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version
:
1.0.0+1
version
:
0.0.1+1
environment
:
sdk
:
'
>=3.4.0-99.0.dev
<4.0.0'
sdk
:
^3.1.1
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
# consider running `flutter pub upgrade --major-versions`. Alternatively,
# dependencies can be manually updated by changing the version numbers below to
# the latest version available on pub.dev. To see which dependencies have newer
# versions available, run `flutter pub outdated`.
dependencies
:
flutter
:
sdk
:
flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons
:
^1.0.6
english_words
:
^4.0.0
provider
:
^6.0.0
dev_dependencies
:
flutter_test
:
sdk
:
flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints
:
^3.0.0
flutter_lints
:
^2.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter
:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.
uses-material-design
:
true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware
# For details regarding adding assets from package dependencies, see
# https://flutter.dev/assets-and-images/#from-packages
# To add custom fonts to your application, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts from package dependencies,
# see https://flutter.dev/custom-fonts/#from-packages
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment