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:provider/provider.dart';
import 'dart:math';
import 'favorite_page.dart';
import 'app_state.dart';
void main() => runApp(const TindBook());
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
class TindBook extends StatelessWidget {
const TindBook({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => AppState(),
create: (context) => TindBookState(),
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))),
primarySwatch: Colors.blue,
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 {
var current = WordPair.random();
void getNext(){
current = WordPair.random();
notifyListeners();
}
var favorites = <WordPair>[];
// Index of the currently displayed image
int currentImageIndex = 0;
void toggleFavorite() {
if (favorites.contains(current)) {
favorites.remove(current);
// Function to handle swiping in any direction
void handleSwipe(int direction) {
if (direction == 1) {
// Swipe right
if (currentImageIndex < imagePaths.length - 1) {
currentImageIndex++;
notifyListeners();
}
} else {
favorites.add(current);
// Swipe left
if (currentImageIndex > 0) {
currentImageIndex--;
notifyListeners();
}
}
notifyListeners();
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var selectedIndex = 0;
@override
Widget build(BuildContext context) {
Widget page;
switch (selectedIndex) {
case 0:
page = GeneratorPage();
page = TindBookContent();
break;
case 1:
page = FavoritePage();
break;
case 2:
page = Placeholder();
break;
default:
throw UnimplementedError('no widget for $selectedIndex');
}
return LayoutBuilder(
builder: (context,constraints) {
builder: (context, constraints) {
return Scaffold(
body: Row(
children: [
SafeArea(
child: NavigationRail(
extended: constraints.maxWidth>=600,
extended: constraints.maxWidth >= 600,
destinations: [
NavigationRailDestination(
icon: Icon(Icons.home),
label: Text('Home'),
),
NavigationRailDestination(
icon: Icon(Icons.favorite),
label: Text('Favorites'),
icon: Icon(Icons.swipe),
label: Text('Swipe'),
),
NavigationRailDestination(
icon: Icon(Icons.info),
label: Text('About'),
),
],
selectedIndex: selectedIndex,
......@@ -100,90 +124,157 @@ class _MyHomePageState extends State<MyHomePage> {
},
),
),
VerticalDivider(
thickness: 1,
width: 1,
), // Add a vertical divider
Expanded(
child: Container(
color: Theme.of(context).colorScheme.primaryContainer,
color: Color.fromRGBO(250, 237, 205, 1),
child: page,
),
),
],
),
);
}
},
);
}
}
class TindBookContent extends StatefulWidget {
const TindBookContent({Key? key}) : super(key: key);
class GeneratorPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
var appState = context.watch<AppState>();
var pair = appState.current;
State<TindBookContent> createState() => _TindBookContentState();
}
IconData icon;
if (appState.favorites.contains(pair)) {
icon = Icons.favorite;
} else {
icon = Icons.favorite_border;
}
class _TindBookContentState extends State<TindBookContent> {
late TindBookState state;
double _startX = 0.0;
double _currentX = 0.0;
double _deltaX = 0.0;
bool _isSwiping = false;
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
BigCard(pair: pair),
SizedBox(height: 10),
Row(
mainAxisSize: MainAxisSize.min,
@override
void didChangeDependencies() {
super.didChangeDependencies();
state = Provider.of<TindBookState>(context);
}
@override
Widget build(BuildContext context) {
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: [
ElevatedButton.icon(
onPressed: () {
appState.toggleFavorite();
},
icon: Icon(icon),
label: Text('Like'),
Positioned.fill(
child: Container(
color: Color.fromRGBO(250, 237, 205, 1),
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,
),
),
),
),
),
SizedBox(width: 10),
ElevatedButton(
onPressed: () {
appState.getNext();
},
child: Text('Next'),
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: [
Text(
'Titre du livre ',
style: TextStyle(
color: Colors.white,
fontSize: 20,
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,
),
),
],
),
),
),
],
),
],
),
);
},
);
}
}
class BigCard extends StatelessWidget {
const BigCard({
super.key,
required this.pair,
});
final WordPair pair;
class FavoritePage extends StatelessWidget {
@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}",
),
return Scaffold(
body: Column(
children: [
Text('Test'),
],
),
);
}
......
......@@ -23,3 +23,7 @@ dev_dependencies:
flutter:
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';
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
await tester.pumpWidget(const TindBookApp());
// Verify that our counter starts at 0.
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