Commit 87a941eb authored by m-spi's avatar m-spi

Merge branch 'tim' into matis

parents dc5cd0b9 f97716bd
import 'package:english_words/english_words.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'dart:math'; import 'dart:math';
import 'favorite_page.dart'; import 'favorite_page.dart';
import 'app_state.dart'; import 'app_state.dart';
void main() => runApp(const TindBook());
void main() { class TindBook extends StatelessWidget {
runApp(MyApp()); const TindBook({Key? key}) : super(key: key);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ChangeNotifierProvider( return ChangeNotifierProvider(
create: (context) => AppState(), create: (context) => TindBookState(),
child: MaterialApp( child: MaterialApp(
title: 'Namer App',
theme: ThemeData( theme: ThemeData(
useMaterial3: true, primarySwatch: Colors.blue,
colorScheme: ColorScheme.fromSeed(seedColor: Color.fromARGB(255, Random().nextInt(255), Random().nextInt(255), Random().nextInt(255))), primaryColor: Color.fromRGBO(204, 213, 174, 1),
backgroundColor: Color.fromRGBO(233, 237, 201, 1),
scaffoldBackgroundColor: Color.fromRGBO(254, 250, 224, 1),
appBarTheme: AppBarTheme(
backgroundColor: Color.fromRGBO(204, 213, 174, 1), // Set app bar color
),
navigationRailTheme: NavigationRailThemeData(
backgroundColor: Color.fromRGBO(212, 163, 115, 1), // Set navigation rail color
),
),
title: 'Tind Book',
home: Scaffold(
appBar: AppBar(title: const Text('Draggable Sample')),
body: const MyHomePage(),
), ),
home: MyHomePage(),
), ),
); );
} }
} }
class TindBookState extends ChangeNotifier {
// List of image paths
List<String> imagePaths = [
'assets/images/passeur.png',
'assets/images/1.jpg',
'assets/images/2.jpg',
// Add more image paths as needed
];
class MyAppState extends ChangeNotifier { // Index of the currently displayed image
var current = WordPair.random(); int currentImageIndex = 0;
void getNext(){ // Function to handle swiping in any direction
current = WordPair.random(); void handleSwipe(int direction) {
if (direction == 1) {
// Swipe right
if (currentImageIndex < imagePaths.length - 1) {
currentImageIndex++;
notifyListeners(); notifyListeners();
} }
var favorites = <WordPair>[];
void toggleFavorite() {
if (favorites.contains(current)) {
favorites.remove(current);
} else { } else {
favorites.add(current); // Swipe left
} if (currentImageIndex > 0) {
currentImageIndex--;
notifyListeners(); notifyListeners();
} }
}
}
} }
class MyHomePage extends StatefulWidget { class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override @override
State<MyHomePage> createState() => _MyHomePageState(); State<MyHomePage> createState() => _MyHomePageState();
} }
class _MyHomePageState extends State<MyHomePage> { class _MyHomePageState extends State<MyHomePage> {
var selectedIndex = 0; var selectedIndex = 0;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Widget page; Widget page;
switch (selectedIndex) { switch (selectedIndex) {
case 0: case 0:
page = GeneratorPage(); page = TindBookContent();
break; break;
case 1: case 1:
page = FavoritePage(); page = FavoritePage();
break; break;
case 2:
page = Placeholder();
break;
default: default:
throw UnimplementedError('no widget for $selectedIndex'); throw UnimplementedError('no widget for $selectedIndex');
} }
return LayoutBuilder( return LayoutBuilder(
builder: (context,constraints) { builder: (context, constraints) {
return Scaffold( return Scaffold(
body: Row( body: Row(
children: [ children: [
SafeArea( SafeArea(
child: NavigationRail( child: NavigationRail(
extended: constraints.maxWidth>=600, extended: constraints.maxWidth >= 600,
destinations: [ destinations: [
NavigationRailDestination( NavigationRailDestination(
icon: Icon(Icons.home), icon: Icon(Icons.home),
label: Text('Home'), label: Text('Home'),
), ),
NavigationRailDestination( NavigationRailDestination(
icon: Icon(Icons.favorite), icon: Icon(Icons.swipe),
label: Text('Favorites'), label: Text('Swipe'),
),
NavigationRailDestination(
icon: Icon(Icons.info),
label: Text('About'),
), ),
], ],
selectedIndex: selectedIndex, selectedIndex: selectedIndex,
...@@ -100,90 +124,157 @@ class _MyHomePageState extends State<MyHomePage> { ...@@ -100,90 +124,157 @@ class _MyHomePageState extends State<MyHomePage> {
}, },
), ),
), ),
VerticalDivider(
thickness: 1,
width: 1,
), // Add a vertical divider
Expanded( Expanded(
child: Container( child: Container(
color: Theme.of(context).colorScheme.primaryContainer, color: Color.fromRGBO(250, 237, 205, 1),
child: page, child: page,
), ),
), ),
], ],
), ),
); );
} },
); );
} }
} }
class TindBookContent extends StatefulWidget {
const TindBookContent({Key? key}) : super(key: key);
class GeneratorPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { State<TindBookContent> createState() => _TindBookContentState();
var appState = context.watch<AppState>(); }
var pair = appState.current;
IconData icon; class _TindBookContentState extends State<TindBookContent> {
if (appState.favorites.contains(pair)) { late TindBookState state;
icon = Icons.favorite; double _startX = 0.0;
} else { double _currentX = 0.0;
icon = Icons.favorite_border; double _deltaX = 0.0;
bool _isSwiping = false;
@override
void didChangeDependencies() {
super.didChangeDependencies();
state = Provider.of<TindBookState>(context);
} }
return Center( @override
child: Column( Widget build(BuildContext context) {
mainAxisAlignment: MainAxisAlignment.center, return LayoutBuilder(
builder: (context, constraints) {
double containerWidth = constraints.maxWidth;
double containerHeight = constraints.maxHeight;
return GestureDetector(
onHorizontalDragStart: (details) {
_startX = details.globalPosition.dx;
_isSwiping = true;
},
onHorizontalDragUpdate: (details) {
if (_isSwiping) {
_currentX = details.globalPosition.dx;
_deltaX = _currentX - _startX;
setState(() {});
}
},
onHorizontalDragEnd: (details) {
if (_isSwiping) {
_isSwiping = false;
if (_deltaX > 50) {
// Swipe right
state.handleSwipe(1);
} else if (_deltaX < -50) {
// Swipe left
state.handleSwipe(-1);
}
}
_startX = 0.0;
_currentX = 0.0;
_deltaX = 0.0;
},
child: Stack(
children: [ children: [
BigCard(pair: pair), Positioned.fill(
SizedBox(height: 10), child: Container(
Row( color: Color.fromRGBO(250, 237, 205, 1),
mainAxisSize: MainAxisSize.min, height: containerHeight / 3,
width: containerWidth / 3,
),
),
Positioned(
top: 0,
left: 0,
right: 0,
bottom: 0,
child: Transform.translate(
offset: Offset(_deltaX, 0.0),
child: Transform.rotate(
angle: _deltaX * 0.0002, // Adjust the rotation speed here
child: ClipRRect(
borderRadius: BorderRadius.circular(100), // Adjust the radius as needed
child: Image.asset(
state.imagePaths[state.currentImageIndex],
height: containerHeight / 3, // Adjust image height
width: containerWidth / 3, // Adjust image width
fit: BoxFit.contain,
),
),
),
),
),
Positioned(
top: 20,
left: 20,
right: 20,
child: Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.5),
borderRadius: BorderRadius.circular(10),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
ElevatedButton.icon( Text(
onPressed: () { 'Titre du livre ',
appState.toggleFavorite(); style: TextStyle(
}, color: Colors.white,
icon: Icon(icon), fontSize: 20,
label: Text('Like'), fontWeight: FontWeight.bold,
),
),
SizedBox(height: 5),
Text(
'un tres bon livre qui parle de beaucoup chose , notamment mais aussi de lorem ipsum dolor sit amet a m Doctrine est pas de ',
style: TextStyle(
color: Colors.white,
fontSize: 16,
), ),
SizedBox(width: 10),
ElevatedButton(
onPressed: () {
appState.getNext();
},
child: Text('Next'),
), ),
], ],
), ),
),
),
], ],
), ),
); );
},
);
} }
} }
class FavoritePage extends StatelessWidget {
class BigCard extends StatelessWidget {
const BigCard({
super.key,
required this.pair,
});
final WordPair pair;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme=Theme.of(context); return Scaffold(
final style = theme.textTheme.displayMedium!.copyWith( body: Column(
color: theme.colorScheme.onPrimary, children: [
); Text('Test'),
],
return Card(
color: theme.colorScheme.primary,
child: Padding(
padding: const EdgeInsets.all(20),
child: Text(
pair.asLowerCase,
style: style,
semanticsLabel: "${pair.first} ${pair.second}",
),
), ),
); );
} }
......
...@@ -23,3 +23,7 @@ dev_dependencies: ...@@ -23,3 +23,7 @@ dev_dependencies:
flutter: flutter:
uses-material-design: true uses-material-design: true
assets:
- assets/images/1.jpg
- assets/images/2.jpg
- assets/images/passeur.png
...@@ -13,7 +13,7 @@ import 'package:tp1/main.dart'; ...@@ -13,7 +13,7 @@ import 'package:tp1/main.dart';
void main() { void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async { testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame. // Build our app and trigger a frame.
await tester.pumpWidget(const MyApp()); await tester.pumpWidget(const TindBookApp());
// Verify that our counter starts at 0. // Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget); expect(find.text('0'), findsOneWidget);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment